How To pwn Your Text Files With Vim

By | 2007/05/01

Recently I did a lecture on the magical world of vim. Despite having used it for quite a long time I realize there is still far more that I could know about it, but there is also more that I haven’t published on this blog.  Some of you might remember some of my earlier posts on vim [here], [here].  Today I have a few more shortcut keys to tell you about that I sure hope you’ll appreciate as much as I have grown to.  First, some more advanced navigation.

Moving your cursor within vim can be done on per character, per sentence and per parapraph.  Also, remember that you can repeat commands (even movement commands) by prepending it with the number of times you would like it done.

To move your cursor within vim per character you can use the arrow keys or the h,j,k,l for left, down, up, right respectively.

To move your cursor within vim per sentence you can use the (, ) keys to move to the previous or next sentence respectively.

To move your cursor within vim per paragraph you can use the {, } keys to move to the previous or next paragraph respectively.

To move your cursor to a specific line within your text you can prefix the line number with : .  ie; to jump to line 10 you would use “:10”.

You can also jump to the beginning or end of the file with G or gg.

Next, now that you can jump from one end of your file to the other quickly you might want to open multiple windows within vim for, perhaps, comparison, etc.

You have the ability to split a window either vertically or horizontally within vim very simply.  To control, move or split windows you must prefix the command with ctrl-w.

ctrl-w n – create a new window representing a new, empty file

ctrl-w s – split the window horizontally

ctrl-w v – split the window vertically

ctrl-w arrow – move to the window in the direction of the arrow

ctrl-w q – quit the current window (also available is the default :q, :wq)

ctrl-w – / + – increase or decrease the size of the current window.  (also available is increasing or decreasing by X value: ctrl-w 5+ – increase window size by 5.)

Adding these commands to the commands that you already know and now you’re getting efficient with vim.  The only editor you’ll ever need!  …but, like I said, this still isn’t everything.  Not by a long-shot, but it’s a really good start!

7 thoughts on “How To pwn Your Text Files With Vim

  1. Pingback: it’s about time» Blog Archive » links for 2007-05-01

  2. Sander Dijkhuis

    Thanks for the overview! Another cool function is tabbing like in Firefox. Use the :tabedit command to open a new tab, and switch tabs with gt. Especially useful when your terminal emulator doesn’t support tabbing or when you need to copy text from one to another file. The tab bar supports the mouse when you’ve enabled it (set mouse=a).

  3. Pingback: Vim Tip of The Week : +[num] or +/{pat} : Ubuntu Tutorials : Breezy - Dapper - Edgy - Feisty

  4. anon

    Not sure about :tabedit — cannot seem to get it to work. Version requirements?

  5. Ubuntu Tutorials

    vim-full or vim-common might be requirements for that option. I have the full vim set installed on my machine, so I take for granted some of the dependencies I suppose.

  6. luismanolo

    Sorry about my english
    I have a problem
    When I’m editing an ftp file like:
    vim ftp://[email protected]/index.html. and I do :Explore for exploring the ftp directory. The server send me an error:

    “ftp://[email protected]/” –No lines in buffer–
    “ftp://[email protected]/” –No lines in buffer–
    Error detected while processing function netrw#Explore..21_NetBrowse..
    line 14:
    E121: Undefined variable: w:netrw_method
    E15: Invalid expression: w:netrw_method == 2 || w:netrw_method == 5
    Press ENTER or type command to continue

    Many Thanks

Comments are closed.