Friday, September 10, 2010

Vim Editor For Beginners : Commands and Things you should Know about VIM

A Brief History:

When UNIX was developed and emerged at Bell Laboratories in 70's,The initial version of UNIX that was distributed had a line editor called as 'ed'  developed by Ken Thomson,'ed' was considered very difficult to use ,many people tried to enhance the functionality of 'ed' and an enhanced version of 'ed' was developed by George Coulouris and named it as 'em' .After some time Bill Joy a student at Berkeley merged various features of 'ed' and 'em' and produced a new version called as 'ex'. Though 'ex' had many combined features of 'ed' and 'em' it was still a line editor, then in 1976 'vi' was developed and it was a rewritten version of 'ex' .Vi was not a line editor like 'ed' or 'em'  it was a screen editor and had many features  of 'ex'.Vim is now improved version of Vi.

Vim as a modal editor:

Vim is known as a modal editor which means Vim will perform certain operations depending on the mode in which it is currently set. Three modes are most important to understand the working of vim.
Command mode,Insert mode and Command-line mode.


Command mode:

Its the central mode of Vim .When you first start Vim it always starts in this mode,in this mode vim accepts commands known to it. like deletion ,copy paste, and cursor movement commands. you cannot enter text in this mode.

Insert mode:


Insert mode is responsible for receiving the characters from standard input and writing them to the file that you are editing . You cannot enter text into a file without going into the insert mode. Actually
this is the first source of confusion to the people who are new to Vim environment .

Command-line mode:

This mode is used for  major Vim operations like opening and closing a file, Vim configurations ,Searching commands,compiling codes, and executing external commands.

Switching between different modes:

As I mentioned earlier when you start vim for the first time it starts in Command mode or normal mode,From here you can switch to any other mode by pressing :

I,i or INSERT button  → Insert mode
colon(:)                       → Command-Line mode
V                                 → Visual mode
R                                 → Replace

Once you entered in a certain mode you cannot go back to other modes by just pressing the above keys.
To achieve this Vim uses another mechanism called as escaping from a mode.

Don't bother its a simple thing,Lets say you are in Insert mode now if you want to go to command-line mode press Esc button and you are in your normal mode from where you can go to any other mode or again in Insert mode by pressing 'I' .

Starting and Exiting Vim:

To start Vim open up the terminal type vim and press enter :

# vim





To quit Vim use following commands in Command-Line mode:

q                       → Exit Vim if file is already written/saved
q!                      → Force Exit
wq!                   → Save current file and exit
wq file_name    → Save to File and exit
wq! file_name   → Save to File and Force exit.

To quit in Command mode :

ZZ           → Save file and exit
ZQ           → Same as q!

Navigation :

Its easier to navigate in a text file using Vim , Infect it is similar to any other editor you can use arrow keys to move right,down,up,left.
Vim uses another set of commands for navigation in Command or Normal mode :

h             → left
j               → down
k               → up
l                → right

Tip to Remember the sequence :
                     
                                                       k
                                               h
                                                      j       l

Deleting Charecters and Lines:

In Command mode use following keys for deletion purpose:

x           → delete one character
dd          → deletes a whole line
ndd         → will delete n number of lines in forward direction
dw        → deletes the current word under the cursor
db         → deletes the word before the cursor
D           → deletes every thing from the cursor to the end of the line

Cut,Copying and Pasting:

For copying and pasting use following commands in the Normal mode:

y            → copies current character
yy          → copies current line
yw          → copies current word
p             → pastes the current copied character or lines

How to Cut and Paste:

its easier whenever you delete a line,word or a character Vim stores it in a register you can paste the contents of this current register anywhere you want by just pressing P.

Repeating ,Undoing and Redoing Changes:

Use 'u' in command mode to undo any changes and Ctrl-R to redo any changes,Press '.' key to repeat the last command.

Searching and Replacing :

For searching purpose Vim provides to Operators ,One for forward search and the other for backward search. In Command-line use:

/pattern/                      → will search the pattern in forward direction starting from cursor position.

?pattern                       → will search the pattern in backward direction starting from cursor.

Replacing :

 %s/search pattern/replace pattern/    → will replace the searched pattern with the replace pattern.

Final Words :

This was  just a shorter article to make you familiarize with the Vim environment,Vim is much more then this ,To me its the most powerful text editor I have seen. Its very flexible and includes every functionality for text processing and for programming like syntax highlighting ,auto indention ,text folding ,auto completion,split widows to edit multiple files,comparing files, advanced pattern matching using perl like regular expressions and much more. Most of todays mature and professional programmers and developer are still using Vim for their tasks. I will explore above mentioned features in later posts.

4 comments:

  1. Web Design and Web Development services that will increase your visibility. My IT Guy offer services as a complete or separate package. We have Web Design and Web Development solutions for all businesses and organizations. Real estate Agents/Brokers, E-Commerce, Doctors, Lawyers, Construction Companies, Musicians, Politicians and many more. Consult with us for free today.

    ReplyDelete
    Replies

    1. windows 7 activation key , valid key for microsoft office professional plus 2007 , office 2016 pro plus key , office 2013 genuine key , get windows 7 starter home basic original serial key , windows upgrade anytime key from starter to home basic , window 7 ultimate product key , windows 7 ulitimate product key , lnqQko

      office project 2013 keys

      windows 7 ultimate sp1

      windows 10 pro key

      windows 10 pro key free

      Delete

  2. Sell your home
    Real Estate Solutions

    OG Property Solutions is here in Bakersfield to help homeowners out of any kind of distressed situation. As investors, we are in business to make a modest profit on any deal; however we can help homeowners out of just about any situation, no matter what! There are no fees, up-front costs, commissions, or anything else. Just the simple honest truth about your home and how we can help you sell it fast to resolve any situation.

    You may hear from others, the news, or even real estate agents, that investors are all out to screw over the home owner, but this simply isn’t true. OG Property Solutions is part of a nationwide group of thousands of investors who are helping tens of thousands of homeowners every year. We may not be the “traditional” route, but the reason many bad mouth investors is because we CAN help and we can do it quickly, which they don’t want YOU to know about!

    I am Randy of OG Property Solutions. I live with my wife, daughter and two grandsons. I was in management for 9 years in Bakersfield and I am now happy to be in real estate investments, something I wanted to do years ago. I now have a team put together to help create a solution to help you resolve any situation.

    Give us a call today at 661-615-3314 to let us know what YOU need help with!

    ReplyDelete
  3. Hi Dear,

    i Like Your Blog Very Much..I see Daily Your Blog ,is A Very Usefull For me.

    You Can see = Professional Moving Service Bakersfield
    We offer the best seo service, web design & marketing strategy company in Victoria Canada. Cadencecreativestudio will work with you to realize your goals.
    Visit Now - Professional Moving Service Bakersfield

    ReplyDelete

Follow me

Join me on the New Digg Follow ur_sunny on Twitter

Translate

Labels

Followers