VIM Editor

From OasisSoftTech.com - Knowledge Base/Java/Springframework/Microservices/Cloud-AWS/AI
Revision as of 02:25, 1 November 2018 by Rasimsen (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

VIM QUICK REFERENCE CARD


Basic movement
h l k jcharacter left, right; line up, down
b wword/token left, right
ge eend of word/token left, right
{  }beginning of previous, next paragraph
( )beginning of previous, next sentence
0 gmbeginning, middle of line
^  $first, last character of line
nG nggline n, default the last, first
n%percentage n of the file (n must be provided)
n|column n of current line
%match of next brace, bracket, comment, #define
nH nLline n from start, bottom of window
Mmiddle line of window

Insertion & replace insert mode
i ainsert before, after cursor
I Ainsert at beginning, end of line
gIinsert text in first column
o Oopen a new line below, above the current line
rcreplace character under cursor with c
grclike r, but without affecting layout
Rreplace characters starting at the cursor
gRlike R, but without affecting layout
cmchange text of movement command m
cc or Schange current line
Cchange to the end of line
schange one character and insert
~switch case and advance cursor
g~mswitch case of movement command m
gum gUmlowercase, uppercase text of movement m
<m >mshift left, right text of movement m
n<< n>>shift n lines left, right

Deletion
x Xdelete character under, before cursor
dmdelete text of movement command m
dd Ddelete current line, to the end of line
J gJjoin current line with next, without space
:rddelete range r lines
:rdxdelete range r lines into register x

Insert mode
^Vc ^Vninsert char c literally, decimal value n
^Ainsert previously inserted text
^@same as ^A and stop insert command mode
^Rx ^R^Rxinsert content of register x, literally
^N ^Ptext completion before, after cursor
^Wdelete word before cursor
^Udelete all inserted character in current line
^D ^Tshift left, right one shift width
^Kc1c2 or c1c2enter digraph \c1,c2\
^Ocexecute c in temporary command mode
^X^E ^X^Yscroll up, down
<esc> or ^[abandon edition command mode

Copying
"xuse register x for next delete, yank, put
:regshow the content of all registers
:reg xshow the content of registers x
ymyank the text of movement command m
yy or Yyank current line into register
p Pput register after, before cursor position
]p [plike p, P with indent adjusted
gp gPlike p, P leaving cursor after new text

Advanced insertion
g?mperform rot13 encoding on movement m
n^A n^X+n, -n to number under cursor
gqmformat lines of movement m to fixed width
:rce wcenter lines in range r to width w
:rle ileft align lines in range r with indent i
:rri wright align lines in range r to width w
!mcfilter lines of movement m through command c
n!!cfilter n lines through command c
:r!cfilter range r lines through command c

Visual mode
v V ^Vstart/stop highlighting characters, lines, block
oexchange cursor position with start of highlighting
gvstart highlighting on previous visual area
aw as apselect a word, a sentence, a paragraph
ab aBselect a block ( ), a block { }

Undoing, repeating & registers
u Uundo last command, restore last changed line
.  ^Rrepeat last changes, redo last undo
nrepeat last changes with count replaced by n
qc qCrecord, append typed characters in register c
qstop recording
@cexecute the content of register c
@@repeat previous @ command
:@cexecute register c as an Ex command
:rg/p/cexecute Ex command c on range r
where pattern p matches

Complex movement
- +line up, down on first non-blank character
B Wspace-separated word left, right
gE Eend of space-separated word left, right
n_down n-1 line on first non-blank character
g0beginning of screen line
g^  g$first, last character of screen line
gk gj screen line up, down
fc Fcnext, previous occurence of character c
tc Tcbefore next, previous occurence of c
; ,repeat last fFtT, in opposite direction
[[ ]]start of section backward, forward
[] ][end of section backward, forward
[( ])unclosed (, ) backward, forward
[{  ]}unclosed {, } backward, forward
[m ]mstart of backward, forward Java method
[# ]#unclosed #if, #else, #endif backward, forward
[* ]*start, end of /* */ backward, forward

Search & substitution
/s  ?ssearch forward, backward for s
/s/o  ?s?osearch fwd, bwd for s with offset o
or /repeat forward last search
or ?repeat backward last search
# *search backward, forward for word under cursor
g# g*same, but also find partial matches
gd gDlocal, global definition of symbol under cursor
:rs/f/t/xsubstitute f by t in range r
x: g-all occurrences, c-confirm changes
:rs xrepeat substitution with new r & x

Special characters in search patterns
.   ^  $any single character, start, end of line
\< \>start, end of word
[c1-c2]a single character in range c1..c2
[^c1-c2]a single character not in range
\i \k \I \Kan identifier, keyword; excl. digits
\f \p \F \Pa file name, printable char.; excl. digits
\s \Sa white space, a non-white space
\e \t \r \b<esc>, <tab>, <>, <>
\= * \+match 0..1, 0.., 1.. of preceding atoms
\|separate two branches (  or)
\( \)group patterns into an atom
\& \nthe whole matched pattern, nth () group
\u \lnext character made upper, lowercase
\c \Cignore, match case on next pattern

Offsets in search commands
n or +nn line downward in column 1
-nn line upward in column 1
e+n e-nn characters right, left to end of match
s+n s-nn characters right, left to start of match
;scexecute search command sc next

Marks and motions
mcmark current position with mark [a..Z]
`c `Cgo to mark c in current, C in any file
`0..9go to last exit position
`` `"go to position before jump, at last edit
`[ `]go to start, end of previously operated text
:marksprint the active marks list
:jumpsprint the jump list
n^Ogo to nth older position in jump list
n^Igo to nth newer position in jump list

Key mapping & abbreviations
:map c emap e in normal & visual mode
:map!  c emap e in insert & cmd-line mode
:unmap c  :unmap!  cremove mapping c
:mk fwrite current mappings, settings... to file f
:ab c eadd abbreviation for e
:ab cshow abbreviations starting with c
:una cremove abbreviation c

Tags
:ta tjump to tag t
:ntajump to nth newer tag in list
^] ^Tjump to the tag under cursor, return from tag
:ts tlist matching tags and select one for jump
:tj tjump to tag or select one if multiple matches
:tagsprint tag list
:npo  :n^Tjump back from, to nth older tag
:tljump to last matching tag
^W}  :pt tpreview tag under cursor, tag t
^W]split window and show tag under cursor
^Wz or :pcclose tag preview window

