-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim.txt
227 lines (201 loc) · 7.22 KB
/
vim.txt
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
Moving
------
h / l / k / j : Left / right / up / down.
+ : Down, to first non-blank character.
- : Up, to first non-blank character.
0 : Start of the current line.
^ : First non blank character of the current line.
$ : End of the current line.
g_ : Last non blank character of the current line.
f<char> : Next occurrence of character <char> in line (inclusive).
F<char> : Previous occurrence of character <char> in line (inclusive).
t<char> : Next occurrence of character <char> in line (exclusive).
T<char> : Previous occurrence of character <char> in line (exclusive).
; : Repeat last f, F, t or T.
, : Repeat last f, F, t or T in the opposite direction.
gg / G : Jump to the start / end of the file.
:# : Go to line #.
% : Jump to the matching { }, ( ), etc.
#% : Go to the line on the #% of the file (50% is the middle of the file).
{ / } : Jump to the previous / next paragraph.
/<text> : Search forward for <text>.
?<text> : Search backward for <text>.
/<text>\c : Search forward for <text> case insensitive.
* / # : Search for the word under the cursor forward / backward.
ma : Set mark "a" (a-z).
'a : Start of the line with mark "a".
`a : Go to mark "a".
marks : View marks set.
H : First line of the current screen.
M : Middle line of the current screen.
L : Last line of the current screen.
ctrl-f : Jump forward one full screen.
ctrl-b : Jump backward one full screen.
ctrl-d : Jump forward (down) half a screen.
ctrl-u : Jump back (up) half a screen.
ctrl-y : Move screen down without moving cursor.
ctrl-e : Move screen up without moving cursor.
z<enter> : Move screen so the current line is first.
zz : Move screen so the current line is middle.
w : Next start of word.
W : Next start of blank-separated word.
b : Previous start of word (before).
B : Previous start of blank-separated word (before).
e : Next end of word.
E : Next end of blank-separated word.
ge : Previous end of word.
gE : Previous end of blank-separated word.
'. : Jump back to last edited line.
g; : Jump back to last edited position.
ctrl-w + h / l / k / j : Move to left / right / up / down window.
Quick editing commands
----------------------
i / I : Insert at cursor / start of line.
a / A : Append to cursor / end of line.
x / X : Cut character at / before cursor.
y : Yank (copy, visual mode).
yy : Yank line.
d : Delete (cut, visual mode).
dd : Delete line.
S : Delete line and insert mode.
D : Delete remaining part of line.
C : Change remaining part of line.
p / P : Paste after / before cursor.
o / O : Open a new line after / before the current line.
v / V / ctrl+v : Visual mode (to select text, single / line / block).
gv : Reselect previous selection.
o : (Visual mode) Change side of selection.
r / R : Replace character / replace mode.
u / U : Undo one change / all changes in line.
ctrl-r : Redo one change.
Useful developer commands
-------------------------
~ : Change case.
gu : Lowercase.
gU : Uppercase.
J : Joins two lines.
ctrl-A / ctrl-X : Increments / decrements the number under cursor.
. : Repeat last command.
== : Fix line indent.
> : Indent line or selected block.
< : Unindent line or selected block.
gf : Open file under cursor.
gg=G : Go to the first line and indent to the last one (everything).
ctrl-n / ctrl-p : (Insert mode) Complete next / previous coincidence of typed word.
gd : Go to declaration of identifier under cursor.
gD : Go to global declaration of identifier under cursor.
!column -t : Indents / aligns multiple columns.
!python -m json.tool : Python unix tool, formats json lines.
norm <cmd> : Executes <cmd> on every line selected (:%norm 0daW deletes the first WORD in all lines).
g/<pattern>/<cmd> : Executes <cmd> on every line with <pattern> (:g/dog/d deletes all lines containing 'dog').
g!/<pattern>/<cmd> : Executes <cmd> on every line without <pattern> (:g!/cat/d deletes all lines not containing 'cat').
Folding
-------
set foldmethod=indent (Indent, syntax).
set foldcolumn=x (x number of tree columns).
zo : Open fold.
zO : Open fold and subfolds.
zc : Close fold.
zC : Close all folds.
zr : Open everything one level (reduce folding).
zR : Open all folds.
zm : Close everything one level.
Objects
-------
w : Word.
W : Blank-separated word.
s : Sentence.
p : Paragraph.
t : Tag (markup languages).
() : Parenthesis.
[] : Brackets.
{} : Braces.
'' : Quotes.
"" : Double quotes.
<> : Angle brackets.
Combining commands.
-------------------
Most commands accept amount and direction:
<operator>a<object> : Operate an object.
<operator>i<object> : Operate inner object.
dw : Delete till start of next word.
cw : Change till start of next word (delete and insert mode).
caw : Change a word.
gUaw : Uppercase a word.
dap : Delete a paragraph.
vip : Select inner paragraph.
ci" : Change inner "" (even before the "").
cit : Change inner tag.
3cw : Change 3 words.
va( : Visual select () and its content.
4dd : Delete 4 lines.
3x : Delete 3 characters.
3s : Substitute 3 characters.
d/foo : Delete till the next occurence of 'foo'.
v?foo : Visual select till de previous occurence of 'foo'.
df<char> : Delete inline to next <char> (inclusive).
vT<char> : Select inline to previous <char> (exclusive).
Macro recording
---------------
1. Press q<key> to start recording, do things.
2. Hit q to stop recording.
3. Use @<key> to execute the macro.
Buffers (files opened)
----------------------
:args ~/* : Opens all files under ~/.
:e <file> : Edit/reload file.
:ls : List buffers.
:b# : Go to buffer # (# can be the number or part of the buffer name).
:bn : Go to next buffer.
:bp : Go to previous buffer.
:bw# : Wipe out buffer #.
:bw * + ctrl-a : Expands * into all open buffers and wipe out all.
ctrl+6 : Jump between last and current buffer.
:bufdo <cmd> : Executes <cmd> in all open buffers.
Windows
-------
ctrl-w + H / L / K / J : Moves current window to left / right / top / bottom.
:resize # : I.e. :resize 40.
:vertical resize # : I.e. :vertical resize 40.
ctrl-w + = : Resize all windows to the same size.
:sb# : Splits horizontally buffer #.
:vert sb# : Splits vertically buffer #.
(ball = All buffers).
:sf# : Splits horizontally file #.
:vert sf# : Splits vertically file #.
:windo <cmd> : Executes <cmd> in all open windows.
Tabs
----
:tabnew : Create tab.
:tabclose : Delete tab.
:tabn : Next tab.
:tabp : Previous tab.
:tabm # : Move tab to position #.
:tabm +# : Move tab # positions right.
:tabm -# : Move tab # positions left.
:tabdo <cmd> : Executes <cmd> in all open tabs.
Plugins:
========
Ctrl-p
------
ctrl-d : Change between path, files and mru.
ctrl-z : Mark multiple files.
ctrl-o : Open marked files.
Ctags
-----
Bash command to construct tags file:
ctags-exuberant --languages=PHP -R --links=no --PHP-kinds=cf <path_to_your_code> <path_to_your_code> ...
ctrl-p / ctrl-n : (Insert mode) Completes with previous / next coincidence.
:tag <className> : Open className definition.
ctrl-] : Open class/method definition under cursor.
ctrl-w + ] : Open class/method definition under cursor in new window.
ctrl-t : Return to method call.
Php-cs-fixer
------------
\pcd <path> : Fix coding standards of files in <path>.
\pcf <file> : Fix coding standards of file <file> (current file if not specified).
Multiple-cursors
----------------
ctrl-k : Switch to select mode and selects word under cursor and next occurrences.
ctrl-p : (Select mode) Deselect current word.
ctrl-x : Skip current selected word.