40 lines
No EOL
2.1 KiB
Markdown
40 lines
No EOL
2.1 KiB
Markdown
Basics 3
|
|
|
|
- cursor location
|
|
`<C-g>` to show location in file and file status. It means 'Ctrl+G'.
|
|
`gg` is used to to start of file like using Ctrl+Home in gui editors
|
|
`G` for end of file
|
|
To go to specific line number `<line_number>G`. Eg: for line number 123 type `123G`.
|
|
- Search command
|
|
To search word type `/<word>`. To search error type `/error`. Then type `n` to go to next search and `N` to 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 `:noh`
|
|
Reference: 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 letter `o`).
|
|
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/g` to 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/g`
|
|
For whole file but with prompt
|
|
`%s/old/new/gc`
|
|
|
|
- Executing external commands
|
|
`:!ls` or `:!pwd`
|
|
- Selecting text to write
|
|
To start selecting text press `v` then move cursor right and down to area u want ti selected. To finish selecting a text type colon `:` `'<,'>` will appear now just type `w` and 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 |