Editing Text files using Vim

Vim editor is an enhancement of Vi editor
Vi stands for Vi Improved, it is used as Text Editor.

Syntax: # vim [options] [filename]

eg: # vim hello.txt

for more information about the options use man pages for vim command.

After executing vim command There are two interfaces in vim editor

1. For insert mode press ‘i’, which is used for writing the text.

2. For Command mode press ‘ESC’ then enter the command and press ‘Enter’, based on that command we save or unsave and exit from text editor.

Now, lets understand the various commands in vim Text editor.To Save a file

To Save a file
command: :w
To Save and quit a file command: :wq To quit a file which is modified (without any overwriting) command: :q!  To undo the text command: press 'u' To redo the text command: press 'ctrl+R' To come to starting of the file command: press 'gg' or :0 To go to bottom of the file command: press 'G' To go to particular line command: Type the number of the line you need and then press 'G' To come to starting of the line command: press '0' To come to end of the line command: press 'A' To come to next word at starting command: press 'w' To come to next word at ending command: press 'e' To come to next 3rd word command: press '3w' To replace the text go to infront of the text command: press 'R' To search a keyword(Text) Forward Search: command: ?keyword eg: ?Sandeep Back word Search: command: /keyword eg: /Sandeep To Find and replace the Keyword(Text) command: :g/search-string/s//replace-string/g eg: :g/sandeep/s//kiran/g To get the count of the Keyword(Text) in a file command: :%s/search-string//gn eg: :%s/sandeep//gn To delete a word: command: dw To delete a sentence: command: ddw To copy the sentence: command: press 'yy' To paste the sentence: command: press 'p' To paste the 10 sentences: command: press '10p'

To see the related command
type a command eg: ‘:e’ and press ‘ctrl+D’ to list all the command name starts with :e and press tab to complete the command

Leave a Reply

Your email address will not be published. Required fields are marked *