2.1 KiB
Basics 3
-
cursor location
<C-g>to show location in file and file status. It means 'Ctrl+G'.ggis used to to start of file like using Ctrl+Home in gui editorsGfor end of file To go to specific line number<line_number>G. Eg: for line number 123 type123G. -
Search command To search word type
/<word>. To search error type/error. Then typento go to next search andNto go to opposite one./is used to search in direction from up to down. To search in direction from down to up use?. Note: To remove highlighting of previous search type:let @/ = ""or use:nohReference: https://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting To go back to where you came from press<C-o>. (keep<Ctrl>pressed down while pressing the lettero). Repeat to go back further.<C-i>{normal} goes forward. -
Matching parenthesis search Type
%to find a matching),], or}. Place the cursor on parenthesis For eg on(tree (they r here [done] ) Then type%. it will move to). Now type%again and it will move back to(. -
Substitute command Type
:s/old/new/gto substitute "new" for "old". Move the cursor to line where subtitution needed to be take place. If g is not used then only first occurence will be substituted instead of all occurences of current line.:201,204s/old/new/g: replace old with new from line 201 to 204 For whole file%s/old/new/gFor whole file but with prompt%s/old/new/gc -
Executing external commands
:!lsor:!pwd -
Selecting text to write To start selecting text press
vthen move cursor right and down to area u want ti selected. To finish selecting a text type colon:'<,'>will appear now just typewand file name where u want to be saved'<,'>w Test.txt. Now selected text will be saved in filename 'Test.txt' -
Retrieving and merging file Move cursor to desired line and type
:r TEST:This will copy contents of file TEST to current position:r !ls: This will copy output of commands ls to current position