VI
Cheat sheet
Visual mode | Shift + v |
Visual block Mode | Ctrl + v |
go to line 55 | 55 gg |
G | Go to the end of the document |
Block comment/uncomment
- Comment: Go into visual block mode
- shift-i to insert, add a # (or any other comment sign)
- the symbol appears in the first line
- esc and it gets copied on every line (it happens only after the -esc !!)
- Uncomment: Select in visual block mode and delete.
Indent
In normal mode, type >>
to indent the current line, or <<
to unindent. Each command can be used with a count. The operators >
and <
do the same for motions, text objects and visual selections. For all commands, pressing .
repeats the operation.
For example, typing 5>>..
shifts five lines to the right, and then repeats the operation twice so that the five lines are shifted three times.
In insert mode, Ctrl-T
indents the current line, and Ctrl-D
unindents.
When indenting or unindenting, lines are shifted one 'shiftwidth'
to the right or left.
:set shiftwidth=4
Source: https://vim.fandom.com/wiki/Shifting_blocks_visually
Substitution
- % indicates the entire file
- s is for “substitute” (or only search)
- g global, replace all occurrences in the line (not only the first)
:[range]s/search/replace/
:8,10 s/search/replace/g
:%s/search/replace/g
:%s/stretch/buster/g
Replace backslah (\) with slash (/)
:g/\\/s//\//g
:%s/\\/\//g
~/.vimrc
syntax on
set background=dark
:command W w
:command Q q
Security
https://docs.ansible.com/ansible/latest/user_guide/vault.html#steps-to-secure-your-editor
Add comment to file for indentation and stuff
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet