Published 1 Feb. 2025.
Last update 18 Feb. 2025.
Tags: technology.
I used to use Neovim as my main development environment. I like the fact that it’s small and fast, and that I can use it over an SSH connection. Neovim is a fork of Vim that I use for the Lua configuration and built-in Language Server Protocol support.
However, I mainly use Emacs these days. I extensively use evil (a Vi(m) compatibility layer for Emacs), so I haven’t really stopped using Vim but instead just use it inside a big Lisp machine.
You can find my configuration in my NixOS repository here.
Below are my working notes on learning and using (Neo)Vim.
- References:
:help usr_toc.txt:help index
ZZ/ZQexit with / without saving- basic motions
hjkliIaA0$webWEBCTRL-eCTRL-dCTRL-uCTRL-yCTRL-fCTRL-bCTRL-bCTRL-f/?nNftFT;Ggg- object selection
iwinner wordawa word (incl whitespace)is/assentenceip/apparagraphi]/a]i)/a)i>/a>i"/a"i'/a'it/at<tag> </tags>
- basic operators
dcydouble for a linerR
- basic commands
xpPuUCTRL-roO:%s/x/y/g:%s/x/y/gcwith confirmation#,#s/x/y/greplaces in selected line numbers:%s/\(.\).../...\1/regex capture:norm:nohls/:set hls:reg/yA/"Ap
- options
- set options with
:set <option> - prefix with
noorinv 'ic'ignore case'hls'highlight caseisincremental search
- set options with
- Enter to follow links
:help/Kon word for documentation- help usage
- mode prefix, e.g.
:help i_CTRL+W - options, e.g.
:help 'number' - special keys, e.g.
:help i_<Up> - error codes
:help E37
- mode prefix, e.g.
%jump to matching bracket'<,'>w FILE- writes part of a file selected in visual mode:rretrieve file or result of external commandCTRL-w CTRL-wswitch windowc_CTRL-Dand<Tab>command line completion:d//<pattern>/:g/<pattern>/<command>/- jump list
CTRL-ICTRL-O - tag stack
CTRL-]CTRL-T Jjoin lines (remove new lines)gJremove spaces too
gOhelp TOC(){}[]sentences/paragraphs/sections forwards/backwards (quickref)- spelling set language
:setlocal spell spelllang=en_gb]s/[smove misspellszget suggestions- insert mode:
CTRL-Xs - add to spellfile
zg - added shortcut for
CTRL-Sto]s1z= - spell file in
~/.config/vim/spell.en.utf-8.add
- searching repo / fuzzy match
- telescope.nvim
plugin
<leader><leader>find files<leader>bbbuffer search<leader>fQcommands<leader>fQcommand history<alt-q>open in quickfix<leader>fdtelecope file browser- iCTRL-t / nt change directory
- e home
- w current dir
- telescope.nvim
plugin
:mksessionandvim -S <file>to save/restore a sessiongcommandsgjgkg0g$gq(q)gu(u)gU_{g}(~)gfgxgvg&
C-6/C-^/:b#go to last buffer- marks
- make
m{a-zA-Z}- NB a-z are file local
- jump to line
'{a-zA-Z} - jump to column
`{a-zA-Z} ``/''previous mark
- make
- indent
<<>>i_CTRL-ti_CTRL-d=<motion>or==for line
- window management
:help windowsc/:closeo/:onlyres/vert res
- tab management
:tabnewCTRL-wTgt/gT
- buffer management
:bd/:bn/:bp
- Markdown formatting a la tutor
- https://github.com/neovim/neovim/blob/5c36701228e166f8aa89983044404ff322fe481f/runtime/tutor/tutor.tutor
- https://github.com/neovim/neovim/blob/5c36701228e166f8aa89983044404ff322fe481f/runtime/syntax/tutor.vim
- https://github.com/neovim/neovim/blob/5c36701228e166f8aa89983044404ff322fe481f/runtime/doc/pi_tutor.txt
- https://github.com/neovim/neovim/blob/5c36701228e166f8aa89983044404ff322fe481f/runtime/plugin/tutor.vim#L4
- folds
zfcreatezoopenzOopen reczcclosezCclose reczatogglezAtoggle reczifold enable:help usr_28.txt:help folding- with markdown folding, we don’t want to have a file all folded on
open
- if we set
nofoldenable, enabling any fold will enable them all - so we set
foldlevel: 99
- if we set
zMclose all folds, set foldlevel=0zRclose all folds, set foldlevel=highestzm/zrdecrement/increment foldlevel
q:command line editing in normal mode:ls tlist buffers in recently used order- paste in insert mode
i_CTRL-r - see lsp servers
:lua =vim.lsp.get_active_clients()[1] gito enter insert mode at the place in the file where you last left iti_CTRL-operform one normal mode command- surround with brackets
ciW""EscP- or with (n)vim-surround
ysiW"- change with
cs'" - NB open brackets add space and closed don’t
- change including tags
ysa"[ - change brackets e.g. =cs[{=
- visual mode: S
- delete
ds<motion>
- change with
- or with (n)vim-surround
- insert date
- expression register
"=strftime('%F') - or in insert mode
<C-r>=strftime('%F')
- expression register
- macros
- record
q<char><recording>q - replay
@<char>reply last@@ Qrepeat last recorded register [count] times- macros paste to the register, e.g.
qrlq"rpwill producel- you can set macros from plain text in the inverse too
- record
- comment.nvim
gccline orgc<motion> - vimtex
csechange surrounding:help vimtex-motions- https://jdhao.github.io/2019/03/26/nvim_latex_write_preview/#useful-mappings-and-shortcuts
dsedelete surroundingtsetoggle surrounding from/to *, e.g. equation to equation *\llstart compilation- textobjects
gqformat- netrw
:Ex%for filedfor dir
:h Select-mode- quickfix menu
copen(populated by search, e.g.:grepor telescope)cdo %s/replace/with/gccdo w- and after make
copen cncp
:changesg;g,
:set pastezzcentre on line- register
%/#current / prev file gsgo to sleepgOoutline*/#search word under cursor{Visual}g CTRL-Aincrement list[%go to containing[:g/^/m 0Reverse line order:help 12.4:e %:h/fileanother file in current file’s directory- more expansions at
:help expand
- more expansions at
- luasnip insert node puts you in select mode
- you can exit it and append with
<Esc>Ea - they continue with
<C-l>
- you can exit it and append with
r!<command>insert command output.repeat last change- groking vim
O nvim-cmp cmp-path
without starting ./
O hydra