- Actions (verbs)
- Insert mode paste
- clipboard
- Moves (adjectives)
- Normal mode to insert mode
- Undo / Redo / Repeat
- Scrolling
- Visual mode
- Search / Replace
- Mapping
- Macros
- External commands
- Register
- Marks
- TODO sort this
- Usefull Tricks
- Plugins
Actions (verbs)
y
yank or copy to default register""
and also to"0
registerd
delete or cutc
cut / cut and go to insert modep
paste"0p
paste from the copy register (even if you havedd
orx
in the meantime)
Insert mode paste
<C-r>0
paste the yank register<C-r>"
paste the default register<C-r>a
paste the a register<C-r>*
paste the system clipoard (mouse selection)<C-r>+
paste the system clipoard (copy)<C-r>.
paste last inserted text<C-r>%
paste the current file name
clipboard
vim --version | grep clipboard
should display +xterm_clipboard
otherwise recompile your vim with the appropriates libs.
"*p
paste the middle-click buffer"+p
paste theCrtl+C
buffer- works with
y
andd
too…
Moves (adjectives)
These can be applied to previously defined actions
s
sentencew
next wordW
next space-separated wordb
previous wordB
begining of / previous word (space separated)e
end of wordE
end of / next word (space separated)tx
to next characterx
excludingx
Tx
to previous characterx
excludingx
fx
to move to the next instance of ax
character on the current line, (; to repeat)Fx
to move to the previous instance of ax
character on the current line ( ; to repeat))
sentence end}
paragraph end$
line end^
first non-blank character of line0
start of linegg
file beginningG
end of filegD
go to the current method definition%
on a(
or\[
go to the ending brace)
or\]
otherwise go to the preceding one.
Normal mode to insert mode
i
start insert mode at cursorI
insert at the beginning of the linea
append after the cursorA
append at the end of the lineo
open (append) blank line below current line (no need to press return)O
open blank line above current lineea
append at end of wordcc
change (delete and go in insert mode) an entire linecw
change (replace) to the end of wordc$
change (replace) to the end of lineciw
replace wordci)
replace parenthesis cents
delete character at cursor and enter insert modeS
delete line at cursor and substitute text (same as cc)
Undo / Redo / Repeat
u
undoCtrl+r
redo.
repeat last command
Scrolling
Crtl+(f/F)
next pageCrtl+(b/B)
previous pageCrtl+u
move up half a pageCrtl+d
move down half a screen
Visual mode
v
enter visual modeShift+v
enter visual mode lines onlyCtrl+v
enter rectangular visual mode (bloc mode)
Exemple, to ident 3 lines:
* Shift-v
* select 3 lines
* ==
Buffers (not tabs !)
:bn
buffer next:bp
buffer previous:bd
buffer delete (close):ls
list buffers:bufdo cmd
execute cmd on all open buffers
Exemples:
* bufdo w
write all buffers
* bufdo bd
close all buffers
Windows
:vsplit
or:vsp
vertical split:split
or:sp
horizontal splitCrtl + w
thenw
navigate through windowsCrtl + w
thenarrow
navigate to arrow directed windowCtrl + w
then+
increase the actual viewport sizeCtrl + w
then-
decrease the actual viewport sizeCtrl + w
then=
equalize viewports sizesCtrl + w
thenr
exchange viewport positionsCtrl + w
thenR
exchange viewport in reverse orderCtrl + w
thenq
close the actual viewport
Search / Replace
#
in normal mode, search backward for the previously word under cursor occurence:s/toto//
search the first occurence oftoto
on the line:s/toto//g
search all occurences oftoto
on the line:%s/toto//g
search all occurences oftoto
for each line of the buffer (or opened file)n
go to the next occurence of what was previously searched:s/toto/tata/
replace the first occurence oftoto
on the line bytata
:s/toto/tata/g
replace all occurences oftoto
on the line bytata
:%s/toto/tata/g
replace all occurences oftoto
in the buffer bytata
- regex allowed ;)
Mapping
Test in buffer before putting them in your .vimrc to create your own shortcuts
* :map
insert + normal mode
* :nmap
normal mode
* :imap
interactive mode
* :iab
substitue
Exemples:
* :nmap <tab> :bnext <CR>
pressing tab
will go to the next buffer in normal mode only
* :map <C-n> :vsp<CR>
pressing Crtl + n
will vertical split the current viewport in normal and insert mode
* :iab c Class
typing c
then space
will be expanded to Class
Macros
- Start with recording: qq
- Do stuff
- Stop recording: q
- Repeat: @q (the first time), @@ after that.
- Repeat 20 times: 20@@
External commands
:!cmd
executes a linux command (ex::!echo 'toto'
) If vim runs at project root::make
works:make target
works great:.! ls
dumps ls result in current window:r! ls
dumps ls result in current window:%!sort
sorts the entire buffer (works best with awk or sed)
Register
To use when working in the : mode
* a - z
the named registers
* "
the unnamed register, containing the text of the last delete or yank
* %
the current file name
* #
the alternate file name
* *
the clipboard contents (X11: primary selection)
* +
the clipboard contents
* /
the last search pattern
* :
the last command-line
* .
the last inserted text
* -
the last small (less than a line) delete “
Ex: when you :%s/toto/tata/g to replace toto by tata in the whole buffer
Marks
ma
mark the actual position with the lettera
a
go to marka
'a
go to the beginning of thea
marked line:marks
show the mark listing
TODO sort this
t
tag example: (dat
deletes from<xml-style-tag>
to</xml-style-tag>
)p
paragrapheB
code block ({
ou}
works only for C style code blocks:25
go to line 25
Usefull Tricks
.
repeat the last text changing command*
on a word to search for the next instance#
on a word to search for the previous instancectx
delete everything until characterx
and enter insert modedtx
delete everything until characterx
(x exclude) and don’t enter insert modedfx
delete everything until characterx
(x include) and don’t enter insert modeda(
inside a parenthesis, deletes parenthesis and inner contentda"
inside a string, deletes character string content and quotesytx
copy until characterx
Shift+j
orJ
add the next line to the end of the current lineShift+k
orK
show the manual page (manual like inman
) for the word under the cursor~
modify the under the cursor character case.
repeat the last command:u
undoCrtl + r
redoCrtl + A
increment “under the cursor” numberCrtl + X
decrement “under the cursor” numberr
replace a letterR
enter replace mode:w !sudo tee %
edit the file anywway if you forgot to call vim with the sudo command:earlier 15m
reverts the document back to how it was 15 minutes ago.:later
revert previous commanddiw
to delete the current worddi(
to delete within the current parensdi"
to delete the text between the quotesci(okok
remplace current parenthesis content with okokC
cut the rest of the line and switch to insert modxp
toggle cuurent char position with the following onexP
copy a characterddp
move current line one row downbde
delete current wordbye
copies current word same asyiw
d$
(orD
) delete until the end of lineg;
goto last insert mode cursor position and stay in normal modegi
goto last insert mode cursor position and enter insert mode:g/pattern/y
A copy all lines containing pattern in a buffer you can then paste:sh
open shell and mask vim Crtl-D kills the shell and brings vim back !gf
goto file which name is under the cursor%TOhtml
Creates an html rendering of the current file.gg=G
Corrects indentation for entire filevip
select in visual mode the entire paragraph
Plugins
TComment
Commands
gc{motion}
Toggle comments (for small comments within one line the &filetype_inline style will be used, if defined)-
gc<Count>c{motion}
Toggle comment text with count argument (seetcomment#Comment() ) gcc
Toggle comment for the current linegC{motion}
Comment regiongCc
Comment the current line
Keymapping
<c-_><c-_>
Toggle comment on line<c-_>p
Comment the current inner paragraph<c-_>i
TCommentInline
Jedi
Keymapping
<leader>g
goto command<leader>d
get definition commandK
show PyDoc<leader>r
refactoring rename item<leader>o
list all names that are related (have the same origin)<C-Space>
autocompletion command
Tell me about your favorite shortcut in the comments, I will add them !