## 概要 [[lualine.nvim]]を使うと[[Neovim]]のステータスラインを格好よくできる。 デフォルトの設定でも十分だが、カスタマイズすることでより自分好みにできるので、そのためのノウハウをまとめてみた。 > [!caution] > [[lualine.nvim]]のインストール方法や基本的なセットアップ方法は記載しない。必要な場合は公式のREADMEを参照。 公式READMEが分かりやすいので基本はそれを読めばOK。 <div class="link-card"> <div class="link-card-header"> <img src="https://github.githubassets.com/favicons/favicon.svg" class="link-card-site-icon"/> <span class="link-card-site-name">GitHub</span> </div> <div class="link-card-body"> <div class="link-card-content"> <div> <p class="link-card-title">GitHub - nvim-lualine/lualine.nvim: A blazing fast and easy to configure neovim statusline plugin written in pure lua.</p> </div> <div class="link-card-description"> A blazing fast and easy to configure neovim statusline plugin written in pure lua. - GitHub - nvim-l... </div> </div> <img src="https://opengraph.githubassets.com/0ebb941ed61df16690de52402430eec381054823dbbefb70748ef66add06dc3a/nvim-lualine/lualine.nvim" class="link-card-image" /> </div> <a href="https://github.com/nvim-lualine/lualine.nvim"></a> </div> ## セクション [[lualine.nvim]]にはセクションという概念がある。以下は公式READMEから引用。 ``` +-------------------------------------------------+ | A | B | C X | Y | Z | +-------------------------------------------------+ ``` 左側がA~Cの3セクション、右側がX~Zの3セクションに分かれている。 ![[Pasted image 20231011154458.png|frame]] *デフォルト設定におけるセクション* この6セクションに何を配置するか...というのが[[lualine.nvim]]の設定。[READMEに記載されているデフォルト設定](https://github.com/nvim-lualine/lualine.nvim#default-configuration)の中では以下の部分。 ```lua sections = { lualine_a = {'mode'}, lualine_b = {'branch', 'diff', 'diagnostics'}, lualine_c = {'filename'}, lualine_x = {'encoding', 'fileformat', 'filetype'}, lualine_y = {'progress'}, lualine_z = {'location'} }, inactive_sections = { lualine_a = {}, lualine_b = {}, lualine_c = {'filename'}, lualine_x = {'location'}, lualine_y = {}, lualine_z = {} }, ``` ## コンポーネント [[#セクション]]の中には複数のコンポーネントがある。 ![[Pasted image 20231011155845.png|frame]] *セクションX内のコンポーネント* ## セパレーター [[#セクション]]や[[#コンポーネント]]の切れ目をセパレーターという。 ![[Pasted image 20231011160251.png|frame]] *2種類のセパレーター* オプションで指定できる。 ```lua { section_separators = { left = '', right = '' }, component_separators = { left = '', right = '' } } ``` ## セクションにコンポーネントを追加 6つの[[#セクション]]に対して、それぞれ[[#コンポーネント]]を複数指定できる。以下はデフォルトの設定。 ```lua sections = { lualine_a = {'mode'}, lualine_b = {'branch', 'diff', 'diagnostics'}, lualine_c = {'filename'}, lualine_x = {'encoding', 'fileformat', 'filetype'}, lualine_y = {'progress'}, lualine_z = {'location'} }, ``` 使用できるコンポーネントは[Available components](https://github.com/nvim-lualine/lualine.nvim#available-components)を参照。 ためしに `mode` `progress` `location` を表示しないような設定にしてみる。よく確認する情報を左に、たまにしか確認しない情報は右にする。 - 左 - ファイル名 - ブランチ名 - 差分と診断結果 - 右 - エンコーディング、ファイルフォーマット - ファイルタイプ 設定は以下のようになる。 ```lua config = function() local lualine = require('lualine') local config = { sections = { lualine_a = {'filename'}, lualine_b = {'branch'}, lualine_c = {'diff', 'diagnostics'}, lualine_x = {'encoding', 'fileformat'}, lualine_y = {'filetype'}, lualine_z = {}, }, inactive_sections = { lualine_a = {}, lualine_b = {}, lualine_c = {}, lualine_x = {}, lualine_y = {}, lualine_z = {}, }, } lualine.setup(config) end ``` ![[Pasted image 20231011162108.png|frame]] *表示内容を変更したあとのバー* ## デザイン調整 ### セパレーターを消す `config`配下の`options`に以下を追加する。 ```lua options = { component_separators = {}, section_separators = {}, }, ``` ### アイコンを変更する フォントの関係か、一部のアイコンが表示されないので変更する。 ![[Pasted image 20231011164143.png|frame]] *文字化けするアイコン* 文字化けしているのは診断結果、ついでに差分の方にもアイコンを設定してみる。`sections`の`lualine_c`を変更。 ```lua lualine_c = { { 'diff', symbols = {added = ' ', modified = ' ', removed = ' '}, }, { 'diagnostics', symbols = {error = ' ', warn = ' ', info = ' ', hint = ' '}, } }, ``` 文字化けが解消され見栄えもよくなった。 ![[Pasted image 20231011165328.png|frame]] *アイコン設定後* > [!info] > `diff` と `diagnostics` のオプション。 > - https://github.com/nvim-lualine/lualine.nvim#diff-component-options > - https://github.com/nvim-lualine/lualine.nvim#diagnostics-component-options ### 中央に表示する 差分と診断結果は重要なので中央に表示したい場合。 ![[Pasted image 20231011165328.png|frame]] *これらを中央に表示* `"'%='",`を差し込むことで実現する。 ```lua lualine_c = { "'%='", { 'diff', symbols = {added = ' ', modified = ' ', removed = ' '}, }, { 'diagnostics', symbols = {error = ' ', warn = ' ', info = ' ', hint = ' '}, } }, ``` ![[Pasted image 20231011170340.png|frame]] *差分と診断結果を中央寄せ* ### 差分と診断結果の境界を分ける 今のままでは差分と診断結果がすべて1つのまとまった情報に見えるので、意味合いごとに分ける。 `separator`を指定するとコンポーネントセパレーターを指定できる。`" | "`を指定して距離をとりつつ縦棒を入れる。 ```lua lualine_c = { "'%='", { 'diff', symbols = {added = ' ', modified = ' ', removed = ' '}, separator = " | ", }, { 'diagnostics', symbols = {error = ' ', warn = ' ', info = ' ', hint = ' '}, } }, ``` > [!info] > `separator = {left = "<", right = ">"}` のように `left` と `right` を指定した場合、それはセクションセパレーターと解釈される。 これで見やすくなった。 ![[Pasted image 20231011171016.png|frame]] *差分と診断結果の間にセパレーターをもうけた* ## まとめ 以上をまとめた設定が以下となる。 ```lua { 'nvim-lualine/lualine.nvim', dependencies = { 'nvim-web-devicons', opt = true }, event = {'BufNewFile', 'BufRead'}, options = { theme = 'gruvbox-material' }, config = function() local lualine = require('lualine') local config = { options = { component_separators = {}, section_separators = {}, }, sections = { lualine_a = {'filename'}, lualine_b = {'branch'}, lualine_c = { "'%='", { 'diff', symbols = {added = ' ', modified = ' ', removed = ' '}, separator = " | ", }, { 'diagnostics', symbols = {error = ' ', warn = ' ', info = ' ', hint = ' '}, }, }, lualine_x = {'encoding', 'fileformat'}, lualine_y = {'filetype','searchcount'}, lualine_z = {}, }, inactive_sections = { lualine_a = {}, lualine_b = {}, lualine_c = {}, lualine_x = {}, lualine_y = {}, lualine_z = {}, }, } lualine.setup(config) end }, ```