-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvim.man
More file actions
282 lines (207 loc) · 7.95 KB
/
vim.man
File metadata and controls
282 lines (207 loc) · 7.95 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# ---- enable x-system clipboard with vim:
$ sudo apt install vim-gui-common
# ---- vim-plug - plugin manager for vim
$ curl -fLo ~/.vim/autoload plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Then edit ~/.vim/vimrc
Launch vim and run :PlugInstall
# ---- Vundle - another plugin manager for vim
$ git clone https://github.com/VundleVim/Vundle.vim.git \
~/.vim/bundle/Vundle.vim
Then edit ~/.vim/vimrc and put something at the top.
(Visit https://github.com/VundleVim/Vundle.vim for details.)
Launch vim and run :PluginInstall
# ---------------- start and edit ----------------
vim # start vim
vim <file> # start vim opening the file(s)
vim + <file> # edit file from last line
vim +n file # edit file from nth line
:help <command> # view help info about command
K # search for manual on keyword
gx # open hyperlink in file
:n <file> # new file
:e <file> # edit file
:e ++enc=gbk <file> # read file using encoding gbk
:n # when starting vim with multiple files, use this
# command to switch to next file
# ---------------- move the cursor ----------------
h # left
j # down
k # up
l # right
gj # down on display lines (wrapped ones)
gk # up on display lines (wrapped ones)
<space> # to next character
<backspace> # to prevous character
w # to the beginning of next word
b # to the beginning of previous word
e # to the end of next word
W B E # likewise, but use blank only to separate words
0 | # to the beginning of current line
^ # to the first non-blank character of current line
$ # to the end of current line
+ <return> # to the beginning of next line
- # to the first non-blank character of prevous line
ngg # to the nth line, default=1
nG # to the nth line, default=lastline
:n # to the nth line
H # to the top of the screen
nH # to the nth line of the screen
M # to the middle of the screen
L # to the bottom of the screen
nL # to the last nth line of the screen
( # to the beginning of the sentence
) # to the end of the sentence
{ # to the beginning of the paragraph
} # to the beginning of the next paragraph
[[ # to last '{'
]] # to next '}'
# ---------------- insert ----------------
i # enter insert mode from the left of the cursor
a # enter insert mode from the right of the cursor
o # open a new line below current line
O # open a new line above current line
I # insert from 0 (see above)
A # append from $ (see above)
<esc> # exit insert mode
# ---------------- delete ----------------
x # delete the character under cursor
dd # delete current line
D # delete right-half line
d # use with movement, for example:
dw # delete to the end of the word, including blanks
de # delete until the end of the word, without blanks
dG # delete until the end of file
d <mouse> # delete until the mouse selected character
:m,nd # delete line m to n
# ---------------- replace, substitute, change ----------------
r # next key typed will replace current character
R # enter replace mode
ns # delete n chars and enter insert mode
S # delete current line and enter insert mode
c cc C # equal to d dd D, then enter insert mode
# ---------------- find and replace ----------------
/<text> # find text in file
?<text> # find text in file backwards
f<char> # find char in current line
F<char> # find char in current line backwards
t<char> T<char> # like f F, but the position of cursor differs
command
:<range>s/txt1/txt2/<option>
discription
replace txt1 with txt2
<range>
default current line
. current line
m,n line m to n
^ first line
$ last line
% global
<option>
default replace once
g replace all
c confirmed by user
examples
:<range>s/txt1/txt2/g # replace all txt1 in range with txt2
:<range>s/txt1/txt2/gc # likewise, but confirmed by user
:m,ns/txt1/txt2/g # do replace from line m to line n
:g/txt/<command> # execute command in all lines containing txt
:v/txt/<command> # execute command in all lines not containing txt
# ---------------- copy and paste ----------------
nyy # copy n lines. default n=1
p # paste text after cursor
P # paste text before cursor
"[a-z]<y or d or p> # yank/delete/paste command with named register
:reg # see registers
# ---------------- undo and repeat ----------------
u # undo last change
U # undo all changes on current line
ctrl-r # redo the undoed change
. # repeat last change
; # repeat the F f T t command
, # repeat the F f T t command backward
n # repeat the / ? command
N # repeat the / ? command backward
& # repeat the :s command
# ---------------- save and exit ----------------
:w # save file
:w <filename> # save file as filename
:wq :x ZZ # save file and exit
:e! # discard all changes
:q! # discard all changes and exit
# ---------------- options ----------------
# NOTE: for more info, see ~/.vim/vimrc
:set all # show all the options
:set no<option> # the opposite of the option, for example,
# :set nonu will close line numbers
# ---------------- info ----------------
:.= # show current line number
:= # show total line count
:f ctrl-g # show filename, total line count and percentage
:l # list blank chars on current line
g ctrl-g # word statistics
# ---------------- mark ----------------
m[a-z] # mark current position
'[a-z] # move to the desired position
# ---------------- join ----------------
nJ # join next n lines to current line. default=1
# ---------------- screen ----------------
ctrl-y # scroll up a line
ctrl-e # scroll down a line
ctrl-u # scroll up half a page
ctrl-d # scroll down half a page
ctrl-b # page up
ctrl-f # page down
ctrl-l # refresh screen
z<return> # top current line
z. # center current line
z- # bottom current line
# --------------- split window ------------------
:split <filename> # split window by top and bottom
:vsplit <filename> # split window by left and right
:new # open new window by top and bottom
:vnew # open new window by left and right
ctrl-w <hjkl> # move to a window
ctrl-w <HJKL> # move current window
# ---------------- shell ----------------
:! <command> # execute shell command
:!! # execute last shell command
:r file # read file and append after current line
:nr file # read file and append after nth line
:r! <command> # read the output of command, e.g. :r!date
:w! <command> # pass current file to command, e.g. :w!grep all
:cd <dir> # change directory to dir
:sh # temporarily enter shell environment
:so <file> # ???
# ---------------- map and abbrevation ----------------
# NOTE: avoid functional keys like K V g q v * = .
:map <key> <cmd_seq> # map key to cmd_seq, e.g. :map fj <esc>
:map # view all defined maps
:unmap <key> # delete the defined map
:ab <str1> <str2> # type in str1, press Esc, got str2
:ab # view all defined abbrevations
:una str # delete the defined abbrevation
# ---------------- indent ----------------
tab ctrl-i # insert a tab if under insert mode
>> # indent
n>> # indent n lines
<< # unindent
= # auto indent; gg=G to indent the whole file
# ---------------- fold & unfold code ------------
:set fdm=<option> # 6 options: manual indent expr syntax diff marker
zc # close fold
zo # open fold
zC # close all
zO # open all
# --------------- digraphs and keymap ------------
:dig # show digraph table. under insert mode, <c-k> to
# go into digraph input mode
:echo globpath(&rtp, "keymap/*.vim")
# show all possible keymaps
:set keymap=kana # japanese kana input
:set keymap=pinyin # hanyu pinyin input
:set keymap=russian-jcuken
# russian input
:set keymap= # close keymap
# --------------- sort --------------------
:%sort