Closed6

久しぶりの NeoVim (→ Lua だけ確認)

toyboot4etoyboot4e

最近の NeoVim は成長が著しい。設定ファイルは Lua で書いて、プラグインは Deno で動くとか。どうしてそうなった?!

全然ついていけていないので、少しだけ設定を更新しておきたい。

toyboot4etoyboot4e

設定 (プロファイル) の切り替え

Emacs では chemacs2 で設定を切り替えることができる:

$ # `leaf` プロファイルで Emacs を起動する:
$ emacs -nw --with-profile leaf "$@"

$ # `vanila` プロファイルで Emacs を起動する:
$ emacs -nw --with-profile vanila "$@"

NeoVim にも同等のもの (chevim) があるらしい。 Lua-only なので以前の設定は起動できないが、人の設定を試すときに便利そう。

早速インストールしてみた:

$ rm -r ~/.local/share/nvim/site/pack
$ rm -r ~/.config/nvim
$ git clone https://github.com/NTBBloodbath/cheovim ~/.config/nvim
$ vim ~/.config/nvim/profiles.lua
profiles.lua
local profiles = {
	nvim = { "~/dotfiles/editor/nvim/init.nvim", {
			plugins = "packer",
			preconfigure = "packer",
		}
	},
}

-- `nvim` プロファイルで起動 (デフォルト)
return "nvim", profiles

特定のプロファイルで起動するには、以下コマンドが使えるみたい?:

$ nvim --cmd "lua load_profile='<name>'"
n
#!/usr/bin/env bash
CARGO_TARGET_DIR=target/ra nvim --cmd "lua load_profile='nvim'" "$@"
toyboot4etoyboot4e

一瞬だけ Nix + NeoVim 入門を考えた……。ただ nixpkgs の更新に依存することになると思う。やめておこう。

toyboot4etoyboot4e

init.lua 入門

入門するぞ!

ファイル分割、ディレクトリ構成

設定ファイルは lua ディレクトリに入れるのが一般的みたい:

~/dotfiles/editor/nvim
├── init.lua
└── lua
    ├── keymap.lua
    ├── options.lua
    └── plugins.lua

lua/ 以下のファイル読み込み:

init.lua
vim.cmd([[
for file in split(glob('~/dotfiles/editor/nvim/lua/*.lua'), '\n')
    execute 'source ' . file
endfor
]])

init.el の編集/読み込みコマンド

:ed, :s を定義する:

-- Define `:ed` and `:s`
-- TODO: Prefer `vim.api.nvim_create_user_command` on NeoVim 0.7
vim.cmd([[
function! Abbreviate(from, to)
    exec 'cnoreabbrev <expr> '.a:from
          \ .' ((getcmdtype() ==# ":" && getcmdline() ==# "'.a:from.'")'
          \ .'? ("'.a:to.'") : ("'.a:from.'"))'
endfunction

call Abbreviate('s',  'source ~/dotfiles/editor/nvim/init.lua')
call Abbreviate('ed', 'edit ~/dotfiles/editor/nvim/init.lua')
]])

普通に VimScript だ……。案外 init.lua への移行はストレートに済みそう。

Option 値の設定

nvim-guide から:

Everything you need to know to configure neovim using lua | Devlog もチートシート的に使う。

こんな感じか:

-- Non-interactive shell:
vim.env.SHELL = 'bash'

-- Interactive shell:
if vim.fn.executable('fish') == 1 then
    opt.shell = 'fish'
end

vim.cmd([[ syntax enable ]]) -- Enable builtin highlight

local opt = vim.opt
opt.updatetime = 300     -- Make vim faster
opt.backspace = "2"      -- Enable backspace in insert mode

人の dotfiles を覗く

$ ghq get https://github.com/yutkat/dotfiles
toyboot4etoyboot4e

Packer 導入

cheovimPacker をインストールしてくれていた。

return require('packer').startup(function(use)
    use({ 'wbthomason/packer.nvim' })
    -- ~~~~
end)

-- `:PackerInstall`

詰まるポイントが無かった……。今後暇な時に fzf, UI widget, LSP, Git あたりを見ていきたい。

toyboot4etoyboot4e

中断

設定ファイル自体は Lua に移行できたので、後はプラグインを見ていく段階ですが、好奇心が尽きてしまいました。

閉じます。また気が向いた時は再開します。

このスクラップは2022/07/04にクローズされました