Difference between revisions of "Vi, Vim, Vscode editors"
Jump to navigation
Jump to search
Line 20: | Line 20: | ||
u -undo last change | u -undo last change | ||
Ctrl-R -redo changes which were undone (undo the undos). '.' to repeat a previous change, at the current cursor position | Ctrl-R -redo changes which were undone (undo the undos). '.' to repeat a previous change, at the current cursor position | ||
;Visual mode | ;Visual mode | ||
v -visual selection using arrows and navigation keys | v -visual selection using arrows and navigation keys | ||
^v -visual block selection, y-yank, d-delete, i-insert still work | ^v -visual block selection, y-yank, d-delete, i-insert still work | ||
Line 26: | Line 26: | ||
;Multi-line insert in visual block selection | ;Multi-line insert in visual block selection | ||
Press '''<tt>I</tt>''' to start a special form of insert mode, then type the wanted text (s:). When you press '''<tt>Esc</tt>''' to exit from insert mode, the text will be inserted in the same position on each of the lines affected by the visual block selection. | Press '''<tt>I</tt>''' to start a special form of insert mode, then type the wanted text (s:). When you press '''<tt>Esc</tt>''' to exit from insert mode, the text will be inserted in the same position on each of the lines affected by the visual block selection. | ||
;Insert comments sign # at the begging each line between 10 and 12th line | |||
:set number | |||
:10,12s/^/# | |||
;Wrap text | ;Wrap text |
Revision as of 11:50, 6 September 2016
VI or VIM
This section describes both editors however these days vi command is an alias to vim. Therefore bear in mind although all have been tested the test itself was made on VIM.
- drop to bash
:!bash or :!sh
- edit other file
:e file.txt #autocomplite works
- redirect command STDOUT to the current edited file in the cursor position
:r!dir
- show line number
:set number or :set nu
- find and replace in VI called substitute (ref. sed)
:%s/wily/trusty/g #substitute all wily with trusty in all document :s/wily/trusty/g #substitute only in the current line
- find and print only lines that match the search
:g/string-to-search/p # :g -global search, /p -print out on a screen
- Undo and redo
u -undo last change Ctrl-R -redo changes which were undone (undo the undos). '.' to repeat a previous change, at the current cursor position
- Visual mode
v -visual selection using arrows and navigation keys ^v -visual block selection, y-yank, d-delete, i-insert still work
- Multi-line insert in visual block selection
Press I to start a special form of insert mode, then type the wanted text (s:). When you press Esc to exit from insert mode, the text will be inserted in the same position on each of the lines affected by the visual block selection.
- Insert comments sign # at the begging each line between 10 and 12th line
:set number :10,12s/^/#
- Wrap text
:set wrap or :set nowrap
VIM only
- Split
:split or :vsplit C^w, c -close current window C^w, C^w - switch between windows
Vimdiff - diff compare
Compare multiple files using Screen program widows like
vimdiff -d file1 file2
Change colour of dark blue comments
You can do it manually with the command below, where ABCDEF is an appropriate colour hex code.
:hi Comment guifg=#ABCDEF
To make it permanent, add these lines to your ~/.vimrc file (using green as an example):
syntax on :highlight Comment ctermfg=green
Oneliner
echo "syntax on" >> ~/.vimrc && echo ":highlight Comment ctermfg=green" >> ~/.vimrc