Version 1.1 April 1st, 06 Esc Vi / Vim Graphical Cheat Sheet

Transcription

version 1.1April 1st, 06vi / vim graphical cheat sheetEscnormalmode ·togglecasegotomarkmotion@· #&%! (*)75694831 2 20QRYPIOUW ET·1,3q·r·ywet·pouiDASF·GHJKL:1,3g· 6 h;askjdf·l343C 1,3 V Z· XBNM5cz·nm· sentencenextidentendsentence"hard"bol{1[·"soft" boldown }]·nextlineauto k'tillyanklineundolineinsertat odeopenbelowpasteaftermiscmiscappendat eolsubstlinedeleteto eol"back"find chappendsubstchardeletefindchareof/goto ackspacechangeto next(find)setmarkreverset/T/f/Frepeatcmdmoves the cursor, or definesthe range for an operatorcommand direct action command,if red, it enters insert moderequires a motion afterwards,operator operates between cursor &destinationspecial functions,extrarequires extra inputcommands with a dot needa char argument afterwardsbol beginning of line, eol end of line,mk mark, yank copywords: quux(foo, bar, baz);WORDs: quux(foo, bar, baz);q·"soft"bolgotomatcheolMain command line commands ('ex')::w (save), :q (quit), :q! (quit w/o saving):e f (open file f),:%s/x/y/g (replace 'x' by 'y' filewide),:h (help in vim), :new (new file in vim),Other important commands:CTRL-R: redo (vim),CTRL-F/-B: page up/down,CTRL-E/-Y: scroll line up/down,CTRL-V: block-visual mode (vim only)Visual mode:Move around and type operator to acton selected region (vim only)ex cmdlinerepeatt/T/f/F?·/·"·'·reg. 1specgotomk. bolbol/ gotocolnot\· used!find(rev.)findNotes:(1) use "x before a yank/paste/del commandto use that register ('clipboard') (x a.z,*)(e.g.: "ay to copy rest of line to reg 'a')(2) type in a number before any actionto repeat it that number of times(e.g.: 2p, d2w, 5i, d4j)(3) duplicate operator to act on current line(dd delete line, indent line)(4) ZZ to save & quit, ZQ to quit w/o saving(5) zt: scroll cursor to top,zb: bottom, zz: center(6) gg: top of file (vim only),gf: open file under cursor (vim only)For a graphical vi/vim tutorial & more tips, go to www.viemu.com - home of ViEmu, vi/vim emulation for Microsoft Visual Studio

version 1.1April 1st, 06motionvi/vim lesson 1 - basic editingmoves the cursor, or definesthe range for an operatorcommand direct action command,if red , it enters insert modeEscnormalmode WwnextWORDnextwordEeendWORD ppendat eoljhXxbackspacedeletecharBb"hard"bolkl:ex cmdlineprevWORDprevwordBasics:Extras:h j k l are vi/vim cursor keys – use them as they are muchcloser than regular cursor keys!u to undo the last action – traditional vi has a single level, while vimsupports unlimited undo (CTRL - R to redo)Use i to enter insert mode, cursor turns from a block into a verticalline, and you can type in text. Use Esc to return to normal mode.jumps directly to the beginning of the line, to the end,and to the first non-blankUse x to delete the current character, or X to delete the one tothe leftUse w b e to move along ‘words’. A ‘word’ is a sequence of allalphanumeric or punctuation signs: quux(foo, bar, baz);Use A to go insert text at the end of the line (wherever you arein the line!)Use W B E to move along WORDs. A 'WORD' is a sequence ofany non-blank characters: quux(foo, bar, baz);(Note: insert mode is actually very similar to a regular editor, you can usecursor/navigation keys, backspace, delete )0Use R to enter insert mode with an overstrike cursor, whichtypes over existing characters.: w and press enter to save, : q and enter to quit.For the rest of the tutorial & a full cheat sheet, go to www.viemu.com - home of ViEmu, vi/vim emulation for Microsoft Visual Studio

