Skip to content

Neovim

https://neovim.io/

  • Remember that Neovim is very customizable, so any shortcuts shown here might not be configured in your installation.
Shortcut In mode Function
: NORMAL Switch to COMMAND-LINE mode
:!command NORMAL Execute “command” (using the shell)
:#,#s/old/new/g NORMAL Replace all occurences of “old” on lines #-# with “new”
:%s/old/new/g NORMAL Replace every occurence of “old” in the whole file with “new”
:%s/old/new/gc NORMAL Replace every occurence of “old” in the whole file with “new”, but ask for confirmation (y/n) for each substitution
:r FILENAME NORMAL Insert contents of FILENAME below cursor position
:r! COMMAND NORMAL Insert output of external COMMAND below cursor position
:s/old/new/ NORMAL Replace first occurence of “old” on the current line with “new”
:s/old/new/g NORMAL Replace all occurences of “old” on the current line with “new”
:set invOPTION NORMAL Toggles a boolean option
:set noOPTION NORMAL Disables an option
:set OPTION NORMAL Sets an option
?TERM NORMAL Search 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)
/TERM NORMAL Search for term (forward in the document)
% NORMAL Move to matching bracket ((), [], {})
^ NORMAL Move to the first non blank character on the current line
$ NORMAL Move to the end of the current line
0 NORMAL Move to the beginning of the current line
1G, 1gg NORMAL Move to first line
a NORMAL Switch to INSERT mode after the current character
A NORMAL Switch to INSERT mode after the end of the current line
b NORMAL Move to previous word (“backwards”)
bd COMMAND Close current buffer
c+motion NORMAL Change text (deletes and places in INSERT mode)
Ctrl+Alt+V INSERT Paste
Ctrl+d COMMAND Suggest completion for the partially typed command
Ctrl+D NORMAL Move half a screen downward
Ctrl+g NORMAL Show file name, total number of lines and relative position
Ctrl+i NORMAL Go ahead to next cursor position in the jump list
Ctrl+o NORMAL Go back to previous cursor position in the jump list
Ctrl+r NORMAL Redo
Ctrl+u NORMAL Move half a screen upward
Ctrl+w NORMAL Start window management (needs further keypresses to do something)
Ctrl+w Ctrl+w NORMAL Switch windows
d+motion NORMAL Delete
dd NORMAL Delete line
Esc, Ctrl+C Any except NORMAL Switch back to NORMAL mode
F1 NORMAL Open help in a new “window”
G NORMAL Go to the end of the file
gg NORMAL Go to the beginning of the file
gUiw NORMAL Switch the word under cursor to uppercase
h NORMAL ⬅️ Move cursor left
help COMMAND Open help in a new “window”
i NORMAL Switch to INSERT mode before the current character
j NORMAL ⬇️ Move cursor down
k NORMAL ⬆️ Move cursor up
l NORMAL ➡️ Move cursor right
n NORMAL Next search result
nohlsearch COMMAND Remove highlighting of matches (after enabling it with :set hlsearch)
N NORMAL Previous search result
number+G NORMAL Move to line <number>
o NORMAL Open a new line below the current and switch to INSERT mode
O NORMAL Open a new line above the current and switch to INSERT mode
p NORMAL Insert deleted/yanked text after cursor (whole lines go below)
P NORMAL Insert deleted/yanked text before cursor (whole lines go above)
q COMMAND-LINE Quit (current window; or the whole app, if this is the last/only window open within Neovim)
q! COMMAND-LINE Quit without saving (current window; or the whole app, if this is the last/only window open within Neovim)
r NORMAL Replace one character
R NORMAL Replace multiple characters (i.e., “overwrite”)
u NORMAL Undo
U NORMAL “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…)
v NORMAL Switch to VISUAL mode
w NORMAL Move to next word
w COMMAND-LINE “Write” (save)
w FILENAME COMMAND-LINE “Write” (save) the current file as FILENAME
w FILENAME VISUAL “Write” (save) the current selection as FILENAME
wq COMMAND-LINE “Write” (save) and quit
x NORMAL Delete character under cursor
< VISUAL Outdent (shift left) selected lines
y VISUAL “Yank” (copy) selection
y+motion NORMAL “Yank” (copy) text indicated by motion
< VISUAL Outdent (shift left) selected lines
* NORMAL Search for the word under the cursor
Character Meaning
w Until start of next word
e Until end of current word
$ To the end of the line
Option Meaning
ignorecase, ic Ignore case when searching
hlsearch, hls Highlight results of last search
incsearch, is Highlight search results incrementally (while typing term)
:w !git diff --no-index % -

Enter key does not insert autocomplete suggestion

Section titled “Enter key does not insert autocomplete suggestion”
  • 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

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