NeoVIM
- advanced vim topics tips and tricks
- learn vim progressively
- quickfix and location lists in vim
- stop using vim like a pig
- vim mode tips
Help
:h <search>
- also works with keymaps,
:h ^n
to searchCTRL-N
purpose in normal mode:h i_^n
to searchCTRL-N
purpose in insert mode
:helpgrep <search>
search through everything in the vim manual
ZZ and zz
vim has 3 modes:
insert
mode: you write text as if in normal text editor- use the
i
button to switch to this mode - use the
a
button to switch to this mode and move the cursor to the next character - use the
o
button to switch to this mode and add a newline
- use the
normal
mode: provides efficient ways to navigate and manipulate texts- use the
Esc
button to switch to this mode
- use the
visual
mode: select text using movement keys before deciding what to do with it- use the
v
button to switch to this mode - use the
shift+v
buttons to select lines instead of characters
- use the
VIM movement
In normal
mode, you can navigate by using the arrow buttons, but vim has been thought for productivity.
So instead of using the arrow buttons, and thus moving your right hand, vim has a set a buttons for which
you won’t need to move your palms and be able to reach every functionnalities vim has to offer.
So use the following to navigate in your file:
h
: move leftj
: move downk
: move upl
: move rightH
: move to top of screenM
: move to middle of screenL
: move the bottom of screen
You can also move by words:
w
: moves to the start of the next worde
: moves to the end of the wordb
: moves to the beginning of the word
If you want to navigate quickly in your file:
ctrl+d
: page downctrl+u
: page upgg
: go to the first lineG
: go to last line of filegj
/gk
: move cursor up and down to wrapped part of a line as if it’s a different lineg0
/g$
: same as previous but move cursor to the first and last letter of a wrapped linegq
: turn a long line into multiple linesgu
/gU
: uncapitalize / capitalize words / linesg~
: switch capitalization of a lettergf
: open highlighted text as filegv
: re-select previous selected textgJ
: conjoining line without leaving spacesg&
: rerun substitute command for all linesshift+g
: go to the last line<number>g
: go to line “number”5g
: go to line 510g
: go to line 10
0
: move cursor to the beginning of the line$
: move cursor to the end of the line*
: find next occurrence of the word under the cursor#
: find previous occurrence of the word under the cursor%
: go to matching parenthesis/brackets
VIM editing
You don’t have to be in insert
mode to edit text. You can also edit portion of your file in normal
mode.
x
: delete the character under the cursorX
: delete the character to the left of the cursorr
: replace only one character under the cursorcw
: remove character until the end the word and switch toinsert
modec$
: remove character until the end of the line and switch toinsert
modedw
: delete the first word on the right side of the cursor and copies the contentdd
: delete the line and copies the contentyw
: copy wordyy
: copy linep
: paste the copied content.
: repeat the previous command
Search and replace
Still in normal
mode:
/
: search from top to bottom?
: search from bottom to top
Use n
and N
to search next and previous occurrence, respectively.
To replace, you can use the same syntax as sed
command:
:s/wordtoreplace/replacedword/
: only replace the first instance of “wordtoreplace” of the line where the cursor is:%s/wordtoreplace/replacedword/
: apply to the entire file:%s/wordtoreplace/replacedword/g
: apply to all instances
Other VIM commands
In normal
mode:
:w
: save file:q
: quit file edition:q!
: force quit:wq
: save and quit file edition:x
: save and quit the file edition:set invnumber
: display/hide line numbers:set invpaste
: format/do not format copied content (useful when copy pasting formatted code)
In insert
mode:
- press the
ctrl+n
for autocompletion
Undo
You can undo the last action by pressing the u
button in normal
mode.
If you want to undo the undo, you can press the ctrl+r
buttons.
Going further with VIM
I did not cover everything, only what’s needed to be able to perform basic edition on files using VIM.
There are lot of tutorials out there:
- VIM offial website
- VIM wikipedia
- openvim
- VIM adventures
:help tutor
: launch VIM own tutorial- …