Use VI Functions in the Command Line

Last updated: Dec 12, 2007

If you are not familiar with the awesomeness of VI(m) check out this post, Making GVim your Default Text Editor in Gnome.

For those of you that already know that VI can save you time and give you a +10 on the geek scale, I have a tip for you.

You can use those same commands that you love in VI on your command line.

Setting up VI on your Command Line

To setup your VI commands on the command line simply type this at your command prompt, set -o vi then hit enter.

Thats it…

Now you can use VI commands in your terminal. For instance do delete the line type ‘dd’. to delete to the end of the line type ’d$‘. There are shortcuts for the command line without using VI but I find it easier to learn one set of commands and use them for everything.

Here is a list of of commonly used VI commands:

VI Commands

  • esc return to command mode; used by most change commands

  • h, j, k, l move the cursor around. h=left, j=down, k=up, l=right

  • ^F move forward full screen

  • ^B move back full screen

  • ^U move up half screen

  • ^D move down half screen

  • ^L clear and redraw screen (^R)

  • w move forward to beginning of next word

  • W move forward to beginning of next word after space

  • e move cursor to end of word

  • E move cursor to next space

  • $ move cursor to end of line (3$ moves to end of third line)

  • b move cursor to beginning of word

  • B move cursor to previous space

  • 0 (zero) move cursor to beginning of line

  • K invokes the man page for the word under the cursor (may only work in VI-improved which is available for most operating systems, including MS windows).

  • [[ goto beginning of section (use (, { or

  • ]] reverse of [[

  • G go to indicated line # (enter number first)

  • / search (enter string after / at bottom of screen)

  • n find next search instance

  • N reverse of n

  • % find matching (, ), [, ], {, or }

  • i insert text from current cursor position;

  • I insert text at start of line;

  • o opens a new line below cursor

  • O opens a new line above cursor

  • J joins next line to end of current line

  • r replace character under cursor

  • R enters replace (typeover) mode;

  • s substitute character under cursor with one or many;

  • S substitute whole line;

  • a appends after cursor;

  • A appends after current line;

  • cw change current word starting at cursor;

  • C change to end of line;

  • dw delete current word starting at cursor

  • dd delete current line; delete 3 lines (3dd)

  • D delete to end of line

  • yy yank data: yank 1 line (yy), yank 3 lines (3yy), yank lines below the cursor (yy) or above the cursor (yk), words (yw), from thecursor position to the end of the line (y$) or the beginning of the line(y0), characters to the right of the cursor (yl) or to the left (yh)

  • p put data yanked with y

  • u undo most recent change

  • . repeat most recent change-producing command

Need to print shipping labels on your site?

Checkout my product RocketShipIt for simple easy-to-use developer tools for UPS™ FedEx™ USPS™ and more.

Get notified on new posts or other things I'm working on

Share: