- 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)
yyank or copy to default register""and also to"0registerddelete or cutccut / cut and go to insert modeppaste"0ppaste from the copy register (even if you haveddorxin the meantime)
Insert mode paste
<C-r>0paste the yank register<C-r>"paste the default register<C-r>apaste 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.
"*ppaste the middle-click buffer"+ppaste theCrtl+Cbuffer- works with
yanddtoo…
Moves (adjectives)
These can be applied to previously defined actions
ssentencewnext wordWnext space-separated wordbprevious wordBbegining of / previous word (space separated)eend of wordEend of / next word (space separated)txto next characterxexcludingxTxto previous characterxexcludingxfxto move to the next instance of axcharacter on the current line, (; to repeat)Fxto move to the previous instance of axcharacter on the current line ( ; to repeat))sentence end}paragraph end$line end^first non-blank character of line0start of lineggfile beginningGend of filegDgo 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
istart insert mode at cursorIinsert at the beginning of the lineaappend after the cursorAappend at the end of the lineoopen (append) blank line below current line (no need to press return)Oopen blank line above current lineeaappend at end of wordccchange (delete and go in insert mode) an entire linecwchange (replace) to the end of wordc$change (replace) to the end of lineciwreplace wordci)replace parenthesis centsdelete character at cursor and enter insert modeSdelete line at cursor and substitute text (same as cc)
Undo / Redo / Repeat
uundoCtrl+rredo.repeat last command
Scrolling
Crtl+(f/F)next pageCrtl+(b/B)previous pageCrtl+umove up half a pageCrtl+dmove down half a screen
Visual mode
venter visual modeShift+venter visual mode lines onlyCtrl+venter rectangular visual mode (bloc mode)
Exemple, to ident 3 lines:
* Shift-v
* select 3 lines
* ==
Buffers (not tabs !)
:bnbuffer next:bpbuffer previous:bdbuffer delete (close):lslist buffers:bufdo cmdexecute cmd on all open buffers
Exemples:
* bufdo w write all buffers
* bufdo bd close all buffers
Windows
:vsplitor:vspvertical split:splitor:sphorizontal splitCrtl + wthenwnavigate through windowsCrtl + wthenarrownavigate to arrow directed windowCtrl + wthen+increase the actual viewport sizeCtrl + wthen-decrease the actual viewport sizeCtrl + wthen=equalize viewports sizesCtrl + wthenrexchange viewport positionsCtrl + wthenRexchange viewport in reverse orderCtrl + wthenqclose the actual viewport
Search / Replace
#in normal mode, search backward for the previously word under cursor occurence:s/toto//search the first occurence oftotoon the line:s/toto//gsearch all occurences oftotoon the line:%s/toto//gsearch all occurences oftotofor each line of the buffer (or opened file)ngo to the next occurence of what was previously searched:s/toto/tata/replace the first occurence oftotoon the line bytata:s/toto/tata/greplace all occurences oftotoon the line bytata:%s/toto/tata/greplace all occurences oftotoin 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
:!cmdexecutes a linux command (ex::!echo 'toto') If vim runs at project root::makeworks:make targetworks great:.! lsdumps ls result in current window:r! lsdumps ls result in current window:%!sortsorts 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
mamark the actual position with the letteraago to marka'ago to the beginning of theamarked line:marksshow the mark listing
TODO sort this
ttag example: (datdeletes from<xml-style-tag>to</xml-style-tag>)pparagrapheBcode block ({ou}works only for C style code blocks:25go 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 instancectxdelete everything until characterxand enter insert modedtxdelete everything until characterx(x exclude) and don’t enter insert modedfxdelete 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 quotesytxcopy until characterxShift+jorJadd the next line to the end of the current lineShift+korKshow the manual page (manual like inman) for the word under the cursor~modify the under the cursor character case.repeat the last command:uundoCrtl + rredoCrtl + Aincrement “under the cursor” numberCrtl + Xdecrement “under the cursor” numberrreplace a letterRenter replace mode:w !sudo tee %edit the file anywway if you forgot to call vim with the sudo command:earlier 15mreverts the document back to how it was 15 minutes ago.:laterrevert previous commanddiwto delete the current worddi(to delete within the current parensdi"to delete the text between the quotesci(okokremplace current parenthesis content with okokCcut the rest of the line and switch to insert modxptoggle cuurent char position with the following onexPcopy a characterddpmove current line one row downbdedelete current wordbyecopies current word same asyiwd$(orD) delete until the end of lineg;goto last insert mode cursor position and stay in normal modegigoto last insert mode cursor position and enter insert mode:g/pattern/yA copy all lines containing pattern in a buffer you can then paste:shopen shell and mask vim Crtl-D kills the shell and brings vim back !gfgoto file which name is under the cursor%TOhtmlCreates an html rendering of the current file.gg=GCorrects indentation for entire filevipselect 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() ) gccToggle comment for the current linegC{motion}Comment regiongCcComment the current line
Keymapping
<c-_><c-_>Toggle comment on line<c-_>pComment the current inner paragraph<c-_>iTCommentInline
Jedi
Keymapping
<leader>ggoto command<leader>dget definition commandKshow PyDoc<leader>rrefactoring rename item<leader>olist 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 !