HomePage » GeneralUnix » vi
VI editor
To show line numbers in VI, do a :set number. Alternatively, put the following in ~/.exrc.exrc
set number
VI block commenting
1. Go to the first line you want commented, and hit V.2. Use your favorite method to reach the last line of the block.
3. Type:
:s/^/# /
VI commands
VI Commands: i insert mode, (ESC to exit insert mode) allows text to be entered on the screen a Append to right mode /word Move to the occurrence of "word" n Locate the next occurance w Advance to the next word e Advance to the next end of a word b Move to the previous word 3b Move backward 3 words dd delete line 3dd delete 3 lines D Delete remainder of a line dw Delete word x Delete character o Open space for new line below the cursor line O Open a line above the cursor CTRL-w Move back a word in append mode u Undo last U Undo all changes to current line . In command mode, repeat the last text changing the command on the current line :w newfilename save the file to newfilename from the command mode :wq save and quit :q! quit without saving r replace then typa a character ot be replaced with r then return to break up a line J join 2 lines s substitute (sentence) typed text over a character, ESC when done cw change word c change part of a line from the cursor to the end of the line cc substitute new text for aline, ESC when done h move the cursor back one space H move the cursor to the highest line on the screen L move the cursor to the lowest line on the screen M position the cursor at the midpoint on the screen G last line in the file 0 (zero) Move the cursor to the beginning of the line it is on view filename Open a file for viewing only set number Turn on line numbers set nonumber Turn off line numbers Options: number autoindent (ai) ctrl-d to move to the left showmatch match brackets and parenthesis tabstop=4 wrapmargine(wm) when line is wrapped (80-value) :2 copy 4 Place a copy of line 2 after line 4. :1,4 copy 7 (lines 1-4) :n Access the next file for editing
Turn off vi auto-indent madless
set nocindent set nosmartindent set noautoindent filetype indent off filetype plugin indent off
There are no comments on this page. [Add comment]