version 1.1April 1st, 06learned in previouslessonsmovesthe cursor, or definesmotionthe range for an operatorcommand direct action command,if red , it enters insert modeoperator requires a motion afterwards,operates between cursor &destinationLearnedlearnedvi/vimlesson2 - operatorsrepetitionvi / vimII - operators&&repetitionEscnormalmode 4R 98insertmode:"back"findfwdchappendat isualmodejhfindfwdtocharcharBb"hard"bolklex cmdlineprevWORD.prevwordrepeatcmdBasics:Extras:f , followed by another key, moves the cursor to the next instanceof that character on the current line, F does the same backwards.Prepend a count to any command/motion to repeat it that numberof times:d 2 w to delete up to the second word.d 2 t 2, to delete up to but not including the second comma.2 i repeats the text after you press (Esc) to finish the input session.t and T do the same, but they stop right before the character.d (delete), followed, by any motion deletes the text between thet , d f - ).cursor and that motion’s destination d wc (change) does the same, but leaves you in insert mode.Some motions, such as j and k , are linewise – deletion includesthe full start/end lines. repeats the last editing action: text input, delete or change, etc motion is recalculated at the new place.Repeat operator ( c c or d d ) to operate on the current line.Only in vim, v enters visual mode. Move around with motions, thetext will be highlighted. Press an operator to operate on that selection.V enters visual-lines mode – like v , but selecting whole lines.CTRL - v selects rectangular blocks.For the rest of the tutorial & a full cheat sheet, go to www.viemu.com - home of ViEmu, vi/vim emulation for Microsoft Visual Studio

version 1.1April 1st, 06learned in previouslessonsmotion moves the cursor, or definesthe range for an operatorcommand direct action command,if red , it enters insert modeoperator requires a motion afterwards,operates between cursor &destinationspecial functions,extrarequires extra inputLearnedlearnedvi/vim lesson 3 - yank & pasteEscnormalmode 4R t eol5T·t·replacemodeF·1,3f·dXVc 1,3 "back"find modejhfindcharBbk0Pplex ExtrasUse y followed by any motion to ‘yank’ (copy).22(“)2" and an a" - z" character before any yank/delete/paste commandchooses a register.22" - Z" register before yank/delete means “append-copy”.An AUse pv to paste after (if charwise, to the right, if linewise, below).v to paste before.Use Py y copies the current line.22 select the system clipboard." 2"* or 2" y also works in visual mode.v is also copied!Text deleted with d , c , xv enters insert mode in a new empty line below the current one.0v does the same above the current line.OFor the rest of the tutorial & a full cheat sheet, go to www.viemu.com - home of ViEmu, vi/vim emulation for Microsoft Visual Studio

version 1.1April 1st, 06learned in previouslessonsmotion moves the cursor, or definesthe range for an operatorcommand direct action command,if red , it enters insert modeoperator requires a motion afterwards,operates between cursor &destinationspecial functions,extrarequires extra inputLearnedlearnedvi/vim lesson 4 - searchingEscnormalmode#23W Eweprevident12Aappendat eol 4R deF·1,3f·dXVc 1,3 aste 1after:"back"find ext(find).repeatcmdex cmdline?·/·"·reg. 1specfind(rev.)findBasics:Extras:/ is the basic search motion – type the text you are searching forkafter the slash, and then press return. Being a motion, you can usethis after an operator, or in visual mode.The following very useful motions work only in vim:k* searches forward for the next instance of the identifier underthe cursor.k does the same backwards.#? does the same, backwards.kk repeats it innk repeats the last search in the same direction, Nthe reverse directionBe careful, because the search target is interpreted as a regularexpression: a*b means zero or more ‘a’s followed by a ‘b’, abcmeans ‘abc’ at the beginning of a line, [0-9] looks for the nextdigit, etc For the rest of the tutorial & a full cheat sheet, go to www.viemu.com - home of ViEmu, vi/vim emulation for Microsoft Visual Studio

