aliquote.org

Vim shortcuts

Here are the current Neovim mappings I came to feel comfortable with over time. This is by no means a reference card, and yes I do use the arrow keys for navigating into my buffers. It depends on motion range, though. Another key idea is that I use Tmux everyday and I like to have an unified set of mappings, beside the leader/prefix key. See my blog posts for how I started to use Vim and Neovim.

Note that I only have a dozen of plugins in my start and opt directories, in addition to part of mini.nvim that I adapted to suit my needs better: (This may change in the future but usually I tend to remove plugins rather than add new ones.1 )

[2022-10-05]
I changed it all again! Latest setup described here. This means that some keybindings no longer apply to my current config. It’s all in the details but I feel like a minimalist setup and almost zero dependencies are the take away message.

I prefer a minimalist setup these days, and I tend to rely on hand-on solutions for tasks I carry over and over. Many of those custom settings come from briliant Vimers who are acknowledged in my config files. Note that some of those mappings may override existing ones, whether they are somewhat redundant (e.g. s and c) or because I don’t use them at all (e.g., some of the Ctrl, g or z combinations).

My leader is “,"2 and I do not define specific mappings for the localleader in my main config files. It looks like I always misunderstood the role of the localleader, and I decided to book it for my after/ftplugin custom settings.

Mapping Mode Command Role
<C-a>c:<Home>Go to start of line
<C-e>c:<End>Go to end of line
-n:ExShow explorer
,!n:10sp +tePopup terminal
,.n:lcd %:p:hSet local current directory
,xn:bp <Bar> bd! #Kill current buffer
,XnOnly()Keep only current buffer (custom)
,en:e <C-R>=expand("%:p:h") . "/"Open file from current directory
<Tab>n:tabnextNext tab
,<Tab>n:$tabnewNew tab
,<S-Tab>nC-wTMove split to new tab
JnmzJ`zJoin lines (cursor stationary)
<C-q>nquickfix_toggle()Close quickfix window (custom)
[Qn:cfirstGo to first quickfix item
]Qn:clastGo to last quickfix item
W!!c:w !sudo tee % >/dev/null<Cr>:e!<Cr>Save as root
<C-s>i<C-g>u<Esc>[s1z=`]a<C-g>uFix last spelling error (repeat.)
,Snvip:sort iuSort in reverse lexicographic order
,Sv:sort uSort in reverse lexicographic order
,snvip:sort uSort in lexicographic order
,sv:sort uSort in lexicographic order
NnNzzKeep cursor centered on screen when looking behind
nnnzzKeep cursor centered on screen when looking ahead
Un<C-r>Redo
zsn1z=Fix spelling using first suggestion
<Backspace>n:nohlClear search highlights
,dfn:setlocal spell!<bar>setlocal spell?<cr>:setlocal spelllang=fr<cr>Toggle spelling on/off (French)
,den:setlocal spell!<bar>setlocal spell?<cr>:setlocal spelllang=en<cr>Toggle spelling on/off (English)
,pn:set invpaste<Cr>:set paste?<Cr>Toggle on/off paste mode
<C-p>n:FilesFuzzy finder for files
<C-s>n:RgCwFzf Rg on current word or project
<C-t>n:TagsCwFzf Tags on current word or project
,,n:BuffersFuzzy finder for buffers
,ggn:GFiles?Git status
,gbn:BCommitsGit buffer commit log
,gcn:CommitsGit commit log
,rn:HistoryOld files
,wwnvim.diagnostic.setqflistShow diagnostics in quickfix (LSP)
[dnvim.diagnostic.goto_prevGo to previous diagnostic (LSP)
]dnvim.diagnostic.goto_nextGo to next diagnostic (LSP)
,wdnvim.diagnostic.open_floatShow diagnostic in a floating window (LSP)
g=nvim.lsp.buf.formatFormat selection (LSP)
z=n,xvim.lsp.buf.code_actionCode action (LSP)
z!n,xvim.lsp.codelens.runCode lens (LSP)
gOnvim.lsp.buf.document_symbol()Show workspace or buffer symbols depending on filetype (LSP)
Knvim.lsp.buf.hoverShow help for current symbol (LSP)
<C-h>ivim.lsp.buf.signature_helpShow signature help (LSP)
gdnvim.lsp.buf.definitionShow definition (LSP)
grnvim.lsp.buf.referencesShow references (LSP)
ginvim.lsp.buf.implementationShow references (LSP)
zrnvim.lsp.buf.renameRename symbol (LSP)

I also have kind of an universal mapping, gs, which depending on filetype may compile a $\LaTeX$ document or a C file and show its output, run a Python/Haskell/Lisp/Scheme script and show its output, etc. It is defined in relevant after/ftplugin/*.vim files. Finally, since I never found a good or reliable plugin to send command to a terminal, and I’ve tried many of the exiting ones for Vim or Neovim, I wrote my own commands: (It assumes that you have a terminal opened next to your buffer in a split, which is how I work in any case.)

" poor man send-to-repl features (we need to fire a REPL in a split first)
noremap ss Vy<C-w>wpa<CR><C-\><C-n><C-w>pj
noremap s y<C-w>wpa<CR><C-\><C-n><C-w>p
xnoremap s y<C-w>wpa<CR><C-\><C-n><C-w>p

  1. When I first drafted this cheatsheet, I was still using 15 plugins or so. Some packages broke at some point and I was too lazy to investigate why, or some were of too little use to justify keeping them. I don’t really miss anything with my current config, though. ↩︎

  2. I recently switched to this leader key after having spent three years using the Space key as my leader, as a leftover of my Doom Emacs period. ↩︎