-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVim
More file actions
230 lines (217 loc) · 15.8 KB
/
Vim
File metadata and controls
230 lines (217 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
Open files
|-------------------------------------------------------+-------------------------|
| Open diff | vimdiff <file> <file>.. |
| update diffs | :diffupdate |
| move to next diff | ? |
|-------------------------------------------------------+-------------------------|
| reload file | :edit, :e! |
|-------------------------------------------------------+-------------------------|
| save changes to a file | :w <file> |
| save visually selected line to a file | v motion :w <file> |
|-------------------------------------------------------+-------------------------|
| save changes and quit | :wq,:x,zz |
|-------------------------------------------------------+-------------------------|
| retrieve file and put it below cursor | :r <file> |
| retrieve shell command output and put it below cursor | :r !ls |
|-------------------------------------------------------+-------------------------|
| open in tabs | $vim -p <file> <file> |
| open other file in tab | :tabf <file> |
| move to next tab | gt |
|-------------------------------------------------------+-------------------------|
| open horizontally files | $vim -o <file> <file> |
| open vertically files | $vim -O <file> <file> |
|-------------------------------------------------------+-------------------------|
| quit all windows | :qa |
|-------------------------------------------------------+-------------------------|
| split current screen horizontally | <C-w> s |
| split current screen vertically | <C-w> v |
|-------------------------------------------------------+-------------------------|
| inside vim & open a new file horizontally | :new <file> |
| inside vim & open a new file vertically | :vert new <file> |
|-------------------------------------------------------+-------------------------|
All the right moves - Motion
|--------------------------------------------------+---------------|
| Moving the cursor | k |
| | h l |
| | j |
|--------------------------------------------------+---------------|
| Moving forward to | |
| beginning of next word | w |
| end of next word | e |
|--------------------------------------------------+---------------|
| backward to | |
| beginning of previous word | b |
| end of the previous word | ge |
|--------------------------------------------------+---------------|
| to the beginning the next two words | 2w |
| to the end of the next three words | 3e |
|--------------------------------------------------+---------------|
| move cursor across more words | |
| to the begining of next 2 words | 2w |
| to the end of next three words | 3e |
|--------------------------------------------------+---------------|
| find character | f{char} |
| to/till character | t{char} |
| repeat action | ; |
| reverse action | , |
|--------------------------------------------------+---------------|
| to the matching of | % |
| }]) | |
| * | |
| preprocessor conditional | |
|--------------------------------------------------+---------------|
| to the start of the line | 0 |
|--------------------------------------------------+---------------|
| to the end of the line | $ |
|--------------------------------------------------+---------------|
| to the start of the file | gg |
|--------------------------------------------------+---------------|
| to the bottom of the file | G |
|--------------------------------------------------+---------------|
| to the line 123 | 123G, 123gg |
|--------------------------------------------------+---------------|
| show cursor location in the file and file status | <C-g> |
|--------------------------------------------------+---------------|
| go back to where the cursor came from | <C-o> |
|--------------------------------------------------+---------------|
| go forward to where the cursor came to | <C-i> |
|--------------------------------------------------+---------------|
| half-page down | <C-d> |
| half-page up | <C-u> |
|--------------------------------------------------+---------------|
| page down | <C-f> |
| page up | <C-b> |
|--------------------------------------------------+---------------|
| "paragraph" up | { |
| "paragraph" down | } |
|--------------------------------------------------+---------------|
| put the current line at | |
| top of screen | zt |
| center of screen | zz, z. |
| bottom of screen | zb |
|--------------------------------------------------+---------------|
| toggle folding | za |
| open all folds | zR |
| close all folds | zM |
|--------------------------------------------------+---------------|
| jump from window to window | <C-w> <C-w> |
|--------------------------------------------------+---------------|
| jump to upper/lower/left/right window | <C-w> j/k/h/l |
|--------------------------------------------------+---------------|
| go to any address in a file | |
| first line | :1 |
| last line | :$ |
| above first line | :0 |
| current line | :. |
|--------------------------------------------------+---------------|
| entire file | :% |
|--------------------------------------------------+---------------|
| line contains mark 'm' ? | :'m |
|--------------------------------------------------+---------------|
Copy/Delete/Undo/Redo
|--------------------------------------------+----------|
| copy line 6 TO the current line | :6t. |
| copy current line TO line 6 | :.t6 |
| copy after yanking TO current line | :t. |
| copy after yanking TO end of file | :t$ |
| copy selected block to TO begining of file | :'<,'>t0 |
|--------------------------------------------+----------|
| MOVE selected block to end of file | :'<,'>t$ |
| MOVE selected block to begining of file | :'<,'>t0 |
|--------------------------------------------+----------|
| delete a character | x |
| delete a word | dw |
| delete a line | dd |
| detele to end of line | d$ |
| delete 6 charecters off the end of line | :%s/.\{6}$//|
| delete newline of each line. Join 42 lines | :42J |
| delete to the begin of line | d0 |
|--------------------------------------------+----------|
| undo | u |
| undo changes on a line | U |
|--------------------------------------------+----------|
| redo | <C-r> |
|--------------------------------------------+----------|
Vim Commands - Operator + motion
|--------------------------------------------------+-----------------------------------------|
| REPLACE | |
| a character with 'x' | rx |
| all occurences with 'new' in a file | search with * and :%s/<C-r><C-w>/new/gc |
|--------------------------------------------------+-----------------------------------------|
| PUT after | p |
| delete a line and put it | dd motion p |
| delete a character and put it | x motion p |
| PUT before | P |
|--------------------------------------------------+-----------------------------------------|
| CHANGE (to insert mode) | |
| to the end of a word | ce, cw |
| a whole word | ciw, caw |
| all text objects inside "'`([{ | ci" |
| inside any tag | cit |
| from the cursor to end of line | c$, C |
| a whole line | cc |
|--------------------------------------------------+-----------------------------------------|
| SEARCH | |
| search forward | /keyword |
| search backward | ?keyword |
| keyword contains '/', then use ? | ?/usr/lib |
| repeat searching in same direction | n |
| repeat searching in opposite direction | N |
| ignore case | /keyword\c |
| highlight all searched text | :set hls, :nohlsearch |
|--------------------------------------------------+-----------------------------------------|
| SUBTITUTE | |
| in first occurence in line | :s/old/new |
| all occurences in line | :s/old/new/g |
| between two lines | :#,#s/old/new/g |
| all occurences in a block with confirmation | first visually select a block, then |
| | :'<,'>s/\%Vold/new/gc |
| all occurences in file | :%s/old/new/g |
| all occurences in file with confirmation | :%s/old/new/gc |
| ? is also delimiter when '/' shown up in keyword | :%s?/usr/lib?/usr/lib64?g |
| > is also delimiter | :24,27:s<true/false<g |
|--------------------------------------------------+-----------------------------------------|
| YANK | |
| yank one word | yw |
| copy and paste | y motion p |
|--------------------------------------------------+-----------------------------------------|
| SET options | |
| set ignore case when searching | :set ic, :set ignorecase |
| set highlight search and incsearch ? | :set hls is, :set hlsearch incsearch |
| set not in compatible mode | :set nocp |
| set folding by syntax | :set foldmethod=syntax |
| set line number | :set number |
| show invisibles | :set list |
| UNSET options | |
| | :set noic, :set noignorecase |
| | :set nohls, :set nohlsearch |
| | :set nonumber |
| TOGGLE set options | |
| | :set number! |
| | :set list! |
|--------------------------------------------------+-----------------------------------------|
| NORMAL command | |
| append at the end of every lines ';' | :%normal A; |
| insert at the begining of every line'//' | :%normal I// |
| repeat same effect to selected block of lines | :'<,'>normal . 'first visualize lines |
|--------------------------------------------------+-----------------------------------------|
External shell commands
|----------------------------+-------------|
| any external shell command | :!ls-lt |
| | :!pwd |
| | :!cd ~ |
| | :!rm <file> |
|----------------------------+-------------|
Command line window
|------------------------------------------+-------------------------|
| open with Ex command history | q: |
| open with search history | q\ |
| pipeline commands in command line window | :set number! | set list!|
|------------------------------------------+-------------------------|
Get help
|---------------------+-----------------|
| HELP | |
| help on any subject | :help <subject> |
|---------------------+-----------------|
| Complete command | <C-d>, <Tab> |
|---------------------+-----------------|