Sei sulla pagina 1di 2

Vim Command Summary

https://github.com/praful/vim-cheatsheet Updated: 2019/04/17 Move forward/back to string matching the one gu, gU{motion} Lowercase / uppercase
*, #
under cursor. Precede by g for embedded match. ~ Toggle case and move right.
General pattern commands: [n] command [m] movement (lower/uppercase i) In status bar, show first/all Switch case of word / lowercase word /
[i , [I g~w, guw, gUw
lines containing word under cursor uppercase word
Line number
Movement Commands CTRL-G
CTRL-A, CTRL-X Increment / decrement number under cursor
Display current line number . (period) Repeat last edit command
Character nG Move to line number n u, CTRL-R, U Undo / redo / restore current line
h, j, k, l Left, down, up, right (3j moves down 3 lines) gg, G Move to first / last line in file j , gJ Join two lines / join without space
Text :n Move to line number n Copy (yank), paste, delete
Forward, backward by word/WORD Bookmarks yw, y$, :%y Yank (copy) word / line / buffer
w, W, b, B (lowercase w, b: letters, numbers, underscore Bookmark current position as x (uppercase mark yy, 5yy Yank current line / next five lines
make up word; uppercase W, B: separator is mx
eg mX set global mark, ie file and location)
"ayy Yank current line into named buffer a
whitespace) `x (back tick) Move cursor to x
e, E y’x Yank from mark x to cursor
End of word/WORD 'x (apostrophe) Move to start of line containing x
ge, gE p, P Put yanked text after / before cursor
End of previous word/WORD `` (2 back ticks) Return to position before most recent jump
), ( ]p , [p Like p, P with indent adjusted
Beginning of next, previous sentence '' (2 apostrophes) Like preceding, but return to start of line
}, { gp , gP Like p, P leaving cursor after new text
Beginning of next, previous paragraph
`. (back tick period) Move to last change
Beginning of next, previous section (or function in "aP Put text from buffer a before cursor
]], [[ `[ , `] Go to start, end of previously operated text
C, Java, etc) Put text from delete buffer number n after cursor
Move backwards and forwards in jumplist. See "np
% Move to matching brace, paren, etc CTRL-O, CTRL-I (for last nine deletions)
:help jumplist x
Line Delete character
gi go to and insert text at last edit X
0, $ First/last position of current line Delete character before cursor
Move backwards and forwards in changelist. See Delete word / line / upto S (c and d both cut but c
^, g_ First/last character of current line (ignore spaces) g; and g,
:help changelist
dw, dd, dfS, d^, stays in insert mode) / to beginning / to pattern /
+, - First character of next, previous line :marks List active marks d/pat, dn, dL, dG to next pattern / to end screen / to end file. 10dd
n| Column n of current line :jumps List jumps deletes 10 lines. dwwP transposes two words.
H, M, L Top / middle / last line of screen :reg x Show registers or register x D Delete to end of line
nH n (number) of lines after top line di> Delete inner block delimited by >
nL n (number) of lines before last line d’x Del from mark x to cursor
Editing Commands
gm middle of line Insert mode
Screens Select CTRL-R"
Paste last yank/delete. Instead of “, use %
CTRL-F, CTRL-B Scroll forward, backward one screen v, V, CTRL-V Select character / line / block (visual mode) (filename), + (clipboard)
CTRL-D, CTRL-U Scroll down, up one-half screen gv Reselect previous selection CTRL-A Repeat last insertion
CTRL-E, CTRL-Y Scroll line up, down Exchange cursor position between start/end of CTRL-D, CTRL-T Shift line left/right to previous shift width
o
z <Enter> or zt Reposition line with cursor: to top of screen selection CTRL-E Insert character found just below cursor
z. or zz Reposition line with cursor: to middle of screen Select a word / a sentence / a paragraph / CTRL-H Delete prev char (=backspace)
vaw, vas, vap, a () block / a {} block. Can use other verbs, eg CTRL-I Insert a tab
z- or zb Reposition line with cursor: to bottom of screen
vab, vaB delete, yank to act on object. Also i instead of a
CTRL-L Redraw screen (without scrolling) CTRL-K Begin insertion of multi-stroke char
acts inside object (a acts around)
% Go to matching pair, eg (), {}, [] Insert next/previous completion of the pattern to
Insert CTRL-N, CTRL-P
the left of the cursor
Searches i, a Insert text before / after cursor CTRL-O command Execute one command eg dw
/pattern Search forward for pattern I, A Insert text at beginning / end of line CTRL-X + CTRL-L Show list of completions for current line
?pattern Search backward for pattern o, O Open new line for text below / above cursor CTRL-X + CTRL-F Filename completion
n, N Repeat last search in same, opposite direction
Change CTRL-U Delete from cursor to start of line
/ , ? Repeat previous search forward, backward r, R Change character / overwrite characters CTRL-V Insert next char verbatim
fx Search forward for character x in current line Begin change / change word / line (stay in insert CTRL-W Delete prev word
Fx Search backward for character x in current line c{motion}, cw,
mode) / change next two words / change to end
cc, 2cw, cG, caw CTRL-Y Insert char found just above cursor
Search forward for character before x in current of file / change word (when in middle)
tx CTRL-[ End insert mode (=ESC)
line C Change to end of line
Search backward for character after x in current C% Change text in next group
Tx
line R Type over characters
Repeat previous current-line search forward /
; , , Delete character (=cl) / delete line and substitute
backward s, S
text
Other Commands CTRL-W j, k Move cursor to next/previous window :%s/old/new/g Substitute in current file
CTRL-W h, l, t, b Move cursor to left/right/top/bottom window Substitute in all lines after current. Can use line
CTRL-W K, B, H, :.+1,$s/old/new/g numbers (eg 3,45s/…) and marks (eg
Command line mode Move current window top/bottom/far left/far right ‘a,’bs/…)
L
CTRL-B, CTRL-E Beginning/end of line CTRL+W f :^,.s/old/new/g Substitute from start of file to cursor
Open file at cursor in new windows / tab
Open command history in new buffer (like q: in CTRL+W gf Escapes regex Eg
CTRL-F normal mode). Use CTRL-C to paste line in CTRL+W r, R Rotate windows down/up \v :%s/\(good\|nice\)/awesome/g can be written
history or press Enter to run command. as %s/\v(good|nice)/awesome/g
CTRL+W +, - Increase/decrease current window size
CTRL-N, CTRL-P Next/previous command in history :& Repeat last substitute command
CTRL+W = Make all windows the same height
CTRL-H, CTRL-R, :d Delete lines
CTRL-U, CTRL-W
As insert mode Miscellaneous commands and options
:m Move lines, eg :30,60m0 ($ to move to end)
:sort u / n Sort, remove duplicates / Sort by number
Insert next non-digit literally. You can enter funky :co or :t Copy lines, eg :5,10t105
keys by pressing ctrl-v first, and then the :sh Start a shell
Copy from current line through line containing
keystroke. This is most useful in help, eg type :so % Source current file, eg vimrc after changes :.,/pattern/co$
CTRL-V pattern to end of file
:help ^v^t to get help for the keystroke ctrl- Execute command on all buffers eg command
t. For this, though, you can also just type :help :bufdo command :d Delete lines, eg 3,10d
bdelete closes all open buffers
ctrl-t. Execute cmd on all lines containing pat. Use ! for
:set list Display tabs and eol character
text UP-ARROW or Searches history for previously entered all lines not containing pattern. eg g/Unix/p
Display help for options and show current values prints all lines containing Unix;
text DOWN-ARROW commands starting with text :options :g[!]/pat/cmd
(:set all dumps settings) g/Name:/s/tom/Tom/ change "tom" to "Tom" on
Shell and Shell Filtering :set ft=html Set filetype to html (use any ext.) all lines containing "Name:". :v is the same as
:r !command Read in output from command after current line :g!. See referemce 1 for examples.
:helptags
:!command Run command, then return Install help file
~/vimfiles/doc :center Centre line
Send the text covered by motion to Unix :verbose map key Shows where key was mapped
!{motion}command
command; replace with output
:verb set str Shows where str was set
:n,m!command Send lines n-m to command; replace with output File Commands
:let g: :let v: Show global/local variables
Send num lines Unix command; replace with ZZ or :x or :wq Write (save) and quit file
num!!command :set [no]spell Disable/enable spellchecking
output
Suggest corrections, next/prev spelling error, :w Write (save) file
:!! Repeat last system command z=, ]s,[s, zg,zw
add/remove word to exception list :w! Write (save) file (overriding protection)
!!command Pass current line only through command
:set path=path Search path for files :30,60w newfile Write from line 30 through line 60 as newfile
Pass area from current line through end of
!}command :sh Start shell Write from line 30 through line 60 and
paragraph through command :30,60w>>file
:noh remove highlight on highlighted text append to file
Pass area from current line through end of file
!Gcommand CTRL-G Print status line :w !sudo tee % Write file using sudo
through command
:%!command Pass the entire current buffer through command Record macro to x, run x (precede by n to run n :q Quit file
qx, @x
times, eg 5@x). :q! Quit file (overriding protection)
Code Reformatting
Shift text described by following motion Q Quit vi and invoke ex
==, =G Fix line indent / indent current line to end of file
<, > command left/right by one shift width eg <} shifts
%!astyle or :e file Edit file
Linux reformatting programs paragraph
%!indent :n Edit next file
Shift line left/right one shift width; 3>> shifts three
gq{motion} Re-do line wrapping intelligently <<, >> Return to version of current file at time of last
lines :e!
gqq Rewrap current line write (save)
:1,$> :1,$< Move entire file 1 shiftwidth to the right / left
gqj Rewrap current and following line :e# Edit alternate file
Insert any number of spaces at the beginning of
gq} Rewrap from current line to end of paragraph :%s/^/ /g each line in the entire file. Press the space bar % Current filename
the desired number of times. # Alternate filename
Buffers, Tabs, Window commands
Delete every other line (example of using normal :r file Read in contents of file after cursor
:bnext, :bprev, :%norm jdd
Next, previous, delete buffer mode command on command line; powerful!). :e . Explore dir. Can change dot to path.
:bdelete
:20>> Moves next 20 lines over 1 shift width. :e# Returns to previous window
:sp file Split current window horizontally or vertically.
With file, edit that file in the new window. K Look up word under cursor in help gf Open file at cursor at same window
:vsp file
q: Command history
:new, CTRL-W n Open a new windows
:mess Show messages
:tabnew Open a new tab
CTRL-X CTRL-O/K/S Complete from omni/dictionary/spelling Links
:new file Open file in new window
:tab help index Open help in new tab for index (or whatever) 1. Best of Vim tips: http://zzapper.co.uk/vimtips.html
:clo, CTRL-W c Close current window
:on, CTRL+W o Make current window the only visible one ex commands 2. The power and joy of Vim. Derek Wyatt: https://vimeo.com/15443936
:s/old/new/g Substitute in current line 3. Functions: https://vimrcfu.com
:qa Close all buffers and exit
4. Plugins: https://vimawesome.com/

Potrebbero piacerti anche