Previous Post | Top | Next Post |
TOC
Nvim configuration retrospective
I have been updating Nvim configuration with AstroNvim as described in Re-learning Vim (5) and Re-learning Vim (6).
I also build the latest Nvim in Building Neovim to be compatible with the latest packages.
Although AstroNvim provided me with great features with simple and consistent customization mechanism, they were still a bit overwhelming and sometimes too much. I needed a simpler baseline Neovim configuration platform which offers most features as opt-in.
As of 2024-06-02, I have migrated to NeoVim (NVIM v0.10.0, local deb)
with lua based lazyVim as my primary editor invoked by
nvim
(or via its n
alias) with
my customized LazyVim starter.
See below for how I configured this
This LazyVim is nice but a bit heavy.
I decided to use vi
to start Vim or Nvim with a single file configuration
with very minimal customization. (Sometimes, LazyVim acts strange. This vi
is much faster to start and caused no such issues.)
Vi as an baseline simple editor
Here, I created a single generic configuration file for Vim and NeoVim ~/.vimrc
.
""" Generic baseline Vim and Neovim configuration (~/.vimrc)
""" - For NeoVim, use "nvim -u ~/.vimrc [filename]"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible " :h 'cp -- sensible (n)vim mode
syntax on " :h :syn-on
filetype plugin indent on " :h :filetype-overview
set encoding=utf-8 " :h 'enc (default: latin1) -- sensible encoding
""" current vim option value can be verified by :set encoding?
set backspace=indent,eol,start " :h 'bs (default: nobs) -- sensible BS
set statusline=%<%f%m%r%h%w%=%y[U+%04B]%2l/%2L=%P,%2c%V
set listchars=eol:¶,tab:⇄\ ,extends:↦,precedes:↤,nbsp:␣
set viminfo=!,'100,<5000,s100,h " :h 'vi -- bigger copy buffer etc.
""" Pick "colorscheme" from blue darkblue default delek desert elflord evening
""" habamax industry koehler lunaperche morning murphy pablo peachpuff quiet ron
""" shine slate torte zellner
colorscheme industry
"colorscheme default
set scrolloff=5 " :h 'scr -- show 5 lines around cursor
set laststatus=2 " :h 'ls (default 1) k
""" boolean options can be unset by prefixing "no"
set ignorecase " :h 'ic
set smartcase " :h 'scs
set autoindent " :h 'ai
set smartindent " :h 'si
set nowrap " :h 'wrap
"set list " :h 'list (default nolist)
set noerrorbells " :h 'eb
set novisualbell " :h 'vb
set t_vb= " :h 't_vb -- termcap visual bell
set spell " :h 'spell
set spelllang=en_us,cjk " :h 'spl -- english spell, ignore CJK
set clipboard=unnamedplus " :h 'cb -- cut/copy/paste with other app
set hidden " :h 'hid
set autowrite " :h 'aw
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Popular mappings
""" Window moves without using CTRL-W which is dangerous in INSERT mode
nnoremap <C-H> <C-W>h
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
silent! nnoremap <C-L> <C-W>l
""" execute previous macro recorded
nnoremap Q @@
""" nohlsearch with <ESC> (<C-L> is mapped as above)
inoremap <ESC> <CMD>noh<CR><ESC>
nnoremap <ESC> <CMD>noh<CR><ESC>
""" center after jump next
nnoremap n nzz
nnoremap N Nzz
""" fast "jk" to get out of INSERT mode (<ESC>)
inoremap jk <ESC>
""" double <ESC> to get out of TERM mode (CTRL-\ CTRL-N)
tnoremap <ESC><ESC> <C-\><C-N>
""" fast "jkjk" to get out of TERM mode (CTRL-\ CTRL-N)
tnoremap jkjk <C-\><C-N>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" nvim default mappings (no need for nvim)
""" copy to EOL (no delete) like D for d
noremap Y y$
""" disable prefix repeats for erases
inoremap <C-U> <C-G>u<C-U>
inoremap <C-W> <C-G>u<C-W>
""" search visual selected string for visual mode
xnoremap * y/\V<C-R>"<CR>
xnoremap # y?\V<C-R>"<CR>
""" repeat last substitute and *KEEP* flags
nnoremap & :&&<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Force to use underline for spell check results
augroup SpellUnderline
autocmd!
autocmd ColorScheme * highlight SpellBad term=Underline gui=Undercurl
autocmd ColorScheme * highlight SpellCap term=Underline gui=Undercurl
autocmd ColorScheme * highlight SpellLocal term=Underline gui=Undercurl
autocmd ColorScheme * highlight SpellRare term=Underline gui=Undercurl
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" highlight tailing spaces as red color
highlight RedundantSpaces ctermbg=red guibg=red
call matchadd('RedundantSpaces', '\s\+$')
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Use faster 'rg' (ripgrep package) for :grep
if executable("rg")
set grepprg=rg\ --vimgrep\ --smart-case
set grepformat=%f:%l:%c:%m
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Retain last cursor position :h '"
augroup RetainLastCursorPosition
autocmd!
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
augroup END
" vim: set sw=2 sts=2 et ft=vim :
Since nvim may not be available, I created bash alias for vi
etc. in ~/.bashrc
as:
# sourced at the end of ~/.bashrc
# vim:set sw=2 sts=2 ai si et:
# Use: shfmt -s -w
#=============================================================================
if [ -r "$HOME/.vimrc" ]; then
VIMRC="$HOME/.vimrc"
else
VIMRC="NORC"
fi
if type /usr/bin/nvim > /dev/null; then
export EDITOR="/usr/bin/nvim"
# Set NVIM_APPNAME for nvim
# Nvim playground
NVIM_APPNAME=nvim # normal nvim -- currently osamu's LazyVim
#NVIM_APPNAME=nvim0 # default LazyVim
#NVIM_APPNAME=nvim1 # osamu's LazyVim (backup)
#NVIM_APPNAME=nvim2 # ...
export NVIM_APPNAME
alias v="/usr/bin/nvim"
alias vi="/usr/bin/nvim"
alias v0="/usr/bin/nvim -u NORC"
alias v1='/usr/bin/nvim -u $VIMRC'
alias sv="env SUDO_EDITOR='/usr/bin/nvim -u NORC' /usr/bin/sudoedit"
alias vimdiff='/usr/bin/nvim -d -u $VIMRC'
alias view="/usr/bin/nvim -R -u NORC"
alias ex="/usr/bin/nvim -e -u NORC"
elif type vim > /dev/null; then
export EDITOR='vim'
alias v='vim -N -u $VIMRC'
alias vi='vim -N -u $VIMRC'
alias v0="vim -N -u NORC"
alias v1='vim -N -u $VIMRC'
alias sv="env SUDO_EDITOR='/usr/bin/vim -N -u NORC' /usr/bin/sudoedit"
else
unset VIMRC
fi
export VISUAL=$EDITOR
alias nvim0="env NVIM_APPNAME=nvim0 /usr/bin/nvim" # upstream default
alias nvim1="env NVIM_APPNAME=nvim1 /usr/bin/nvim" # osamu default
alias nvim2="env NVIM_APPNAME=nvim2 /usr/bin/nvim" # ...
Here, I use $NVIM_APPNAME
environment variable.
LazyVim
A new baseline Neovim setup system LazyVim is published by the upstream of the new smart delayed package loader 💤lazy.nvim.
Its guide is available at www.lazyvim.org.
LazyVim functions as a nice baseline Neovim configuration system similar to AstroNvim but with less complication. -> So I decided to switch over to this.
- LazyVim is designed to install a trivial bootstrap code and empty
configuration template files in
~/.config/nvim
. The template files are meant to be customized by the user. - LazyVim package contains non-trivial baseline configuration files and utility codes.
- LazyVim package itself is installed under the
~/.local/share/nvim/lazy
together with all other packages including the package manager 💤lazy.nvim. - Installed lua packages can be managed by
:Lazy
(alternatively,<SPACE>l
).
Terminal emulator
The current gnome-terminal
seems to support true color and undercurls without
much issues.
Just to be sure, I also installed kitty
and optionally alacritty
which are
officially supported by www.lazyvim.org.
The colorscheme
for them was adjusted to match gnome-terminal
to ensure
readability for programs such as mc
.
Key bindings
- You can reach Normal mode by pressing
<ESC>
-key. - In Normal mode,
which-key.nvim
displays the key binding.- for the second and following keys as you type.
- for the first keys just by pressing
<BS>
-key after any random keys such as<SPACE>
-key.
- Notable first keys used by native Neovim and user defined commands:
<SPACE>
-key: user defined utility commandsg
-key: MOVE-type commandsz
-key: FOLD-type commands[
-key: PREVIOUS-type commands]
-key: NEXT-type commands<SPACE>l
-key: Lazy lua package manager<SPACE>cm
-key: Mason binary command manager
NOTE: The comment-out command is gc
for LazyVim which is the native Nvim
internal function and its keymap. (it is <SPACE>/
for AstroNvim).
Colorscheme of Lazyvim
The default colorscheme
for Lazyvim
is tokyonight
.
Now Neovim default to vim.go.background = "dark"
. (as of 0.9.0+)
mason.nvim
support
mason.nvim
manages binary commands used by null-ls.nvim
. It can be started
by :Mason
(alternatively, <SPACE>cm
). To update binary commands to the
latest, just press “U”.
Basically, this helps us to install requested <packagename>
package into
~/.local/share/nvim/mason/packages/<packagename>/
and make its executable
<progname>
program accessible from Neovim in
~/.local/share/nvim/mason/bin/<progname>
. So executable programs from Neovim
plugins are not the one on the main system.
As I see my situation with :checkhelth mason
.:
==============================================================================
mason: require("mason.health").check()
mason.nvim ~
- OK mason.nvim version v1.10.0
- OK PATH: prepend
- OK Providers:
mason.providers.registry-api
mason.providers.client
- OK neovim version >= 0.7.0
mason.nvim [Registries] ~
- OK Registry `github.com/mason-org/mason-registry version: 2024-04-10-ripe-crush` is installed.
mason.nvim [Core utils] ~
- OK unzip: `UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.`
- OK wget: `GNU Wget 1.21.3 built on linux-gnu.`
- OK curl: `curl 7.88.1 (x86_64-pc-linux-gnu) libcurl/7.88.1 OpenSSL/3.0.11 zlib/1.2.13 brotli/1.0.9 zstd/1.5.4 libidn2/2.3.3 libpsl/0.21.2 (+libidn2/2.3.3) libssh2/1.10.0 nghttp2/1.52.0 librtmp/2.3 OpenLDAP/2.5.13`
- OK gzip: `gzip 1.12`
- OK tar: `tar (GNU tar) 1.34`
- OK bash: `GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)`
- OK sh: `Ok`
mason.nvim [Languages] ~
- OK Go: `go version go1.19.8 linux/amd64`
- WARNING Composer: not available
- ADVICE:
- spawn: composer failed with exit code - and signal -. composer is not executable
- WARNING PHP: not available
- ADVICE:
- spawn: php failed with exit code - and signal -. php is not executable
- OK cargo: `cargo 1.65.0`
- OK Ruby: `ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]`
- WARNING javac: not available
- ADVICE:
- spawn: javac failed with exit code - and signal -. javac is not executable
- OK node: `v18.19.0`
- WARNING julia: not available
- ADVICE:
- spawn: julia failed with exit code - and signal -. julia is not executable
- OK python: `Python 3.11.2`
- OK luarocks: `/usr/bin/luarocks 3.8.0`
- OK java: `openjdk version "17.0.10" 2024-01-16`
- OK RubyGem: `3.3.15`
- OK pip: `pip 23.0.1 from /usr/lib/python3/dist-packages/pip (python 3.11)`
- OK python venv: `Ok`
- OK npm: `9.2.0`
mason.nvim [GitHub] ~
- OK GitHub API rate limit. Used: 0. Remaining: 60. Limit: 60. Reset: Wed 10 Apr 2024 03:06:37 PM JST.
Install and authenticate via gh-cli to increase rate limit.
I ended up to install following Debian packages as required system programs.
luarocks
npm
nodejs
cargo
python3-pip
python3-venv
curl
wget
See more :h mason.nvim
.
The programs generated by mason.nvim
are accessible only from :term
.
I also added ~/.editorconfig to cope with sources using editorconfig.
Choice of linter and formatter
I have installed and used followings established formatter and linter tools from DEB packages.
- Bash
shellcheck
(HASKELL) (linter)shfmt
(GO) (formatter)
- Python
black
(PYTHON) (formatter)isort
(PYTHON) (formatter)
- Perl
perltidy
(Perl) (formatter)
On top of these, mason.nvim
enables to install and use much newer tools
(These are accessible from :term
).
- Bash
shellharden
(Rust) – new over shellcheck (linter)shfmt
(GO) (formatter)
- Python
ruff
(Rust) – new overblack
andisort
(formatter and linter)
- Lua
- Stylua (Rust) (formatter)
- selene (Rust) – new over
luacheck
(linter)
These seem to be installed under $XDG_DATA_HOME/$NVIM_APPNAME/
(e.g.,
~/.local/share/nvim1
) and $PATH
in :term
is extended to include installed
binary path (e.g., ~/.local/share/nvim1/bin
) when NVIM_APPNAME=nvim1
is
set.
LazyVim customization
I created folked LazyVim starter with
my changes in osamu
branch to keep backup of my local configuration. I
intend to git push -f
. It now contains following changes.
Update .gitigonore
I excluded *.json
from git repo.
Opening Gzip files
Since Debian ships most documentation files as Gzipped, I enabled “gzip”
plugin for view
purpose.
LazyVim’s extra features as opt-in features
I made some LazyVim’s extra features as opt-in features by making them disabled as started.
Additional key bindings are added to enable/disable/toggle these.
- auto-input (= completion, auto pairs, auto format) – enable with
<leader>ua
/ disable with<leader>uA
- completion (cmp by
nvim-cmp
) – toggle with<leader>uP
- dismiss all Notifications with
<leader>z
recall all Notifications with(use<leader>Z
<leader>snh
with noice.nvim)- activate menu for Lazy Extras with
<leader>X
– since LazyVim’s dashboard has been disabled
Column and Line number and, Unicode codepoint in statusline
Using ~/.config/nvim/lua/plugin/ui.lua
, I replaced clock display in statusline with Unicode codepoint as [+U20]
.
Treesitter and LSP
It is a bit confusing what is all about Treesitter and LSP. Reddit gave me good intro: Treesitter vs LSP. Differences ans overlap.
The nvim-treesitter playground plugin is now integrated into Neovim v0.9, so :InspectTree
works without installing this plugin.
Previous Post | Top | Next Post |