(M)  s i s t e m a   o p e r a c i o n a l   m a g n u x   l i n u x ~/ · documentação · suporte · sobre

  Next Previous Contents

10. Vim Reference Card

10.1 Vi states

Vi has 3 modes:

  1. command mode - Normal and initial state; others return here (use ESC to abort a partially typed command)
  2. input mode - entered by specific commands a i A I o O c C s S R and ended by ESC or abnormally with interrupt
  3. line mode - i.e. waiting for input after a : , / , ? or a ! command (end with CR, abort with CTRL-c). CTRL is the control key: CTRL-c means "control c"

10.2 Shell Commands

  1. TERM= code Puts a code name for your terminal into the variable TERM
  2. export TERM Conveys the value of TERM (the terminal code) to any UNIX system program that is terminal dependant.
  3. tput init Initializes the terminal so that it will function properly with various UNIX system programs.
  4. vi filename Accesses the vi screen editor so that you can edit a specified file.
  5. vi file1 file2 file3 Enters three files into the vi buffer to be edited. Those files are file1, file2, and file3.
  6. view file Invoke vi editor on file in read-only mode
  7. vi -R file Invoke vi editor on file in read-only mode
  8. vi -r file Recover file and recent edits after system crash
  9. vi -r file Recover file and recent edits after system crash

10.3 Setting Options

  1. :set option Activate option
  2. :set option=value Assign value to option
  3. :set no option Deactivate option
  4. :set Display options set by user
  5. :set all Display list of all current options, both default and those set by the user
  6. :set option? Display values of option

10.4 Notations used

Notations:

  1. CTRL-c CTRL is the control key: CTRL-c means "control c"
  2. CR is Carriage return (ENTER key)

10.5 Interrupting, cancelling

  • ESC end insert or incomplete command
  • CTRL-? CTRL is the control key: CTRL-? means "control ?" delete or rubout interrupts
  • CTRL-l reprint/refresh screen if CTRL-? scrambles it

10.6 File Manipulation

  • ZZ Save the file and exit vi
  • :wq Save the file and exit vi
  • :w Write the current file
  • :w! Force write the current file, if file is read-only
  • :wname Write to file name
  • :q Exit from vi
  • :q! Force exit from vi (discarding changes)
  • :e name Edit file name
  • :e! reedit, discard changes
  • :e + name edit file name, starting at end
  • :e + n edit starting at line n
  • :e # edit alternate file
  • :n edit next file in arglist
  • :args list files in current filelist
  • :rew rewind current filelist and edit first file
  • :n args specify new arglist
  • :f show current file and line
  • CTRL-G synonym for :f , show current file and line
  • :ta tag to tag file entry tag
  • CTRL-] :ta, following word is tag

