Monday, 29 August 2011

VI Essentials

Sometimes you visit a client and you have got only access to the vi editor. While this editor can be frustrating to learn especially for Windows and Mac users I believe that learning or referring to the below commands might become handy to any IT professional.

Starting/Saving
vi [+n] <file_name>
Open filename positioning the cursor at line number n
:wq
Save the file to disk and quit
:q!
Quit without saving any changes


Moving Cursor
h (or Left arrow key)
Left
l  (or Right arrow key)
Right
k (or Up arrow key)
Up
j  (or Down arrow key)
Down
G
End of file
^
Beginning of current line
$
End of current line


Searching Text
/string
Search down for string
?string
Search up for string
n
Repeat last search
:%s/old-string/new-string/g
Search and replace old-string with new-string


Copying and Pasting Text
[n]yy
Copying n lines into buffer
p
Paste the buffer after the current line


Inserting and Deleting Text
i
Insert starting left of cursor
x
Delete single character
[n]dd
Delete n lines
u
Undo last change


Directives
:set nu / :set nonu
Turn on line numbering / Turn off line numbering
:set ic / :set noic
Ignore case when searching / Ignore case off

1 comment:

  1. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    Amazon Web Services Training in Pune | Best AWS Training in Pune

    ReplyDelete