Skip to content

Instantly share code, notes, and snippets.

@suchov
Created November 15, 2014 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save suchov/5b8c43b2f4ee6a835529 to your computer and use it in GitHub Desktop.
Save suchov/5b8c43b2f4ee6a835529 to your computer and use it in GitHub Desktop.
vim commands
VI
#Move:
b - back + shift
w - word + shift
e - end of the word
$,0,^
{} - paragraph
f - find the word
F - find the word backword
t, T - find and put the cursor before
#Edit
dw - delete word
db - delete previous word
cw - chenge word(delete and insert mode)
dd, cc
ct" - change all in "" ct["'{[(]
ci" - change all in "" no metter where the cursore is
ca" - delete all in "" and the ""
#Cut and paste
p - paste
P - paste before
#Search
/ - usuall search, n N - for next
? - usuall search backword
options for search
:set incsearch :set ignorcase :set hlsearch/notlsearch
#Replace
:s/word/Word - change the word only in this line
:%s/word/Word - change the work in all file, but only the first word
:%s/word/Word/g - global, c - confirm each replecement i - case insensetive
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
#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 #
#Serach and 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