Aug
6
2010

Navigation in Vim

Vim, the more advanced form of the earlier Vi editor(found in the older versions) is one of the most powerful text editors in the Linux Platform. Slight alterations in the configuration files can be of the upmost importance and can change the whole setting of the system therefore learning the basics of navigation of this text editor is a minimal prerequisite for any Linux novice.

Everything in Linux is a file, from all the software to any hardware which makes the vim text editor a very powerful tool. Be it starting an FTP server or Samba sharing almost everything in Linux can be done with the slightest of modifications, making it compulsory for anyone and almost everyone to have a strong command over the navigation of the text editor. Here I have discussed some of the most basic and necessary problems that I have come up across while using the Vim editor.

Note that the vim editor works in 2 basic modes, the command mode and the insert mode (entered by pressing the character ‘i’). Here all the commands are executed in the command mode as the name suggests. Also the magic key for entering from the text mode to the command mode is Esc.

1. Searching for a word

  • To search for a word(e.g. boot)
/word (e.g. /boot)
  • To search for the next occurrence of the same word(i.e. suppose you want to find the next occurrence of the word boot)
*
  • To move to the previous occurrence of the same word
#
  • To move to the next word
w
  • To move to the previous word
b
  • To find a word from the end of the document(e.g. in a file containing many ‘boot’ words finding the last ‘boot’)
?word (e.g. ?boot)

2. To move to the bottom of the page: G or GG in some cases

3. To move to the top of the page: gg

4. Altering words using a: For instance if you want to change the      word boot to booot, then go to the last o in boot, press a and  then enter the character o.

5. Appending to the end of the line: A

6. Deleting a character under the cursor: x

7. Going to the end of the current line: $

8. Going to the beginning of the current line: 0

9. To move to a particular line number: :line number ( e.g. To go to the fifth line of the editor: :5 )

Share

Related Posts

About the Author: Raju Khanal

An IIIT student, pursing his B.Tech degree in the IT, is one of the other aspiring authors of fortystones. He is a passionate learner and a wanna-be coder. He loves Linux and always plays with it in his spare time.

10 Comments + Add Comment

  • there are lots of more we should know. they are too little…

    • thanks for the advice…will keep that in mind

  • sure did jumpstart me on linux..

  • Try this out,
    find and replace . most useful and missed out ..

    :%s/old/new/g

    all occurrences of old will be changed to new

    g – replace all occurrences in the line
    %s – all lines

    • thanks….would love many more such ideas in the articles to come :)

  • will keep that in mind next time around :)

  • gud one..keep up the good work!!!!

  • You have to see the Vim Shortcut wallpaper from my friend Ted:

    http://naleid.com/blog/2010/10/04/vim-movement-shortcuts-wallpaper/

    This is great to have on the desktop background.

    • Thankx for the wonderful share :)

  • [...] with our stone of the VIM Navigation, I have focused on the ‘find’ command in this stone. This command is an extremely handy [...]

Leave a comment

*