aliquote

< a quantity that can be divided into another a whole number of time />

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

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 misunderstoof the role of 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
,ln<C-^>Alternate buffer
,!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:tabe <C-R>=expand("%:p:h") . "/"Open file in new tab from current directory
,en:e <C-R>=expand("%:p:h") . "/"Open file from current directory
<C-Left>n:tabprevPrevious tab
<C-Right>n:tabnextNext tab
<Tab>n:tabnextNext tab
,<Tab>n:$tabnewNew tab
,<S-Tab>nC-wTMove split to new tab
JnmzJ`zJoin lines (cursor stationary)
<v<gvFix block indentation (backward)
>v>gvFix block indentation (forward)
<C-q>nquickfix_toggle()Close quickfix window (custom)
[Qn:cfirstGo to first quickfix item
]Qn:clastGo to last quickfix item
<C-h>n:vertical resize -4Resize split (left)
<C-j>n:resize -4Resize split (down)
<C-k>n:resize +4Resize split (up)
<C-l>n:vertical resize +4Resize split (right)
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
^n:set hls!<Bar>set hls?Toggle on/off search highlights
<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)
<C-s>n:let @s='\<'.expand('<cword>').'\>'<Cr>:%s/<C-r>s//<Left>Substitute current word
<C-s>xsy:%s/<C-r>s//<Left>Substitute current word
,pn:set invpaste<Cr>:set paste?<Cr>Toggle on/off paste mode
YYn,v"+yYank to clipboard
<C-f>n:Grep<Space>Grep (custom)
<C-p>n:Telescope find_filesFuzzy finder for files
,/n:Telescope current_buffer_fuzzy_findFuzzy search in buffer
,:n:Telescope command_historyFuzzy finder for command history
,,n:Telescope buffersFuzzy finder for buffers
,fn:Telescope live_grepLive grep in working directory
,*n:lua require('telescope.builtin').grep_string({search = vim.fn.expand("<cword>")})Fuzzy grep current word in working directory
,ggn:Telescope git_statusGit status
,gCn:Telescope git_commitsGit commit log
,gcn:Telescope git_bcommitsGit buffer commit log
,gbn:Telescope git_branchesGit branches
,gsn:Telescope git_stashGit stash
,qn:Telescope quickfixTelescope quickfix
,rn:Telescope oldfilesTelescope old files
,wwn:Telescope diagnosticsLSP diagnostics
,Tn:TestFileTest file (vimtest)
,tn:TestNearestTest nearest (vimtest)
sv,xy<C-w>wpa<CR><CR><Esc>Send selection to nearest terminal
ssnVy<C-w>wpa<CR><CR><Esc>Send line to nearest terminal
gKn:DashtQuery documentation from Dash
,wqnvim.diagnostic.setqflistShow diagnostics in quickfix (LSP)
[wnvim.diagnostic.goto_prevGo to previous diagnostic (LSP)
]wnvim.diagnostic.goto_nextGo to next diagnostic (LSP)
,wdnvim.diagnostic.open_floatShow diagnostic in a floating window (LSP)
g=xvim.lsp.buf.range_formattingFormat selection (LSP)
g=nvim.lsp.buf.formattingFormat selection (LSP)
z=n,xvim.lsp.buf.code_actionCode action (LSP)
g0nrequire("telescope.builtin").lsp_workspace_symbolsShow workspace symbols (LSP)
Knvim.lsp.buf.hoverShow help for current symbol (LSP)
<C-h>ivim.lsp.buf.signature_helpShow signature help (LSP)
gdnrequire("telescope.builtin").lsp_definitionsShow definition (LSP)
grnrequire("telescope.builtin").lsp_referencesShow references (LSP)
zrnvim.lsp.buf.renameRename symbol (LSP)
ginvim.lsp.buf.implementationShow implementation (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><CR><Esc>
noremap s y<C-w>wpa<CR><CR><Esc>
xnoremap s y<C-w>wpa<CR><CR><Esc>

  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. ↩︎