Skip to content

Instantly share code, notes, and snippets.

@eduardo-matos
Last active August 29, 2015 14:06
Show Gist options
  • Save eduardo-matos/1344e178f9e3bcb54400 to your computer and use it in GitHub Desktop.
Save eduardo-matos/1344e178f9e3bcb54400 to your computer and use it in GitHub Desktop.
Studying VIM
=== command mode ===
h - moves left 1 char
j - moves down 1 line
k - moves up 1 line
l - moves right 1 char
w - moves right 1 word
b - mover left 1 word
$ - moves to the end of the line
^ - moves right before the first non-blank character in the line
0 - moves to the beginning of the line
gg - moves to the beginning of the file
G - moves to the end of the file
} - moves to the next paragraph
{ - moves to the previous paragraph
o - inserts line after current line
O - inserts line before current line
f {then} <char> - moves cursor to the first ocurrence of <char> following current cursor position in current line
F {then} <char> - moves cursor to the first previous ocurrence of <char> following current cursor position in current line
t {then} <char> - moves cursor to right before first ocurrence of <char> following current cursor position in current line
T {then} <char> - moves cursor to right after first ocurrence of <char> before current cursor position in current line
<number> <command> - repeat <command> <number> times.
:set number - enable line numbers
x - deletes character right above cursor position
X - deletes character right before cursor position
u - undoes what last change (may undo several times)
dw - delete word
cw - delete word and enter insert mode
dd - remove line
cc - make line blank and enter insert mode
ci<enclosing char> - deletes everythin inside enclosing char. could be double quotes, single quote, parenthesis, curly braces...
ca<enclosing char> - same as above, but also deletes enclosing characters
p - paste, after cursor, whatever is stored in memory
P - paste, after cursor, whatever is stored in memory
y - copy (yank) something
yw - copy remaining word (everything after the cursor)
byw - copy whole word if the cursor is in the middle of it
/<search term> - searches for a specific term
n - after a search, looks for next entries of that term
N - after a search, looks for previous entries of that term
?<search term> - searches for a specific term backwards
:set ignorecase - make searches case insensitive
:set hlsearch - highlight search results
:nohlseach - stop highlighting search results
:noh - same as above
:<number> - go to line number <number>
11G - goes to line 11
/ - search again for last search term
/<regex> - searches based on regular expression
d/<search term> - deletes everything from cursor until next search result
y/<search term> - copies everything from cursor until next search result
:s/<pattern>/<replacement>/<flag> - searches for <pattern> and replaces with <replacement>
:%s/<pattern>/<replacement>/<flag> - same as above, but operates on the entire file
% - when on bracket, go to closing/opening one. if in visual mode, selects everything between the two
q - start macro recording
@<char> - execute macro
@@ - execute last used macro
:reg - show registered macros
ctrl + g - show file stats
ctrl + d - goes down half screen
ctrl + u - goes up half screen
ctrl + f - goes forward a screen
ctrl + b - goes backward a screen
H - puts cursor in the first character at the first line seen in the window (header)
M - puts cursor on the middle of the window (middle)
L - puts cursor in the first character at the last line seen in the window (last)
zt - puts active line in the top of the window
zb - puts active line in the bottom of the window
zz - puts active line in the middle of the window
m<char> - saves bookmark in current line
'<char> - goes to bookmark <char>
'' - goes to line that you were before
:ls - shows open files
:bn - goes to next open file
:bp - goes to previous open file
:bd<number> - closes buffer number <number>. If <number> is ommited, then current buffer is closed.
:vsplit <file> - vertical splits window opening new buffer
:vsp <file> - same as above
:sp <file> - horizontal splits window opening new buffer
ctrl + wl - moves to next panel on right
ctrl + wh - moves to next panel on left
ctrl + wj - moves to next panel on bottom
ctrl + wk - moves to next panel above
ctrl + w> - increases panel width
ctrl + w10> - increases panel width by 10 times
ctrl + w< - decreases panel width
ctrl + w+ - increases panel height
ctrl + w- - decreases panel width
ctrl + wL - moves panel all way to the right
ctrl + wH - moves panel all way to the left
ctrl + wJ - moves panel all way to the bottom
ctrl + wK - moves panel all way to the top
ctrl + w= - normalize panels width and height
:sb <buffer> - splits buffer horizontally
:vert sb<buffer> - splits buffer <buffer> vertically
:tabedit <file> - open <file> on new tab
:tabe <file> - same as above
gt - moves to next tag
gT - moves to previous tab
:set expandtab - uses spaces instead of tags for indentation
:set noexpandtab - uses tabs instead of spaces for indentation
:set shiftwidth=4 - uses 4 spaces on indentation
6>> - indents 6 six lines (counting current)
=3j - autoindents 3 lines (counting current)
zd - deletes fold
zo - opens fold
zi - inverts fold
zf3j - folds next 3 lines
zf% - folds matching bracket
zC - closes all folding 'til the top
zO - opens everythinh form top 'til where you are
:set fdm=manual|marker|syntax|diff|indent
:set foldmarker={{{,}}} - uses "{{{" as foldmarker. Requires that fdm=marker
=== INSERT MODE ===
ctrl+t - indents forward
ctrl+d - indents backwards
=== VISUAL MODE ===
gv - reselects the last selection
o - changes side of visual selection
> - increases indentation
< - decreases indentation
= - autoindents selected lines
=== on .vimrc ===
syntax on - enable syntax highlight
set number - enable line numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment