Skip to content

Instantly share code, notes, and snippets.

@starikovs
Last active January 3, 2016 02:49
Show Gist options
  • Save starikovs/8397791 to your computer and use it in GitHub Desktop.
Save starikovs/8397791 to your computer and use it in GitHub Desktop.
--- moving around ---
h j k l
2h 3j 4k 5l
0 ^ $
w b e, W B E
fx Fx
tx Tx
G 3G
Ctrl+D, Ctrl+U (half a screen of text)
Ctrl+F, Ctrl+B (page)
H (screen top), M (middle), L (bottom)
( ) - sentence
{ } - paragraph
% - matching /*([{}])*/
http://stackoverflow.com/questions/635770/jump-to-function-definition-in-vim
g*, g# or *, # (search for the word under the cursor)
gd (goto definition)
'' (two single quotes) return to the line where the cursor was before the latest jump
`` (two back ticks) return to the cursor position where the cursor was before the latest jump
http://stackoverflow.com/questions/235839/how-do-i-indent-multiple-lines-quickly-in-vi
http://vim.wikia.com/wiki/Indent_a_code_block
<, > in VISUAL to indent code
In NORMAL:
<<, >>, 3>> (3 lines), 3>> . (3 lines and repeat), 3==
>%, <%, =%
>i{, =i{, <i{, >a{, =a{, <a{
In vim there're small and big words.
x (delete char on cursor)
X (delete before cursor)
J (join lines), 3J 4J
r+char (replace)
dd, dw, d), d}, d(, d{, d$, d^
. - repeat command, dd.., J..., p.....
(this repeats command, not motion)
i, a, A, Esc
v, V (whole lines), Ctrl-q or Ctrl+v (block, vertical selection, visual vertical)
set paste (for ctrl+p pasting mode)
set nopaste (after pasting)
c$, cw, (delete motion text and start insert)
d3w -> once
3dw -> 3 times
y, c, d, d3w, 3dw, 3$, 3d2w
p, P (after, before)
--- Search and replace ---
(http://vim.wikia.com/wiki/Search_and_replace)
% - whole file = 1,$
.,1 - from current line to the end
. - current line
$ - end of file
:s/regexp/repl (current line, signe occurrence)
:s/regexp/repl/g (current line, all occurrences)
:%s/regexp/repl/g (all file)
:%s/regexp/repl/gc (all file but asks confirmation)
:%s/,\s*\(\n\)\+\s*"style":\s\+"toolbar"\s*//gc (http://vimregex.com/)
c - changes text, acts just like "d"
cc, dd - entire line
c$, C - change from cursor to end of line
~ (change case)
U (in visual, change to uppercase)
u (in visual, change to lowercase)
gUe (change to uppercase to the end of word)
--- visual ---
(http://vim.wikia.com/wiki/Search_and_replace_in_a_visual_selection)
:'<,'>s/red/green/gc
:s/\%Vus/az/gc (select some words in a line, press Esc, apply substitute command to the last-selected area)
:%s/\%Vold/NEW/g (when selecting a block with c-q)
/search_something (in visual will extend the selection)
/\%Vseach_something (select, Esc, seach with the command in the last-selected area)
(marks for the beginning and end of the visual selection)
'< start line, '> end line
`< start character, `> end character
--- tag delete example ---
<b>...</b> - delete this!
df> f< .
--- buffers ---
:ls
:bd, :bd!, :bd 2 (buffer delete; delete from buffer list, close buffer window)
:bnext, :bn
:bprev, :bp
:b 3, :b htm[TAB], :b12 (space may be ignored)
Ctrl+^ (6) (toggle between the current and the last used buffer), :b#
:bn, :bd# (switch to next, close previous)
:b#, :bd# (switch to previous, close previous)
:sb#, :sb1, :sbN - split buffer horizontally
:vert sb#, :vert sb1, :vert :sbN - split buffer vertically
--- windows ---
C-W w - move cursor to other window
C-W r - swap
^w followed by h, j, k or l (ctrl+w, ctrl+H) - move cursor to the left, bottom, top or right window
^w followed by capital H, J, K or L will move the current window to the far left, bottom, top or right respectively like normal cursor navigation.
--- open files ---
vim c:\tmp\test1
ls -la | vim -
:e c:\tmp\test1 (edit existing file or new file)
:sp (split current window in two)
:sp filename
:vsp
--- save and exit ---
:q
:q!
:w
:w filename
:wa (write all changed)
:x is the :wq
:qa, :qa!, :wqa (close all files, tabs, windows)
Never use :x never never never. You'll screw up some day and do :X encrypt your file, and you won't know the key.
--- Vim error/other messages ---
:messages
:mes
--- searching in files ---
http://vim.wikia.com/wiki/Find_in_files_within_Vim
vimgrep, lvimgrep - part of vim; vim style regexp
vimgrep - quickfix list, shared between ALL windows
lvimgrep - location list, local to the current window
:vimgrep /\.section/gj ./**/*.css
:vimgrep /hover-bg-rounded/j **\widgets\*.htm*
:cw, :copen - open "quickfix"
:lw, :lopen - open "location fix"
:colder, :cnewer
:lolder, :lnewer
:vimgrep /long-dialog/j **/*.html - current directory and subdirectories
:vimgrep /long-dialog/j *.html - current directory
:vimgrep /uipopup\c/j **\*.js - case insensitive
:vimgrep /uipopup\C/j **\*.js - case sensitive
--- tabs ---
:tabedit file (open file in new tab)
1gt, 2gt (switch to first or second tab)
gt, gT (forward, back)
:tabclose, :tabclose 1 (close current tab or first tab)
:tabonly (close all other tabs)
--- file info ---
Ctrl+G
--- vim options ---
Boolean options (On/Off):
:set number (On)
:set nonumber (Off)
:set all
.vimrc:
set nobackup
set noswapfile
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
:retab (change all the existing tab characters to match the current tab settings)
--- help ---
vimtutor
:help :sp
:h :sp
:help design-not
:help C-indenting
:help smartindent
:help auto-setting
--- :NERDTree ---
gt, gT
I
B
A
:Bookmark <name>
m
u
U
C
--- NERDTreeGlobalCommands ---
:NERDTreeFind (Find the current file in the tree.)
:NERDTreeMirror
:NERDTree [<start-directory> | <bookmark>]
:NERDTreeFromBookmark <bookmark>
:NERDTreeToggle [<start-directory> | <bookmark>]
:NERDTreeClose
--- NERDTree plugin install on Win http://www.vim.org/scripts/script.php?script_id=1658 ---
Unzip the archive into your ~/vimfiles directory.
That should put NERD_tree.vim in ~/vimfiles/plugin and NERD_tree.txt in ~/vimfiles/doc.
Run :helptags.
Go :help NERD_tree.txt for the help page.
--- help tags for NERDTree plugin on Win ---
:helptags ~/vimfiles/doc
--- another help ---
http://habrahabr.ru/post/221267/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment