Last active
August 10, 2017 20:51
-
-
Save bnikkhoo/7029a99cf6157689b40419e0c3bb0316 to your computer and use it in GitHub Desktop.
VIM Cheat Sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Move: | |
j, k, h, l - up, down, left, right | |
b - back + shift | |
w - word + shift | |
e - end of the word | |
$,0,^ | |
{} - paragraph | |
f - find the word | |
F - find the word backwards | |
t, T - find and put the cursor before | |
G - go to end of the file | |
1G - go to top of the file | |
#Edit | |
i - change to insert mode (before cursor) | |
I - insert at beginning of line | |
a - change to insert mode (after cursor) | |
A - change to insert mode (at end of line) | |
r - replace one character | |
R - overwrite text | |
J - merge next line with this one | |
x - delete one character | |
dd - delete one line | |
dw - delete word | |
db - delete previous word | |
cw - change word(delete and insert mode) | |
dd, cc | |
ct" - change all in "" ct["'{[(] | |
ci" - change all in "" no matter where the cursor is | |
ca" - delete all in "" and the "" | |
:wq - write file and quit | |
:q! - quit without saving | |
#Cut & paste | |
yy - yank line (copy) | |
p - paste | |
P - paste before cursor | |
#Search | |
/ - usual search, n N - for next | |
? - usual search backword | |
options for search | |
:set incsearch :set ignorcase :set hlsearch/notlsearch | |
#Replace | |
:s/old/new - change the word only in this line | |
:%s/old/new - change the word in all file, but only the first word | |
:%s/old/new/g - global, c - confirm each replecement i - case insensitive | |
:g/pattern/d - delete all lines that match the pattern | |
v - visual mode | |
v% on symbol "{" - try to find closed symbol "}" | |
and then you can replase with regexp in this text | |
#Macros | |
q - start recording the macros, and any letter - name of the macros | |
j0 - finish the macros | |
@ and name of the macros - to execute the macros | |
@@ - use the latest macro | |
q<letter><commands>q - Record macro | |
VG:normal @letter - Execute macro to end of buffer | |
#Navigate | |
ctrl + d - half a screen forword | |
ctrl + u - half a screen up | |
ctrl + f - full screen forword | |
ctrl + b - backword one screen | |
M - go to the middle of the screen | |
H - go to top of the window | |
L - go bottom of the window | |
zt - line that the cursor is on stay on top | |
zb - line that the cursor is on to the bottom of the screen | |
zz - line where the cursor is to the middle of the window | |
o key in visual mode - to move cursore up and down in the visual selection | |
gv - to select previous selection | |
m - add marker and then name of the marker | |
'and a marker - go to the marker | |
'' - go back | |
#Windows and Tabs | |
:vs - split the window + you can type the path to the file | |
ctrl + w and (lhjk) to go between the windows(l-left h-right) | |
:sp - split horizontaly + you...(jk-up, down) | |
ctrl + w and (LHJK) - to move window to the... | |
ctrl + w + "+"(you can always use number here) or "-" resize the window | |
crtl + w + ">" or "<" resize the window | |
ctrl + w + "=" - back to the standart size | |
:sb - split with the buffer | |
:sp2 (choose the buffer) | |
:vert sb - splet vertically | |
:tabe(tabedit) and the path - open new tab | |
gt - move aroutd tabs forward | |
gT - move around tabs backward | |
#Indents and Folds | |
>> - indent by one tab one line | |
3>> - indent 3 lines | |
:set list - show the tabs and new lines | |
:set expandtab - spaces over tabs | |
:set noexpandtab - tabs over spaces | |
:set shiftwidth=3 - change amount of spaces in the tab(3) | |
:set smartindent - smart indentation | |
select the lines and = - set the indentation to normal | |
=G at the begining of the file - indent all file | |
:set softtabstop=3 | |
ctrl + t move forward in indent mode | |
crtl + d move backward in indent mode | |
:se foldmethod | |
zf5j - create the fold 5 lines | |
zo - open fold | |
zc - close fold(zC) | |
zd - delete the fold | |
zf% (looking for marching bracket in the metrod...) | |
zi - invert the foldes | |
:h 'foldmethod' | |
:set fdm=syntax (manual...) | |
:set foldmarker={{{,}}} | |
#Command line from vim - :! | |
:read(or r) !command - write int the file output from the command | |
:se ft=javascript - set the file type to JS | |
#Buffers | |
:ls - list all active buffers | |
:bn - next buffer | |
:bp - previous buffer | |
:b# - go to previous file | |
:bf - go to the fist buffer | |
:bd - delete the current buffer | |
:bd12 - delete buffer 12 | |
#Help | |
:help :s(for search) | |
/\n\n - all blanc lines in the file (vim use the regexp) | |
d /word - delete all from the cursore to the word | |
d /word - delete and put insert mode | |
d /word - delete all backword | |
#Commands: | |
:source [path to the file] - reload file | |
ctrl + g - status of the file | |
#Delete line with regular expressions | |
:g/^\s*$/d - delete lines that contain only spaces | |
:g/^#/d - delete lines that start with # | |
#Search & replace | |
:%s/foo/bar/g - Find each occurrence of 'foo' (in all lines), and replace it with 'bar'. | |
:%s/foo/bar/gci - Change each 'foo' (case insensitive) to 'bar'; ask for confirmation. | |
#Shortcuts | |
:map ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment