{ claus.conrad }

Neovim

https://neovim.io/

Shortcuts

  • Remember that Neovim is very customizable, so any shortcuts shown here might not be configured in your installation.
ShortcutIn modeFunction
:NORMALSwitch to COMMAND-LINE mode
:!commandNORMALExecute “command” (using the shell)
:#,#s/old/new/gNORMALReplace all occurences of “old” on lines #-# with “new”
:%s/old/new/gNORMALReplace every occurence of “old” in the whole file with “new”
:%s/old/new/gcNORMALReplace every occurence of “old” in the whole file with “new”, but ask for confirmation (y/n) for each substitution
:r FILENAMENORMALInsert contents of FILENAME below cursor position
:r! COMMANDNORMALInsert output of external COMMAND below cursor position
:s/old/new/NORMALReplace first occurence of “old” on the current line with “new”
:s/old/new/gNORMALReplace all occurences of “old” on the current line with “new”
:set invOPTIONNORMALToggles a boolean option
:set noOPTIONNORMALDisables an option
:setOPTIONNORMALSets an option
?TERMNORMALSearch backwards (behaves the same as /, except the first result is searched for toward the top of the file instead of downwards, and n goes up and N goes down)
/TERMNORMALSearch for term (forward in the document)
%NORMALMove to matching bracket ((), [], {})
^NORMALMove to the first non blank character on the current line
$NORMALMove to the end of the current line
0NORMALMove to the beginning of the current line
1G, 1ggNORMALMove to first line
aNORMALSwitch to INSERT mode after the current character
ANORMALSwitch to INSERT mode after the end of the current line
bNORMALMove to previous word (“backwards”)
bdCOMMANDClose current buffer
c+motionNORMALChange text (deletes and places in INSERT mode)
Ctrl+Alt+VINSERTPaste
Ctrl+dCOMMANDSuggest completion for the partially typed command
Ctrl+DNORMALMove half a screen downward
Ctrl+gNORMALShow file name, total number of lines and relative position
Ctrl+iNORMALGo ahead to next cursor position in the jump list
Ctrl+oNORMALGo back to previous cursor position in the jump list
Ctrl+rNORMALRedo
Ctrl+uNORMALMove half a screen upward
Ctrl+wNORMALStart window management (needs further keypresses to do something)
Ctrl+w Ctrl+wNORMALSwitch windows
d+motionNORMALDelete
ddNORMALDelete line
Esc, Ctrl+CAny except NORMALSwitch back to NORMAL mode
F1NORMALOpen help in a new “window”
GNORMALGo to the end of the file
ggNORMALGo to the beginning of the file
gUiwNORMALSwitch the word under cursor to uppercase
hNORMAL⬅️ Move cursor left
helpCOMMANDOpen help in a new “window”
iNORMALSwitch to INSERT mode before the current character
jNORMAL⬇️ Move cursor down
kNORMAL⬆️ Move cursor up
lNORMAL➡️ Move cursor right
nNORMALNext search result
nohlsearchCOMMANDRemove highlighting of matches (after enabling it with :set hlsearch)
NNORMALPrevious search result
number+GNORMALMove to line <number>
oNORMALOpen a new line below the current and switch to INSERT mode
ONORMALOpen a new line above the current and switch to INSERT mode
pNORMALInsert deleted/yanked text after cursor (whole lines go below)
PNORMALInsert deleted/yanked text before cursor (whole lines go above)
qCOMMAND-LINEQuit (current window; or the whole app, if this is the last/only window open within Neovim)
q!COMMAND-LINEQuit without saving (current window; or the whole app, if this is the last/only window open within Neovim)
rNORMALReplace one character
RNORMALReplace multiple characters (i.e., “overwrite”)
uNORMALUndo
UNORMAL“Undo line” (resets the current line to its original state, possibly undoing multiple commands - but it does not correspond to multiple u in a row, because U itself can be undone…)
vNORMALSwitch to VISUAL mode
wNORMALMove to next word
wCOMMAND-LINE“Write” (save)
w FILENAMECOMMAND-LINE“Write” (save) the current file as FILENAME
w FILENAMEVISUAL“Write” (save) the current selection as FILENAME
wqCOMMAND-LINE“Write” (save) and quit
xNORMALDelete character under cursor
<VISUALOutdent (shift left) selected lines
yVISUAL“Yank” (copy) selection
y+motionNORMAL“Yank” (copy) text indicated by motion
<VISUALOutdent (shift left) selected lines
*NORMALSearch for the word under the cursor

Motions

CharacterMeaning
wUntil start of next word
eUntil end of current word
$To the end of the line

Options

OptionMeaning
ignorecase, icIgnore case when searching
hlsearch, hlsHighlight results of last search
incsearch, isHighlight search results incrementally (while typing term)

FAQ

![[r.dev.building-your-mouseless-development-environment.notes#First Steps In Neovim]]

Show unsaved changes

:w !git diff --no-index % -

Enter key does not insert autocomplete suggestion

Highlight TODO

Switch to a terminal

  • This can be achieved using standard shell features:
    • Ctrl+Z to suspend Neovim
    • fg to switch back to Neovim
  • Or with the :terminal command
    • Switch to “INSERT” mode with “i” as usual to type in the shell
    • Exit the shell with Ctrl+D and (maybe?) :bd

Resources

Learning

:Tutor

Tutor is an integrated command that starts a tutorial of approx. 30 minutes length. These are my notes from that tutorial.

  • The correct order is “operator number motion”, e.g. “d2w” to delete 2 words
  • The command to delete 2 lines is 2dd, not d2d
  • The remaining learnings from :Tutor have been added to the [[#Shortcuts]] list

Plugins