Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 158 lines (129 sloc) 4.537 kB
6184494 @tj add vim.md
authored
1
2 # Cursor movement
3
4 h - move left
5 j - move down
6 k - move up
7 l - move right
8 ctrl-b - page up
9 ctrl-f - page down
10 % - jump to matching brace
11 w - jump by start of words (punctuation considered words)
12 W - jump by words (spaces separate words)
13 e - jump to end of words (punctuation considered words)
14 E - jump to end of words (no punctuation)
15 b - jump backward by words (punctuation considered words)
16 B - jump backward by words (no punctuation)
17 0 - (zero) start of line
18 ^ - first non-blank character of line
19 $ - end of line
20 gg - Go to first line
21 [N]G - Go To line N. No N: last line
22 Note: Prefix a cursor movement command with a number to repeat it. For example,
23 4j moves down 4 lines.
24
25 # Insert Mode - Inserting/Appending text
26
27 i - start insert mode at cursor
28 I - insert at the beginning of the line
29 a - append after the cursor
30 A - append at the end of the line
31 o - open (append) blank line below current line (no need to press return)
32 O - open blank line above current line
33 ea - append at end of word
34 Esc - exit insert mode
35
36 # Editing
37
38 r - replace a single character (does not use insert mode)
39 J - join line below to the current one
40 cc - change (replace) an entire line
41 cw - change (replace) to the end of word
42 c$ - change (replace) to the end of line
43 s - delete character at cursor and subsitute text
44 S - delete line at cursor and substitute text (same as cc)
45 xp - transpose two letters (delete and paste, technically)
46 u - undo
47 ctrl-r - redo
48 . - repeat last command
49 ~ - switch case
50 g~iw - switch case of current word
51 gUiw - make current word uppercase
52 guiw - make current word lowercase
53 >> - indent line one column to right
54 << - indet line one column to left
55 == - auto-indent current line
56 ddp - swap current line with next
57 ddkP - swap current line with previous
58
59 # Cut and Paste
60
61 dd - delete (cut) a line
62 dw - delete the current word
63 x - delete current character
64 X - delete previous character
65 D - delete from cursor to end of line
66 yy - yank (copy) a line
67 2yy - yank 2 lines
68 yw - yank word
69 y$ - yank to end of line
70 p - put (paste) the clipboard after cursor/current line
71 P - put (paste) before cursor/current line
72 :set paste - avoid unexpected effects in pasting
73
74 # Visual Mode - Marking text
75
76 v - start visual mode, mark lines, then do command (such as y-yank)
77 V - start Linewise visual mode
78 o - move to other end of marked area
79 U - upper case of marked area
80 ctrl+v - start visual block mode
81 O - move to Other corner of block
82 aw - mark a word
83 ab - a () block (with braces)
84 aB - a {} block (with brackets)
85 ib - inner () block
86 iB - inner {} block
87 Esc - exit visual mode
88
89 # Visual Mode - Commands
90
91 > - shift right
92 < - shift left
93 c - change (replace) marked text
94 y - yank (copy) marked text
95 d - delete (cut) marked text
96 ~ - switch case
97
98 # Visual Mode - Cut and paste
99
100 1. Place the cursor at the start of your text.
101 2. ma (marks the location as point 'a')
102 3. Place the cursor at the end of your text.
103 4. d'a (cuts back to location 'a')
104
105 # Exiting
106
107 :w - write (save) the file, but don't exit
108 :wq - write (save) and quit
109 :x - same as :wq
110 :q - quit (fails if anything has changed)
111 :q! - quit and throw away changes
112
113 # Search/Replace
114
115 /pattern - search for pattern
116 ?pattern - search backward for pattern
117 n - repeat search in same direction
118 N - repeat search in opposite direction
119 :%s/old/new/g - replace all old with new throughout file
120 :%s/old/new/gc - replace all old with new throughout file with confirmations
121
122 # Working with multiple files
123
124 :e filename - Edit a file in a new buffer
125 :n **/*.pl - Open all perl files under the current directory, recursively
126 :tabe filename - Edit a file in a new tab (Vim7, gVim)
127 :bnext (or :bn) - go to next buffer
128 :bprev (or :bp) - go to previous buffer
129 :bd - delete a buffer (close a file)
130 :sp filename - Open a file in a new buffer and split window
131 ctrl-w s - Split windows
132 ctrl-w w - switch between windows
133 ctrl-w q - Quit a window
134 ctrl-w v - Split windows vertically
135
136 # Tabs (Vim7)
137
138 gt - Next tab
139 gT - Previous tab
140 :tabr - First tab
141 :tabl - Last tab
142 :tabm [N] - Move current tab after tab N. No N: last. N=0: first.
143 $vim -p file1 file2 fileN - Open multiple files in different tabs (vim7)
144
145 # Command Line Options
146
147 $ vim -c "vim command" file - execute an editor command on startup
148
149 # Commands
150
151 :setlocal fileformat=dos|unix
152 :setlocal fileencoding=utf-8
153
154 # More help
155
156 :help - main help portal (with links to more help pages)
157 :viusage - show a huge cheat sheet listing every command
158
Something went wrong with that request. Please try again.