-
Notifications
You must be signed in to change notification settings - Fork 0
/
NOTES-vim
147 lines (110 loc) · 4.1 KB
/
NOTES-vim
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
" hello - double quote is comment in vim; see .vimrc for working ex.
:so % " reload the .vimrc you are editing"
:set number " turn on numbering"
:set nu "same
:set nonumber "turn off numbering"
:set nonu "same
:set spell " turn on spell check; turn off with nospell"
Working with tabs
-----------------
:vsp {file} aka vsplit
:tabnew {file}
:tabedit {file} edit specified file in a new tab
:tabfind {file} open a new tab with filename given, searching the 'path' to find it
:tabclose close current tab
:tabclose {i} close i-th tab
:tabonly close all other tabs (show only the current tab)
gt go to next tab
gT go to previous tab
{i}gt go to tab in position i
Text width/paragraphs
--------------------
:set tw=60 - sets text width,
gqip - reformats longer text to text width
Working with multiple windows aka panes
------------------------------
:e filename - edit another file
:split filename - split window and load another file
ctrl-w up arrow - move cursor up a window
ctrl-w ctrl-w - move cursor to another window (cycle)
ctrl-w_ - maximize current window
ctrl-w= - make all equal size
10 ctrl-w+ - increase window size by 10 lines
:vsplit file - vertical split
:sview file - same as split, but readonly
:hide - close current window
:only - keep only this window open
:ls - show current buffers
:b 2 - open buffer #2 in this window
Vim viewport keybinding quick reference
----------------------------------------
:sp will split the Vim window horizontally. Can be written out entirely as :split .
:vsp will split the Vim window vertically. Can be written out as :vsplit .
Ctrl-w Ctrl-w moves between Vim viewports.
Ctrl-w j moves one viewport down.
Ctrl-w k moves one viewport up.
Ctrl-w h moves one viewport to the left.
Ctrl-w l moves one viewport to the right.
Ctrl-w = tells Vim to resize viewports to be of equal size.
Ctrl-w - reduce active viewport by one line.
Ctrl-w + increase active viewport by one line.
Ctrl-w q will close the active window.
Ctrl-w r will rotate windows to the right.
Ctrl-w R will rotate windows to the left.
Vim folding commands
--------------------
zf#j creates a fold from the cursor down # lines.
zf/string creates a fold from the cursor to string .
zj moves the cursor to the next fold.
zk moves the cursor to the previous fold.
zo opens a fold at the cursor.
zO opens all folds at the cursor.
zm increases the foldlevel by one.
zM closes all open folds.
zr decreases the foldlevel by one.
zR decreases the foldlevel to zero -- all folds will be open.
zd deletes the fold at the cursor.
zE deletes all folds.
[z move to start of open fold.
]z move to end of open fold.
Commenting code out
------------------
aka https://github.com/scrooloose/nerdcommenter
usually always visual for me
<leader><cmd> where leader is backslash key '\'
\cl comment out left side
\cu uncomment
\cs sexy comment
\cm block comment ie. C style /* before and then after */
Chars/Unicode
-------------
Fun With Unicode ٩(●̮̮̃•̃)۶
Following up on the last post, you can also use CTRL-V to enter unicode characters. All you have to do is the following:
CTRL-V u (unicode character hex code)
Note that you can also combine multi-byte character
When typing in insert or ex mode, hiting CTRL-V allows you to enter a literal character. Some examples:
CTRL-V CTRL-M # enters a literal carriage-return \r
CTRL-V 10 <enter> # enters a null character
Delete huge blocks
-----------------
" go to line 13, mark it with 'x', then to line 42 and delete
:13
mx
:42
d'x
Block edits
-----------
ctrl-V for column selection
I - insert in block mode
Binary files
------------
aka pesky git diff that carps about new line at end of file:
vim -b file and once in vim:
:set noeol
:wq
done.
alternatively you can open files in vim with :e ++bin file
Yet another alternative:
:set binary
:set noeol
:wq