Last Updated: February 25, 2016
·
334
· kelkooelodies

Useful commands for vi tool

undo/redo

undo: u
redo: ctrl-r

case ignoring

desactivate case: :set ic
activate case: :set noic

see all characters

to see all characters (tab...): :set list

text substitution

subsitute X by Y in all file (regex allowed in X and Y): :%s/X/Y/g
subsitute X by Y from line A to line B only (regex allowed in X and Y): :A,Bs/X/Y/g

use visual mode to copy/paste/delete/substitute

use visual mode to select text: v then use arrows keys
then you can use classic commands on selected text: d to delete, y to copy, :s/X/Y/g to substitute X by Y in the selection

use external command to manipulate current text

example: use the external "sort" command to sort all file: :%!sort (can be obviously used on visual selection too)
example: insert external command output "hostname" at current position: :r!hostname

use different copy/paste buffers

list all buffers: :reg
paste content of buffer number X than the default: "Xp

manage multiple files

open multiple files: vi file1 file2 file3
naviguate from one file to another: :n forward and :N backward
open multiple files with vertical splitted screen: vi -o file1 file2 file3 then use ctrl-ww to move to next screen

set options from command line

use the "+" option when opening files: vi +"set ic" +"set nu" file1 file2" to open files with case ignoring and lines number displayed