The tricky part is to remember the shortcuts for using this editor. To start the application use it like this : vi filename
There are two modes in this text editor :
I.Command MODE
When you start you are in command mode.
You can use the arrow keys to move around but you can start using HJKL if you decide to go pro.
Copy/Paste
yy # to copy the current line
p # to paste the text in the buffer
Undo
u # to undo the last operation
Deleting a row
dd - is used to delete the current row
To save
:w
To exit and save
zz
To exit no save
:q!
II. Insert MODE
If you want to go in insert mode you can press
i # to start inserting before the current position
a # to start inserting after the current position
If you want to exit Insert Mode you can press
!!! Don't press the arrow keys why in Insert mode. Use only DELETE to erase the current position.
Source: http://ubuntuswitch.blogspot.com/2007/09/vi-text-editor.html
-------------------------------------------------
Displaying line numbers while editing a file
:set number
:set nonumber
-----------------------------------------------------
Search and Replace
First occurrence on current line: :s/OLD/NEW
Globally (all) on current line: :s/OLD/NEW/g
Between two lines #,#: :#,#s/OLD/NEW/g
Every occurrence in file: :%s/OLD/NEW/g
http://www.felixgers.de/teaching/emacs/vi_search_replace.html
---------------------------------------------------------------------
How to show special characters in a file with vi
:set list -- Show invisible characters
:set nolist -- Don't show invisible characters
No comments:
Post a Comment