Scrolling & multi-windowing
^E ^Yscroll line up, down
^D ^Uscroll half a page up, down
^F ^Bscroll page up, down
zt or zset current line at top of window
zz or z.  set current line at center of window
zb or z-set current line at bottom of window
zh zlscroll one character to the right, left
zH zLscroll half a screen to the right, left
^Ws or :splitsplit window in two
^Wn or :newcreate new empty window
^Wo or :onmake current window one on screen
^Wj ^Wkmove to window below, above
^Ww ^W^Wmove to window below, above (wrap)

Ex commands ()
:e fedit file f, unless changes have been made
:e!  fedit file f always (by default reload current)
:wn :wNwrite file and edit next, previous one
:n :Nedit next, previous file in list
:rwwrite range r to current file
:rw fwrite range r to file f
:rw>>fappend range r to file f
:q :q!quit and confirm, quit and discard changes
:wq or :x or ZZwrite to current file and exit
<up> <down>recall commands starting with current
:r finsert content of file f below cursor
:r!  cinsert output of command c below cursor
:argsdisplay the argument list
:rco  a :racopy, move range r below line a

Ex ranges
, ;  separates two lines numbers, set to first line
nan absolute line number n
.   $the current line, the last line in file
% *entire file, visual area
'tposition of mark t
/p/ ?p?the next, previous line where p matches
+n -n+n, -n to the preceding line number

Folding
zfmcreate fold of movement m
:rfocreate fold for range r
zd zEdelete fold at cursor, all in window
zo zc zO zCopen, close one fold; recursively
[z ]zmove to start, end of current open fold
zj zkmove down, up to start, end of next fold

Miscellaneous
:sh  :!cstart shell, execute command c in shell
Klookup keyword under cursor with man
:makestart make, read errors and jump to first
:cn  :cpdisplay the next, previous error
:cl  :cflist all errors, read errors from file
^L ^Gredraw screen, show filename and position
g^Gshow cursor column, line, and character position
gashow ASCII value of character under cursor
gfopen file which filename is under cursor
:redir>fredirect output to file f
:mkview [f]save view configuration [to file f]
:loadview [f]load view configuration [from file f]
^@ ^K ^_  \  Fn ^Fnunmapped keys

source: http://tnerual.eriogerg.free.fr/vimqrc.html