Skip to content

How To pwn Your Text Files With Vim

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!

If this site has been useful, please consider participating in the Fundraiser.

Other Points of Interest

  • No Related Post