To enter from command mode:
i : insert before current positiona : insert after current position (append)I : insert at first non-blank char in lineA : insert at last char of the lineHit <Esc> to enter this mode.
Grammar
{operator}{count}{object}
object = {motion, text object}
. : repeat the last commandy : yank/copyc : change; cut and enter insert modeC : change the rest of the current lined : delete; cut but remain in normal modeD : delete the rest of the current linep : paste after the cursorP : paste before the cursoro : insert new line afterO : insert new line beforeSingle char operators (can’t modify with count)
x : delete character under the cursorX : delete characters before the cursorr : replace char under cursor with another chars : substitute char under cursor and move to insert
modeMisc
U : undoCtrl-R : redog~ : toggle casegU : uppercasegu : lowercaseGrammar
{count=N}{motion}
↑
← h j k l →
↓
w / b : jump word to worde / ge: jump to end of wordW / B : jump WORD to WORDE / gE: jump to end of WORDA word is alphanumeric. A WORD is a word and punctuation
.({}),.
0 : the first char of a line^ : the first non-blank char of a line$ : the last char of a lineg_ : the last non-blank char of a linegg : go to line N (default: first line)G : go to line N (default: last line)- : go up to the first non-blank char+ : go down to the first non-blank char) : sentences forward( : sentences backward} : paragraphs forward{ : paragraphs backwardCTRL-D : move down half a pageCTRL-U : move up half a pageH : top line on screenM : middle line on screenL : bottom line on screenzz: center cursor on screenf{char} : jump to next occurrence of char
in a lineF{char} : … prev …t{char} : jump to before the next occurrence of
charT{char} : … to after the prev …; (next) and , (prev): repeat the last
char search/{pattern} : to search forward inside a file?{pattern} : to search backwardsn : jump to next matchN : jump to prev match/<Enter> or ?<Enter>: run the
last search* : to search for the next word under the cursor# : to search for the prev word under the cursor% : jump to matching ({[]})gd : jump to definition of whatever is under your
cursorgf : jump to a file in an importAdjectives
i : insidea : around, inside and surrounding
({[ ]})Nouns
l : letterw : wordW : WORDs : sentencep : paragraphb : ()( : ()B : {}{ : {}t : <>< : <>" : “”' : ’’Some operators (ydc) can be doubled
(e.g. yy) to make them operate on a whole
line.
v : switch to visual mode (character oriented)V : switch to visual mode (line oriented)Ctrl-V : switch to block-visual mode (select rectangles
of text)Once the selection has been made, you can:
J : join all the lines together.< : indent to the left> : indent to the right= : auto indent~ : switch caseu : lower caseU : upper caseA mark (i.e. bookmark)
mx: sets a mark to the cursor location (x
is any of a-z)'x: move to the start of the line containing the mark
(single quote)x: move to the precise location of any mark
(backtick):marks display marks set
"{register}{operator}{count}{object}
" (last changed content)0-9
0 contains the last copied item1-9 is the stack containing prev itemsa-z
A-Z. last inserted text% name of current file: most recently executed command+ system clipboard* selection clipboard (Unix)_: black hole register (not cut)/: last search pattern register:registers (alias :reg) prints contents of
all registers :reg a prints contents of register
a
To write to system register automatically, add this to your vimrc:
clipboard+=unnamedplus
ctrl + R {register} in Insert/Command mode will put
contents at cursor.
:pwd : print working directory:cd <path> : change current directory:f[ile] : current file path:e[dit] <path/to/file>:w[rite] : save:q[uit]:q[uit]! : quit, discarding any changes:saveas <path/to/file> : save to
<path/to/file>:x, ZZ or :wq : save and quit (:x only
save if necessary): Enter command mode R Enter replace mode v Enter visual mode (highlighting) V Enter visual line mode (highlighting lines) esc Return to normal mode from insert or replace mode esc+esc Return to normal mode from command or visual mode
:[range]s/foo/bar/[flags] Replace foo with bar in range according to flags. (if range is empty, then current line)
Ranges
Flags
map <F5> :x <CR> :! nim -c -r %
:nmap for normal mode mappings
:vmap for visual mode mappings
:imap for insert mode mappings
" Example
nnoremap Y y$
`:set bg=dark/light` to change theme
`:echo $MYVIMRC`
# line wrap
:set textwidth=n (or :set tw=n)
:iabbrev forr for(int i=n; i>=0; --i){}
:iab
:sort
:sor! # reverse
# view buffer
:buffers
# to close a buffer
:bd
# run external programs
# prefix with !, % is path
!python %