NOTE: Every command in vi Editor should be start with “:” except insert cmd
set “vi” editor as default editor
export EDITOR=vi
Open existing file in “vi” editor
Cmd: vi {file_name}
Close a file with out changes
:q or :q!
Close & save with all changes
:wq!
Write the content in editor
Cmd : i (when click on ‘i’ button, it shows --- INSERT--- in bottom of screen)
show line numbers in a file
:set num
Jump to specific line in a file
:{line_no}
Delete entire content in file
:%d
Delete specific lines in a file
:start_line_no,end_line_no{d}
E.g: :2,45d
Directly go to specific line while opening file
sudo +line number {file_name}
e.g: sudo +300 demo.txt
Search a word or string in a file
/{search_term}
E.g: :/page
Delete a current line
:dd
Undo last command
:u
0 Comments