version 1.1April 1st, 06learned in previouslessonsmovesthe cursor, or definesmotionthe range for an operatorcommand direct action command,if red , it enters insert moderequiresa motion afterwards,operatoroperates between cursor &destinationspecial functions,extrarequires extra inputLearnedlearnedvi/vim lesson 5 - marks & macrosEscnormalmode ·@· #1 2 23W Eweq·Aplaymacrogotomarkrecordmacroappendat eolprevident F·1,3f·dXVc 1,3 owpaste1after:"back"find ordkjhfindcharbackspacedeletechar 6eolNnprev(find)next(find)m·setmarklex cmdline"·'·reg. 1specgotomk. bol.repeatcmd?·/·find(rev.)findMarks:Macros:v followed by an av - zv character to set a mark.Use mv̀ followed by a character to go to that mark.Use vv - zv character to start recording.v followed by an aUse qUse v' and a character to go to the first non-blank in that line.v marks are global, av - zv per-buffer.v - ZAv afterwards to stop recording.Use q@v followed by a character replays that macro.@v @v to repeat the last macro played.v̀ . refers to the position of the last modification.vFor the rest of the tutorial & a full cheat sheet, go to www.viemu.com - home of ViEmu, vi/vim emulation for Microsoft Visual Studio

version 1.1April 1st, 06learned in previouslessonsmotion moves the cursor, or definesthe range for an operatorcommand direct action command,if red , it enters insert modeoperator requires a motion afterwards,operates between cursor &destinationspecial functions,extrarequires extra inputLearnedlearnedvi/vim lesson 6 – various motionsEscnormalmode ·@· #1 2 23W Eweq·A% macrogotomarkrecordmacroappendat eolprevident replacemode'till"back"find chdeleteundoyankeof/goto lnchange() 09{}OP1po[·]·:L"· nbelowpasteaftermiscmiscscreenbottomex cmdlinereg.specgotomk. bolfind(rev.)repeatcmdfind% jumps between matching pairs of ‘(‘ ‘)’, ‘[‘, ‘]’, etc ( and ) jump to the beginning/end of the current sentence.H M L jump directly to the top/middle/bottom of the screen.{ and } jump to the previous/next empty line.G jumps to the end of the file, or to the line # typed before it.[[ jumps to the previous '{' in column 0.- / jump to the previous/next line.G]] jumps to the next '{' in column 0.K , not technically a motion, jumps to the help for the word underthe cursor: vim help, man page under unix, etc.For the rest of the tutorial & a full cheat sheet, go to www.viemu.com - home of ViEmu, vi/vim emulation for Microsoft Visual Studio

version 1.1April 1st, 06learned in previouslessonsmotion moves the cursor, or definesthe range for an operatorcommand direct action command,if red , it enters insert modeoperator requires a motion afterwards,operates between cursor &destinationspecial functions,extrarequires extra inputLearnedlearnedvi/vim lesson 7 - various commandsEscnormalmode ·togglecasegotomark@· #% (*)24207569813T·ORW EPYt·yweq·our·piDLF·SG:AJKH1,3skjf·dlhC XBVMNm·c 1,3 endat wordendwordreplacechar'tillyanksubstlinedeleteto eol"back"find chsubstchardeletefindchareof/goto o bottomindentrepeatcmd?·/·v and a motion to reformat a range of text. vs deletes the character under the cursor and enters insert mode.v clears the current line and enters insert mode.Sbeginparag.endparag.miscmisc"·'·reg. 1specfind(rev.)findExtras:vr followed by any character replaces the current character withthat one.y , yanks the whole line.y vv is shorthand for vY{[·gotomk. bolv and a motion to indent one or more lines. v , deletes to end of line.v is shorthand for dv Dautoformatprevlineex cmdlinev joins the current line with the next one, or all the lines in theJcurrent visual selection.v is shorthand for cv v , changes to end of line.Cnextline-openabove }]·v and a motion to unindent. v v , etc )All of them work in visual mode, or can be repeated ( to operate on the current line. v toggles the case of the character under the cursor.Now go grab the full cheat sheet and learn the rest.a v, and v; . Piece of cake!I vStart with vFor the rest of the tutorial & a full cheat sheet, go to www.viemu.com home of ViEmu, vi/vim emulation for Microsoft Visual Studio

For the rest of the tutorial & a full cheat sheet, go to www.viemu.com - home of ViEmu, vi/vim emulation for Microsoft Visual Studio prev B WORD b prev word back-X space x delete char Basics: h j k l append A at eol next W WORD w next word end E WORD e end word i insert mode Rreplace mode u undo 0"hard" bol eol "soft" bol motion command .