Learning Vim(2)

I can’t help myself learning Vim today. I found much fun and more magic hidden in it!
1. Enable mouse
:set mouse=a
2. tab pages
Yeah, vim have tab navigation! You can open a tab by :tabedit to open a empty file in a new tab or :tab split to open the current page in a new tab. If you have mouse enabled(see above), you can navigate among tabs with mouse just like under windows. double-click on the empty space will open a new tab and clicking the "X" on the right-most corner will close the current tab. With keyboard, :gt and :gT will go tab previous and next. Use :tabpage for more
3. Completion
In command-line, use the <Tab> key and <Ctrl-D> to complete commands. In insert mode, you can use <Ctrl-P> and <Ctrl-N> to complete your input. More in usr_24.txt. You can type :help and search the text "usr_24.txt" to get in.(But is there better way to go there in command-line?).
4. manage your window
:split and :vsplit will split your current window in two horizonally and vertically. You can move your cursor among these windows with <Ctrl-W> hjkl to move left, down, up and right.
And if you feel boring with so many windows, use <Ctrl-W><Ctrl-W> to move your cursor in the window you want to keep and press <Ctrl-W> O to close all other windows!
5. fold
I’m not quite familiar with this magic but it’s kind of very useful. In visual mode, selecting several lines and type :zf to fold these lines and :zd to delete the fold(Note: not the text). You can also just :zo to open it and after viewing :zc to close it.

To be continued…

Best,
Sha Liu

Advertisements

11 Responses to “Learning Vim(2)”

  1. Albert Says:

    Keep the tips coming! Vim is a little bit like Othello, an hour to learn (instead of a minute), a lifetime to master.

  2. Albert Says:

    Also, FWIW, I use folding all the time in jEdit, mainly to hide the licensing and copyright headers in source files.

  3. James Says:

    I’d suggest getting used to switching among buffers before fiddling with tab pages. Vim’s buffers already provide the ability to switch among various files (especially once you’ve “set hidden”). Tab pages are designed more as different workspaces.

    The windows-intro and tab-page-intro help topics should help clarify the different use cases for buffers (which are the base unit you’re always working with), windows, and tab pages.

    You can easily switch among buffers with , which by itself toggles between your current buffer and the previous one you were viewing. Typing a number before pressing will switch to that buffer number. There’s also the :b command which accepts partial file names (to select the buffer matching that file name) or the buffer number. Use tab completion to your advantage: “:b” will help select the buffer.

  4. James Says:

    Gar, wordpress ate part of my comment. The first sentence of the 3rd paragraph should be:

    You can easily switch among buffers with ctrl-6, …

  5. Byron Says:

    :he usr_24.txt

  6. Tomaž Says:

    I find :set mouse=a more trouble than it’s worth because it disables middle-click pasting in the terminal.

    Or am I missing something?

    • dominiko Says:

      > find :set mouse=a more trouble than it’s
      > worth because it disables middle-click
      > pasting in the terminal.

      You can still copy/paste if you press shift
      while selecting with the mouse.

      But I find “:set mouse=a” causing troubles
      too when clicking in the window to give it
      focus, it changes the position of the cursor.
      So I’ve settled for the less intrusive setting:

      if has(‘mouse’) | set mouse=vic | endif

      Full .vimrc at http://dominique.pelle.free.fr/.vimrc.html

  7. deifl Says:

    @Tomaž: Pasting into the terminal can be also accomplished with Shift-Ins

  8. James Says:

    The benefit to having the ‘mouse’ option set is that Vim will recognize when you’re pasting so you won’t end up with the “stair case” effect. Without having that set, you need to make use of the ‘paste’ option (made easier by using setting a key for ‘pastetoggle’) — set it, paste, then unset it.

  9. evolelick Says:

    Looks like you are a real specialist. Did you study about the topic? lol

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: