Greg Hinkel's UNIX Tip of the Week for June 9, 1996

Using vi more efficiently

Here's a few ideas that may help you navigate in "vi" more quickly.

In Command Mode

     	Movement
     	Commands	Action
     	----------------------
	  w		move ahead one word (or group of punctuation marks)
	  W		move ahead one word, skipping punctuation
	  b		move back one word (or group of punctuation marks)
	  B  		move back one word, skipping punctuation
	  e		move ahead to the end of the word (or punct. marks)
	  E   		move ahead to the end of the word, skipping punctuation

	  )     	move to next sentence
	  (  		move to previous sentence
	  }		move to next paragraph
	  {		move to previous paragraph

	  G		move to last line in file.  Preceed "G" with a number
			and move to that line number.  10G moves to line number
			10.
	  ^f		(Control-f) scroll forward one screen
	  ^b		(Control-b) scroll backward one screen
	  ^d		(Control-d) scroll forward one-half screen
	  ^u		(Control-u) scroll backward one-half screen

	  Note:  All of these commands can be preceeded by a count, i.e.,
		  4w moves ahead 4 words
		  2{ moves ahead 2 paragraphs
		  8^f jumps ahead 8 screens of text


        Search
        Commands	Action
        ----------------------
	  /pattern	Search forward for pattern
	  ?pattern	Search backward for pattern
	  n		Repeat last search in same direction
	  N		Repeat last search in opposite direction


	Insert
	Command		Action
	----------------------
	  i		insert text before cursor
	  a 		append text after cursor
	  o		open a new line below the current line
	  I		Insert text at beginning of line
	  A		Append text at end of line
	  O		Open a line above the current line

	Note:  Press the escape key (Esc) to get out of "insert mode"


	Delete
	Command		Action
	----------------------
	  x		delete character under cursor
	  dw		delete from current cursor position to end of word
	  D		delete from current cursor position to end of line
	  dd		delete the current line

	Note:  All of these commands can be preceeded by a count, i.e.,
		4x deletes 4 characters from the current cursor position
		14dw deltes 14 words from the current position
		36dd deletes 36 lines from the current position

	Change or
	Replace		Action
	----------------------
	  r		replace character under cursor (no Esc)
	  cw		replace current word beginning at current position.
			6cw changes the next 6 words.
	  s		replace current character with any number of characters
	  R		replace many characters beginning at current position
	  S		replace the entire line
	  C		replace from current position to end of line
	  
	Note:  Press the escape key (Esc) to get out of "insert mode" for all
	       of these except for the "r" command.


	Next tip will be some "advanced" vi commands.

Previous Tip of the Week · Next Tip of the Week · Index

Greg's Home Page


Greg Hinkel / (hinkelgc AT ornl.gov)
Last Modified: Friday, 02-Sep-2005 12:53:23 EDT
Visitors: 5377 since March 18, 1996