Sunday, June 5, 2011

Understanding VIM : [Viewpoints] Tutorial-4

Using viewpoints & tabs (introduced in vim 7), we can edit more than one file at a time. This is useful when you are connected with a remote machine & you prefer to open only one session. It's also useful when we want to edit a long file at different lines.
Viewpoints breaks the vim editor into two or more segments, either vertically or horizontally. Open a vi editor & then go to last line command, enter :split. You can now see two views of the same file.

In case, you want to open another file in a new viewpoint, you can do it by :sp [filename], if you don't provide any filename, then the editor will open the same file in another viewpoint, so now you have 3 viewpoints. You may want a new empty viewpoint for doing some rough work & then adding it  in original file, try :new. At this stage if you want to go back to 2 viewpoints just do :q & you are back.  Now, try editing different parts of the same file, press Ctrl-w to switch in between different viewpoint, you can run Ctrl-w k to move to the upper viewport, and Ctrl-w j to move down.
If, instead of moving between viewports, you want to move the viewports, you can use Ctrl-w r and Ctrl-w R to rotate windows clockwise and counter-clockwise, respectively.
If you want to return to a single view, you can close the view by quitting the file normally (:q) or by running Ctrl-w c in the viewport you want to close. You'll be prompted to save the file first.
Quick review.

  • :split or Ctrl-w s will split the Vim view into two viewports, horizontally.
  • :vsplit or Ctrl-w v will split the Vim view into two viewports, vertically.
  • :split filename will split the Vim view into two viewports, horizontally,  and open filename in the new viewport.
  • :vsplit filename will split the Vim view into two viewports, vertically, and   open filename in the new viewport.
  • :new open new empty viewpoint.
  • :sp[lit] [filename] open new viewpoint in new file.
  • :qall! quit all viewpoints.
  • Ctrl-w to rotate between views.
  • Ctrl-w k to move to upper view.
  • Ctrl-w j to move down.
  • Ctrl-w r moves viewports clockwise.
  • Ctrl-w R moves viewports counter-clockwise.    

2 comments:

  1. I think youve made some truly interesting points. Not too many people would actually think about this the way you just did. Im really impressed that theres so much about this subject thats been uncovered and you did it so well with so much class. Good one you man! Really great stuff here.
    sell house fast

    ReplyDelete
  2. These kind of articles are always attractive and I am happy to find so many good point here in the post writing is simply great thanks for sharing.
    best weight loss product

    ReplyDelete