Vi / Vim / Neovim🔗
General Informations🔗
There are several starting point for informations:
- Quick reference guide:
:help quickref - User manual:
:help usr_toc - Reference manual:
:help reference_toc
Motions🔗
See: :help motion
Left-Right Motions🔗
0- move to first character in current line^- move to first non-blank character in current line$- move to last character in current linefchar- move to charactercharto the rightcf>- change up to next character>- including match
Fchar- move to charactercharto the lefttchar- move to before charactercharto the rightdt)- delete up to next character)- excluding match
Tchar- move to after charactercharto the left;- repeat latestf,F,t,Tmovement,- repeat latestf,F,t,Tmovement in opposite direction
Up-Down Motions🔗
gg- go to first line in fileG- go to last line in filecountG- go to lastcountline in filecountgo- go tocountbyte
Word Motions🔗
See: :help word-motions
w- word forwardW- WORDS forward (WORDS are words with special characters)
Text Object Motions🔗
See: :help object-motions
)- sentence forward}- paragraph forward]]- section forward
Text Object Selection🔗
See: :help text-objects
- commands starting with
aselects an object with whitespaces - commands starting with
iselects an inner object without whitespaces - objects
- quotes:
da"- delete around quotes orda' - brackets:
di]- delete inside brackets - braces:
ci{- change inside braces - paragraph:
dap- delete inside paragraph - word:
vaw- visual select around word - WORD:
vaW- visual select around WORD - tag:
vit- visual select inside tag orvi<
- quotes:
Quickfix🔗
See: :help quickfix
The quickfix commands are used to work with a list of positions in files. A location list is a window-local quickfix list.
:vim word ** or :vim /pattern/ ** searches the word or pattern in all files
recursively beneath the current directory. And opens the first location. After
that the following commands are working on this quickfix list.
:copen- open the quickfix list:cfirst/:clast- open the first resp. last location:cnext/:cprev- open the next resp. previous location:cc4- open the fourth location:ccloseor:ccl- close the quickfix list:colder/:cnewer- open the older resp. newer quickfix list (within the last ten):cdocmd - execute cmd on each location:cdo s/Foo/Bar/- replace Foo with Bar at each location:cdo s/Foo/Bar/ | update- store each buffer after executing the command
:cfdocmd - execute cmd on each file in the quickfix list:cdo bd- close all buffers from the quickfix list
Commands starting with g🔗
See: :help *g*
ga- print ASCII value of character under the cursorgqmotion- format text described bymotiongwmotion- format text described bymotionwithout cursor movement
Jump through or work with changes:
g;- jump to last changeg,- jump forward through the change list:changes- show the last 100 changesu- undo changes<C-r>- redo changes
Misc🔗
Search in Key Mappings🔗
Besides the plugin Telescope the command :filter allows to search through all
available key mappings.
Search for key mappings in insert mode:
Search for key mappings in normal mode:
To print the content of a mapping:
Clear Search Highlight🔗
With the option :hlsearch all matches of the last search are highlighted. To
clear all highlights the command :nohlsearch can be used. Often this command
is mapped to C-L. In NeoVim the following default mapping exists:
Indenting Code🔗
With == or = code can be formatted.
==- indent current line>>- increase current indentation level be one<<- decrease current indentation level be one
4==- indent four lines (including current line)V3j=- same indentation by using visual selection
=ap- indent current paragraphgg=G- indent whole file=%- when cursor is on{or}indent whole code block
Avoid Wrong Formatting During Paste🔗
Set the configuration :set paste before pasting into Vi. Disable this option
afterwards with :set nopaste.
Remove Lines Matching a Pattern🔗
:g/pattern/d- remove lines that do match the pattern:g!/pattern/d- remove lines that do not match the pattern
Non-Greedy Regular Expression🔗
See: :help non-greedy
The regular expression ".*" will select "key1": "valueA" because it is
greedy. It tries to match as many as possible characters.
The regular expression ".\{-\}" will select only "key1". It will match the
fewest number of characters as possible. The last \ is optional, so the
expression ".\{-}" is also possible.