Re-learning Vim (3)

Date: 2021/09/12 (initial publish), 2022/07/20 (last update)

Source: en/note-00027.md

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.

For ease of customization, I chose NvChad. Result was great start-up time reduction.

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,

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.

Setting of update-alternatives settings:

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)

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)

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")

Upstreamed mod for “Tweak”

      {
        "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

Lack of good ALE equivalent support stalled me to use neovim 0.5.

Previous Post Top Next Post