Previous Post | Top | Next Post |
TOC
This page is here as my old memo and contents are outdated. See:
Neovim 0.5 migration
After finding out Neovim (nvim) 0.5 starts up 30%-40% faster than Vim 8 probably due to asynchronous processing and more effective use of multi-core modern CPU, I decided to migrate to nvim. Then lua thing got my attention. Since nvim source package for version 0.5 was available in Debian experimental, I made a local package from it. So I am in good shape to try the latest lua scripts.
After translating my old vimrc to lua as https://github.com/osamuaoki/dot-nvim
, I realized this isn’t going anywhere. It was easy to convert
.config/nvim/init.vim
but it was hard to decide how to migrate all my vimL
based packages to new new lua based ones.
I found 3 interesting projects which offer examples for how this is done.
- Lunar Vim
- NvChad
- SRC: https://github.com/NvChad/NvChad
- WIKI: https://github.com/NvChad/NvChad/wiki (old?
- HOME: https://nvchad.netlify.app/
- DOOM-NVIM
For ease of customization, I chose NvChad. Result was great start-up time reduction.
- vim 230 ms (dot-vim in vimL)
- nvim 161 ms (dot-nvim in lua starting vimL packages)
- nvim 65 ms (NvChad in all lua) – use lazy loading
- nvim 44-60 ms (doom-nvim in all lua) – use lazy loading more (?)
Doom-Nvim report it started in 0.013-0.040 s on the bottom of the opening screen if I scrolled down. The value is nowhere seen on the log generated by `vi –startuptime …``.
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.012 000.012: --- NVIM STARTING ---
...
003.926 000.038: initialized screen early for UI
...
013.482 009.341 008.970: sourcing /home/osamu/.config/nvim/init.lua
013.507 000.241: sourcing vimrc file(s)
...
043.248 026.179 026.179: sourcing /home/osamu/.config/nvim/plugin/packer_compiled.lua
043.622 001.985: loading plugins
...
046.493 001.711: loading packages
046.952 000.459: loading after plugins
046.970 000.018: inits 3
046.973 000.003: reading ShaDa
...
053.165 004.798: opening buffers
053.764 000.599: BufEnter autocommands
053.773 000.009: editing files in windows
...
058.531 004.216: VimEnter autocommands
058.535 000.004: UIEnter autocommands
058.537 000.002: before starting main loop
059.987 001.449: first screen update
059.994 000.007: --- NVIM STARTED ---
Here,
BufEnter
is a hook useful for setting options for a file type.VimEnter
is a hook after doing all the startup stuffUIEnter
is a hook after doing all the GUI startup stuff
Here is my memo on how to use DOOM-NVIM and customize it.
Terminal settings
Set DEL-code(0x7F) for Backspace and use escape sequence for Delete. This
frees the ASCII BS (CTRL-H) code so window jump can be mapped to <C-H>
.
Now I see why this was default.
Key bindings
I am keeping mostly default key bindings for now.
- Vim’s original key bindings:
:help index
- Configuration introduced key bindings (with opened empty file):
:put =execute('nmap')
etc.
which-key.nvim
also solves allow us to set timeoutlen to be short (500ms instead of default 1000ms).which-key.nvim
is good for dummy like me.- This makes
jk
for<Esc>
not so clunky.
- keep and for internal index jumper and external file explorer
Setting of update-alternatives
settings:
vi
tonvim
(manual)vim
tovim.gtk3
(default)
Dependency package management
Any of these packer based system, it is good idea to run followings in EX-mode after editing the system.
:PackerSync
:PackerCompile
Main configuration management
In order to minimize conflict, I now use git pull --rebase
to my local
branch. (Probably using upstream provided interface)
main
tracksmain
byupstream
(but no push)upstream
is set to the official site
local
is rebased onmain
and commit actual used configuration with deep modification.
help
Lazy loading of packges seems to cause missing documentation.
See workaroun https://github.com/NTBBloodbath/doom-nvim/issues/126
Skipped programs
lazygit – go program not packaged in Debian
minimap – rust program not packaged in Debian – non-essential
neogit – immature CLI git is good enough for me with gitsigs
suda – sudo -E
can start editting with vi running as user
autopairs – thank you but … I don’t need this "" for "
Note on delayed loading
For example, init.lua
has:
-- Load keybindings module at the end because the keybindings module cost is high
vim.defer_fn(function()
load_modules("doom.extras", { "keybindings" })
vim.cmd([[
PackerLoad which-key.nvim
silent! bufdo e
]])
end, 20)
- This uses
defer_fn
to deffer calling keybinding change code until 20 ms passes. - Set up
vim.g
variables for which-key.nvim. - Loads opt plugin which-key.nvim immediately
- Then at the end,
e
reloads the current file and continues to edit it.
Any heavy CPU/storage hungry programs can use this techniques.
map
For key bindings, nvim-mapper
is used as the backend for doom-nvim.
map(mode, keys, cmd, options, category, unique_identifier, description)
is
used for usual map(mode, keys, cmd, options)
.
Actual code looks like:
map("n", "<leader>v", "<cmd>w<cr>", opts, "Save", "save_left", "Save v")
- Packer load nvim-mapper’s setup() and search keybindings at path
~/.config/nvim/lua
lua/init.lua
–> delayed –>lua/doom/extras/keybindings/init.lua
Upstreamed mod for “Tweak”
- Toggle/rotate features (which-key)
- number – done change_number
- spell – done toggle_spell
- syntax – done change_syntax
- git – done toggle_signcolumn
- ale – no yet addressed
- indent 2/4/8 – done set_indent
{
"t",
name = "+tweak",
{
{ "b", require("doom.core.functions").toggle_background, name = "Toggle background" },
{ "s", require("doom.core.functions").toggle_signcolumn, name = "Toggle sigcolumn" },
{ "i", require("doom.core.functions").set_indent, name = "Set indent" },
{ "n", require("doom.core.functions").change_number, name = "Toggle number" },
{ "S", require("doom.core.functions").toggle_spell, name = "Toggle spelling" },
{ "x", require("doom.core.functions").change_syntax, name = "Toggle syntax" },
},
},
TODO
- ale – shellcheck integration needed
- Stop suggestion if CTRL-Y is pressed (same as .)
F6
-F10
,ALT
/SHIFT
/WIN-SPACE
should be off limit (used by IM)
Lack of good ALE equivalent support stalled me to use neovim 0.5.
Previous Post | Top | Next Post |