10.7 Movement

  • Arrows Move the cursor
  • CTRL-d Scroll half page down
  • CTRL-u Scroll half page up
  • CTRL-f Scroll a full page down
  • CTRL-b Scroll a full page up
  • :0 Move to start of file
  • :n Move to line number n
  • :$ Move to end of file
  • 0 Move to start of line
  • ^ Move to first non-blank character
  • $ Move to end of line
  • CR Move to the start of next line
  • - Move to the start of previous line
  • % Find matching bracket
  • G goto line (last line default)
  • ]] next section/function
  • [[ previous section/function

10.8 Line Positioning

  • H Home window line
  • L Last window line
  • M Middle window line
  • + Next line, at first non-white
  • - Previous line, at first non-white
  • CR return, same as +
  • j next line, same column
  • k previous line, same column

10.9 Character positioning

  • 0 beginning of line
  • $ end of line
  • h forward
  • l backwards
  • SPACE same as l
  • fx find x forward
  • Fx find x backward
  • ; repeat last f F
  • , inverse of ;
  • | to specified column
  • % find matching { or }

10.10 Words, sentences, paragraphs

  • w Word forward
  • b Word backward
  • e End of word
  • ) To next sentence
  • ( Back sentence
  • } To next paragraph
  • { Back paragraph
  • W Blank delimited word
  • B Back W
  • E To end of W

10.11 Marking and returning

  • `` (press twice the back-quote ` key) Previous context
  • '' (press twice the single-quote ` key) Previous context at first non-white in line
  • mx mark position with letter x
  • `x (back quote key and letter x) goto mark x
  • 'x goto mark x at first non-white in line

10.12 Corrections during insert

  • CTRL-h Erase last character
  • CTRL-w Erase last word
  • erase Press DELETE key, same as CTRL-h
  • kill Your kill key, erase input this line
  • \ Escapes CTRL-h, DELETE and kill
  • ESC Ends insertion, back to command
  • CTRL-? Interrupt, terminates insert
  • CTRL-d Backtab over autoindent
  • CTRL-v Quote non-printing character

10.13 Adjusting the screen

  • CTRL-l Clear and redraw
  • CTRL-r retype, eliminate @lines
  • z-CR redraw, current line at window top
  • z- redraw, current line at window bottom
  • z. redraw, current line at window center
  • /pat/z- pat line bottom
  • tn Use n line window
  • CTRL-e Scroll window down 1 line
  • CTRL-y Scroll window up 1 line

10.14 Delete

  • x Delete the character under the cursor
  • X Delete the charater before the cursor
  • D Delete to the end of line
  • d^ Delete back to start of line
  • dd Delete the current line
  • ndd Delete n lines starting with the current one
  • dnw Delete n words starting from cursor

10.15 Insert, change

  • i Enter input mode inserting before the cursor
  • I Enter input mode inserting before the first non-blank character
  • a Enter input mode inserting after the cursor
  • A Enter input mode inserting after the end of the line
  • o Open a new line below current line and enter input mode
  • O Open a new line above current line and enter input mode
  • r Replace the character under the cursor (does NOT enter input mode)
  • R Enter input mode replacing characters
  • C shift-c. Change rest of line
  • D shift-d. Delete rest of line
  • s Substitute chars
  • S Substitute lines
  • J Join lines
  • J Join lines

10.16 Copy and Paste

The "yank buffer" is filled by EVERY delete command, or explicitely by Y and yy.

  • Y Copy the current line to the yank buffer
  • nyy Copy n lines starting from the current to the yank buffer
  • p Paste the yank buffer after the cursor (or below the current line)
  • P Paste the yank buffer before the cursor (or above the current line)
  • "xp Put from buffer x
  • "xy Yank to buffer x
  • "xd Delete into buffer x

10.17 Operators (use double to affect lines)

  • d delete
  • c change
  • < left shift
  • > right shift
  • ! filter through command
  • = indent for LISP
  • y yank text to buffer

10.18 Search and replace

  • /text Search forward for text
  • ?text Search backward for text
  • n Repeat the last search in the same direction
  • N Repeat the last search in the reverse direction
  • / Repeat the last search forward
  • ? Repeat the last search backward
  • [ addr ] s/from/to/ [ g ] Search for the occurence of from and replace it with to in the current line, or in the range addr (two line numbers seperated by command; 1,$ is the whole file). Replaces one occurrence per line, or all occurrences if g is specified. For example, :3,20s/someword/anotherword/g Will replace "someword" with "anotherword" starting from line 3 to line 20. 'g' is global means replace all occurrences of "someword".

10.19 General

  • :sh Forks a shell (to be exited with CTRL-d)
  • :!command Forks a shell to execute command
  • :set number Switch on line numbering
  • :set nonumber Switch off line numbering

10.20 Line Editor Commands

  • : Tells vi that the next commands you issue will be line editor commands.
  • :sh Temporarily returns to the shell to perform some shell commands without leaving vi.
  • CTRL-d Escapes the temporary return to the shell and returns to vi so you can edit the current window.
  • :n Goes to the nth line of the buffer.
  • :x,zw filename Writes lines from the numbers x through the number z into a new file called filename.
  • :$ Moves the cursor to the beginning of the last line in the buffer.
  • :.,$d Deletes all the lines from the current line to the last line
  • :r filename Inserts the contents of the file filename under the current line of the buffer.
  • :s/text/new_text/ Replaces the first instance of text on the current line with new_text
  • :s/text/new_text/g Replaces the every occurrence of text on the current line with new_text
  • :g/text/s//new_text/g Changes every occurrence of text on the buffer to new_text.

10.21 Other commands

  • u Undo the last change
  • U Restore the current line
  • ~ Change case
  • J Join the currentline with the next line
  • . Repeat last text changing command
  • CTRL-g Show file name and line number

Next Previous Contents