-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim.txt
132 lines (109 loc) · 3.19 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
100 G
Ctrl-G
*/? nN
fF ;,
% ()
moving inside a line: ^ $ f wb e
moving between lines: gg G 10G j k
:! terminal command
:%s/\cword/replacement/gc &u
Default changes only first /g changes multiple
:1,8s - replace between lines
:w to write the selection to a file
:r filename to write any text file to this one
Ctrl + W Ctrl + W
CTRL + D/TAB autocomplete
:vs :sp
> gg/G/10G
>> indent line
Calling a command in duplicate executes it on the current line
qx{changes}q @x/u
C = c$
s = cl
S = ^C Change whole line
One key to move, one key to execute
i{insert text}<Esc> constitutes a u change
If you've paused long enough to ask the question:"Should I leave insert mode?" then do.
daw :delete a word
10C-a/C-x -increment/decrement a number by 10
yyp - duplicate line
2dw==d2w, but use dw. instead
act, repeat, reverse
ap,aw
gU
C-h/w/u delete back one char/to the start of the word/to start of line
^ Always excludes current character, behaves like backspace
C-o(mmand)
C-r in insert 0-9, =
c-v insert character literal, dec, hex
c-k digraph mode, fractions etc.
gr/gR Virtual replace expands tabs to spaces
v/V/C-v/o
Use C-v -> A{typing} to append stuff to the end of all the lines
gv repeats last selection
vi(nside)w
operators and motions work inside Visual mode, use c for expected behaviour
c/v i/a w/t/p
Ex Commands Strike far and wide
:1,5p . $ % V /<html>/,/</html>/p -3
:linefrom t lineto
:t lineto
:t. = yyp
:t copy :m move :d
Vjj m$ @:
normal.
lines normal i/a/c
These commands don't overwrite buffers
Buffer: in-memory representation of a file, add only
Args: list of files, can reload
:ls lists buffers
C-^ swaps buffers
Open files using the Arglist/Buffers
Open Windows on them
Arrange windows in to Tabs
Windows: Views over buffers
C-w hjkl v/s c/o =
:vs :sp :on
Argument List:
clears the argument list and repopulates it
:args*.* **/*.js **/*.css
:args 'cat .chapters'
:argdo/buffdo does a command on each buffer
:edit! rereads the file from disk
:lcd sets the working directory for the current window
:cd sets the working directory for vim
Prefer windows in tabs over buffers
Tabs hold a collection of windows and a working directory
Each tab is essentially a project, composed of windows over buffers in a working directory.
:tabe :tabc :tabo C-wT 1 gt gT :tabmove
:edit %:h<tab> open file in same path as current file (not pwd)
:set path+=app/** :find
:wa
Registers:
xp ddp
"_ black hole register
""p is the same as p
When y anking also be copied to the yank register: "0
:reg
"A appends to a
"+ system clipboard
"* middle mouse button
"= expression register
"%#:/. store what you'd expect
Pasting over a visual selection swaps with "0
<C-r>0 is more intuitive than p/P
Pasting lines puts the cursor at the top of the pasted text
gp/gP will place the cursor at the end of the pasted text
Opening files
:e %:h<tab> expands to the directory of the currently open buffer
set path+=/**
:find filename
:!mkdir -p %:h When writing a file to directories that don't exist
:w !sudo tee % > /dev/null Write file as root
Navigation:
0 first char
^ first non-blank char, I
$ last char, including spaces
g0, g^, g$ for virtual lines
Vim has WORDS(list of any char separated by spaces) and words (letters, digits, underscores)
ab123_ we're e.g.