General Purpose Cheatsheets
Commands I forget a lot
:set [setting-name]?
to view the current setting value.:echo &rtp
to view the runtime path of files that vim checks when running functions.:help rtp
for more.- when you want to reload
.vimrc
without leaving vim, execute:source ~/.vimrc
Macros
Type qa
to start "recording" into register a
(I think available registers are a-z
and 0-9
and perhaps some special characters as well). This will record an arbitrary sequence of keystrokes, which is the macro itself. Pressing q
a second time will end the recording. That macro is now "registered". In order to play back that macro you type @a
. I'm not sure how to repeat it via .
, but you can repeat it n-many times by typing 3@a
for example.
TLDR: qa
then arbitrary sequence then q
to record macro in register a. Then, @a
to play the macro again.
Multiple occurrence
next word
*
will select the next word that occurs in that file. n
will then move you to the next next word repeatedly. I think you are in some kind of visual mode at this point.
word replacement
Assuming you are in the #next word state, cgn
changes the current selected word. .
will repeat the change-word action for next next word repeatedly.
Restart lsp server when it crashes in neovim
The quickest solution is :e
. This somehow reloads the buffer, which allows for reattachment of LSP. I'm not sure if you have to wait for some form of LSP reboot, since the LSP server is what crashed. But if it does have auto-restart enabled, it should "just work", at least after some time.
Undo and Redo
u
in normal mode, or :undo
, will undo the lastest vim changes.
ctrl-r
in normal mode, or :redo
, will redo the undone vim changes.
Tabs
gt
next tabgT
previous tab
Movement commands
(
and)
move to the next sentence{
and}
move to the next paragraph
Folding
za
toggle single-fold open or closedzc
single-fold closezo
single-fold openzM
fold everythingzR
open everything
Autoload directory
The autoload directory will reactively load files as you need them, as opposed to some otherwise upfront load that could result in a slow startup. This is especially relevant for larger libraries, or for when you have many libraries. I understand it as lazy loading, essentially. I.e., load the file only when you are literally about to execute a function from within it.