Translate to your Language

Wednesday, December 26, 2012

Unix Vi Quick Reference

by Unknown  |  in Other at  8:16 PM



vi Notes
----------------------------------------------------------------------
Modes:
   vi
      command
      edit (ESC to goto command mode)
   ex - line editor
      : prompt
      :vi  (to goto visual mode)
----------------------------------------------------------------------
vi Commands:
   a - append after cursor
   A - append after end of line
   c - change needs scope (ex: 3cw would change the next 3 small words)
   cc - change line
   C - change from cursor to end of line
   d - delete scope (ex. 5dW would delete next 5 big words)
   dd - deletes line
   D - deletes to end of line
   i - insert after cursor
   I - insert at begining of line (not counting whitespace)
   o - opens new line after cursor
   O - opens new line before cursor
   p - "put" or paste after cursor from cut & paste buffer
   "3p - paste from 3 edit
   P - pastes before cursor
   r - replace current char
   R - replace till ESC pressed
   s - substitute till ESC pressed
   u - undo
   U - undo all changes on this line
   x - delete 1 char
   yy - "yank yank" or copy current line into cut & paste buffer
   ZZ - save and quit
   . - repeat last change
   >> - indent 1 shiftwidth
   << - outdent 1 shiftwidth
   ^V - in edit mode will insert control codes
   /regexpression - finds regular expression
   ?regexpression - finds regular expression towards top of file
----------------------------------------------------------------------
Regular expressions: (wild cards)
   ^ - begining of a line not counting whitespace
   0 - goto first char on line
   $ - end of a line
   \ - gets rid of magic
   \$ - matches a dollar sign
   . - matches any char
   [4-7] - matches numbers 4 thru 7
   [A-Z] - matches A thru Z
   [j-r] - matches j thru r
   * - zero or more of preceding expression
   ^[A-Z][0-9][0-9]* - would match a cap letter 1 number at begining of line
----------------------------------------------------------------------

----------------------------------------------------------------------
vi Movement:
   ^ - begining of line
   $ - end of line
   b - back 1 small word
   B - back 1 big word
   e - end of small word
   E - end of big word
   G - goto end of file
   2G - goes to line 2
   h - moves to left
   j - moves down 1 line
   l - moves 1 char to right
   k - moves up 1 line
   w - move 1 small word
   W - move 1 big word
----------------------------------------------------------------------
vi Scope:
   w,W,b,B, etc
----------------------------------------------------------------------
vi Notes:
   most commands can be preceeded by a number for multiple occurances
      (example 3dd - would delete the next 3 lines)
   small word is defined by whitespace
   whitespace is tabs, spaces.
   big word is defined by any puncuation (){}[],.!?\|:;'"<>-_@#$%^&*
----------------------------------------------------------------------

----------------------------------------------------------------------
ex commands:
   g - global finds regular expressions
   map  - map control codes or function keys to macros
   q - quit
   r - reads in file
   s - substitute
   so - execute macro file
   set - set options
   w - write
----------------------------------------------------------------------
ex Examples:
   :7 - goes to line 7
   :4,6d - deletes lines 4 thru 6
   :r file - reads file into current doc after current line
   :r !command - reads results of UNIX command into doc
   :r !date - would read in date command
   :4,9!command - pipes lines 4 thru 9 to UNIX command
   :%!sort - would sort all lines
   :3,8!sort - would sort lines 3 thru 8
   :%g/^print/d - would delete all lines that start with print
   :%s/ouput/output/g - would change ouput to output on all lines
   :set nows - nowrapscan set searches not wrap around to begining of file
   :set ic - ignore case on searches
   :set nonu - no line numbers
   :set all - to see all the options
   :map #1 1G - map function key 1 to goto line 1
   :map #2 G - map function key 2 to goto last line
   :map #3 :set ts=40^M - map f3 to set tabstops to 40 chars
   :map #4 :set sw=3^M - map f4 to set shiftwidth to 3 chars
   :map #5 :set ai^M - map f5 to autoindent
   :map #6 :%s/^I/   /g^M - map f6 to change control-i to 3 spaces
   :map ^O :%s/display/print/g^M - map ^O to change display to print
----------------------------------------------------------------------
Saving and Quiting:
   :q! - force a quit even on a modified file
   :wq - write and quit
   :wq! - force a write then quit (can not do if permissions wrong)
   :w newfilename
   :q - quit
----------------------------------------------------------------------
ex Scope:
   . - current line
   $ - last line
   5,7 - lines 5 thru 7
   1,$ - all lines
   % - all lines
   .,$ - current line to end of file
----------------------------------------------------------------------
ex Notes:
   most commands require scope
   scope are the lines to issue command on
----------------------------------------------------------------------



0 comments:

© Copyright © 2015Big Data - DW & BI. by