Difference between revisions of "Vi Short Command Reference"
m |
m (Protected "Vi Short Command Reference" [edit=sysop:move=sysop]) |
||
(4 intermediate revisions by one user not shown) | |||
Line 44: | Line 44: | ||
|} | |} | ||
+ | | ||
+ | === Navigation and movement === | ||
+ | |||
+ | {| width="525" border="01" cellpadding="2" | ||
+ | | width="150" | - | ||
+ | | go to beginning of previous line | ||
+ | |- | ||
+ | | 0 (zero) or ^ | ||
+ | | go to beginning of this line | ||
+ | |- | ||
+ | | $ | ||
+ | | go to end of this line | ||
+ | |- | ||
+ | | ret or + | ||
+ | | = go to beginning of next line (NOT THE SAME AS INPUT RETURN) | ||
+ | |- | ||
+ | | w | ||
+ | | go to beginning of next word | ||
+ | |- | ||
+ | | b | ||
+ | | go to beginning of this word | ||
+ | |- | ||
+ | | e | ||
+ | | go to end of this word | ||
+ | |- | ||
+ | | sft-h | ||
+ | | go to first line onscreen | ||
+ | |- | ||
+ | | sft-l | ||
+ | | go to last line onscreen | ||
+ | |- | ||
+ | | ctrl-f | ||
+ | | forward (down) one screen | ||
+ | |- | ||
+ | | ctrl-b | ||
+ | | backward (up) one screen | ||
+ | |- | ||
+ | | 1,sft-g | ||
+ | | top of the buffer | ||
+ | |- | ||
+ | | sft-g | ||
+ | | bottom of the buffer (i.e. EOF) | ||
+ | |- | ||
+ | | line,sft-g | ||
+ | | go to line (e.g. 3,5,sft-g = line 35) | ||
+ | |- | ||
+ | | column,| | ||
+ | | go to column (e.g. 4,| = column 4) | ||
+ | |- | ||
+ | | sft-J | ||
+ | | Join / bring next line up (append next line to end) | ||
+ | |} | ||
+ | |||
+ | | ||
+ | |||
+ | === Deletion === | ||
+ | deleted text is put to the general purpose buffer; use the p cmd to retrieve it you can also use yanks to not delete it but still put it in the GPB basically delete = cut and yank = copy in your OS's Edit menu | ||
+ | {| width="525" border="01" cellpadding="2" | ||
+ | | width="150" | x | ||
+ | | delete this character | ||
+ | |- | ||
+ | | d,w | ||
+ | | delete word | ||
+ | |- | ||
+ | | d,d | ||
+ | | delete line | ||
+ | |- | ||
+ | | sft-d | ||
+ | | delete to end of line (same as emacs ctrl-k) | ||
+ | |- | ||
+ | | y,w | ||
+ | | yank to beginning of next word | ||
+ | |- | ||
+ | | sft-y or y,$ | ||
+ | | yank to end of line | ||
+ | |- | ||
+ | | y,y | ||
+ | | yank entire line | ||
+ | |- | ||
+ | | buffer"lines"y,y | ||
+ | | yank lines number of lines into buffer buffer (a-z) | ||
+ | |- | ||
+ | | p | ||
+ | | paste contents of general-purpose buffer | ||
+ | |} | ||
+ | |||
+ | | ||
+ | |||
+ | === Replacement === | ||
+ | To use replacers type the sequence and then type the string of characters to replace with, e.g. 2,c,w,"Bored Zo" to replace from the cursor to the end of the next word to "Bored Zo" | ||
+ | {| width="525" border="01" cellpadding="2" | ||
+ | | r | ||
+ | | replace a single character | ||
+ | |- | ||
+ | | shift-r | ||
+ | | replace characters from the cursor(e.g. if | is the cursor and your text is "I AM the |Entertained Zo!" shift-r,"Bored" will give you "I AM the Boredtained Zo!") | ||
+ | |- | ||
+ | | c,w or c,e | ||
+ | | change from cursor to end of word | ||
+ | |- | ||
+ | | c,b | ||
+ | | change from beginning of word to before cursor | ||
+ | |- | ||
+ | | c,$ or sft-c | ||
+ | | change from cursor to end of line | ||
+ | |- | ||
+ | | c,c | ||
+ | | change the ENTIRE line | ||
+ | |- | ||
+ | | <nowiki>:x,ys/oldstring/newstring/</nowiki> | ||
+ | | substitute one occurrence of newstring for oldstring from line x to line y (if y = $ then to EOF) | ||
+ | |- | ||
+ | | <nowiki>:x,ys/oldstr/newstr/g</nowiki> | ||
+ | | substitute all occurrences per line of newstring for oldstring | ||
+ | |- | ||
+ | | <nowiki>:%s/oldstr/newstr/g</nowiki> | ||
+ | | substitution from start of document to end of document all lines, all occurrences per line. | ||
+ | |- | ||
+ | | ~ | ||
+ | | toggle a character's case | ||
+ | |} | ||
+ | |||
+ | | ||
+ | |||
+ | === Searching === | ||
+ | {| width="525" border="01" cellpadding="2" | ||
+ | | width="150" | / | ||
+ | | search forward from cursor for a pattern | ||
+ | |- | ||
+ | | ? | ||
+ | | search backward from cursor for a pattern | ||
+ | |- | ||
+ | | n | ||
+ | | next result | ||
+ | |- | ||
+ | | sft-n | ||
+ | | previous result | ||
+ | |} | ||
+ | |||
+ | | ||
+ | |||
+ | === Insertion === | ||
+ | {| width="525" border="01" cellpadding="2" | ||
+ | | width="150" | o | ||
+ | | insert a blank line below this one | ||
+ | |- | ||
+ | | sft-o | ||
+ | | ...above this one | ||
+ | |- | ||
+ | | <nowiki>:r file</nowiki> | ||
+ | | insert file at cursor | ||
+ | |} | ||
+ | |||
+ | | ||
+ | |||
+ | === Customizing Vim === | ||
+ | Vim is an editor designed to work like the traditional UNIX vi. Vim extends the features of vi and supports syntax coloring. You can control vim's default behavior by creating a custom .vimrc file in your home directory (or move .exrc to .vimrc). The table below shows some common options you can include in your custom .vimrc file. You may also type these interactively within vim by preceding with a colon. | ||
+ | |||
+ | | ||
+ | |||
+ | === Vim Custom Options === | ||
+ | {| width="525" border="01" cellpadding="2" | ||
+ | | width="150" | set incsearch | ||
+ | | incremental searching | ||
+ | |- | ||
+ | | set ignorecase | ||
+ | | disregards upper and lowercase distinctions | ||
+ | |- | ||
+ | | set smartcase | ||
+ | | ignore case of search if pattern is lower-case | ||
+ | |- | ||
+ | | set scrolloff=2 | ||
+ | | two lines of context visible around cursor | ||
+ | |- | ||
+ | | set wildmode=longest,list | ||
+ | | Tab, Enter, Esc filename completion | ||
+ | |- | ||
+ | | set cindent | ||
+ | | C code indentation | ||
+ | |- | ||
+ | | set nocindent | ||
+ | | disable C code indentation | ||
+ | |- | ||
+ | | set compatible | ||
+ | | behave more like old vi | ||
+ | |- | ||
+ | | set nowrap | ||
+ | | disable line wrap for long lines | ||
+ | |- | ||
+ | | set textwidth=72 | ||
+ | | supplement to line wrap annoyance | ||
+ | |- | ||
+ | | filetype off | ||
+ | | disable file type recognition and behavior | ||
+ | |- | ||
+ | | set uc=0 | ||
+ | | No swap file will be used | ||
+ | |- | ||
+ | | set number | ||
+ | | display line numbers in editor | ||
+ | |- | ||
+ | | set nonumber | ||
+ | | disable display line numbers in editor | ||
+ | |} | ||
+ | |||
+ | | ||
+ | |||
+ | === Vim command line history === | ||
+ | (Thu Nov 10 18:12:47 CST 2005) The command-lines that you enter are remembered in a history table. You can recall them with the up and down cursor keys. Example, .viminfo in the user profile. When this doesn't work you might see :<Up> appear in the editor instead of the last command. Reason: You have invoked vim-minimal (/bin/vi) rather than vim-enhanced (/usr/bin/bim). The vim-minimal package doesn't seem to support cmd-line history. The libgpm.so.1 console mouse library is required to use vim-enhanced. Applies when: Linux OS, Linux Terminal Emulation correct, also relates to command complete <Tab>. | ||
+ | |||
+ | | ||
+ | |||
+ | === about the author === | ||
+ | Krissy is an enthusiastic member in a growing trend of linux geek girls. The females place in computer technology is not well defined and very few are exploring this realm. Krissy specializes in documentation for various linux related projects and her contributions are highly valued. Krissy has a linux related [http://www.robotz.com/~krissyj/ web site] and is a member of [http://www.lazygirl.net/ lazygirl.net]. | ||
<br /> | <br /> |
Latest revision as of 20:45, 27 June 2007
ContentsVi short command reference(Learn or review your Vi commands with this concise reference) |
Operation
i | input mode |
esc | command mode |
:se number | display line numbers |
:se nonumber | don't display line numbers |
:e | open file |
:w | save (write) file to disk |
:wq | save and quit |
:q! | quit but don't save |
number,command | apply command number times (e.g. 4,x = delete 4 characters) |
. | repeat last effective cmd |
esc,u | undo it |
ctrl-r | redo it |
- | go to beginning of previous line |
0 (zero) or ^ | go to beginning of this line |
$ | go to end of this line |
ret or + | = go to beginning of next line (NOT THE SAME AS INPUT RETURN) |
w | go to beginning of next word |
b | go to beginning of this word |
e | go to end of this word |
sft-h | go to first line onscreen |
sft-l | go to last line onscreen |
ctrl-f | forward (down) one screen |
ctrl-b | backward (up) one screen |
1,sft-g | top of the buffer |
sft-g | bottom of the buffer (i.e. EOF) |
line,sft-g | go to line (e.g. 3,5,sft-g = line 35) |
= column 4) | |
sft-J | Join / bring next line up (append next line to end) |
Deletion
deleted text is put to the general purpose buffer; use the p cmd to retrieve it you can also use yanks to not delete it but still put it in the GPB basically delete = cut and yank = copy in your OS's Edit menu
x | delete this character |
d,w | delete word |
d,d | delete line |
sft-d | delete to end of line (same as emacs ctrl-k) |
y,w | yank to beginning of next word |
sft-y or y,$ | yank to end of line |
y,y | yank entire line |
buffer"lines"y,y | yank lines number of lines into buffer buffer (a-z) |
p | paste contents of general-purpose buffer |
Replacement
To use replacers type the sequence and then type the string of characters to replace with, e.g. 2,c,w,"Bored Zo" to replace from the cursor to the end of the next word to "Bored Zo"
r | replace a single character |
shift-r | is the cursor and your text is "I AM the |Entertained Zo!" shift-r,"Bored" will give you "I AM the Boredtained Zo!") |
c,w or c,e | change from cursor to end of word |
c,b | change from beginning of word to before cursor |
c,$ or sft-c | change from cursor to end of line |
c,c | change the ENTIRE line |
:x,ys/oldstring/newstring/ | substitute one occurrence of newstring for oldstring from line x to line y (if y = $ then to EOF) |
:x,ys/oldstr/newstr/g | substitute all occurrences per line of newstring for oldstring |
:%s/oldstr/newstr/g | substitution from start of document to end of document all lines, all occurrences per line. |
~ | toggle a character's case |
Searching
/ | search forward from cursor for a pattern |
? | search backward from cursor for a pattern |
n | next result |
sft-n | previous result |
Insertion
o | insert a blank line below this one |
sft-o | ...above this one |
:r file | insert file at cursor |
Customizing Vim
Vim is an editor designed to work like the traditional UNIX vi. Vim extends the features of vi and supports syntax coloring. You can control vim's default behavior by creating a custom .vimrc file in your home directory (or move .exrc to .vimrc). The table below shows some common options you can include in your custom .vimrc file. You may also type these interactively within vim by preceding with a colon.
Vim Custom Options
set incsearch | incremental searching |
set ignorecase | disregards upper and lowercase distinctions |
set smartcase | ignore case of search if pattern is lower-case |
set scrolloff=2 | two lines of context visible around cursor |
set wildmode=longest,list | Tab, Enter, Esc filename completion |
set cindent | C code indentation |
set nocindent | disable C code indentation |
set compatible | behave more like old vi |
set nowrap | disable line wrap for long lines |
set textwidth=72 | supplement to line wrap annoyance |
filetype off | disable file type recognition and behavior |
set uc=0 | No swap file will be used |
set number | display line numbers in editor |
set nonumber | disable display line numbers in editor |
Vim command line history
(Thu Nov 10 18:12:47 CST 2005) The command-lines that you enter are remembered in a history table. You can recall them with the up and down cursor keys. Example, .viminfo in the user profile. When this doesn't work you might see :<Up> appear in the editor instead of the last command. Reason: You have invoked vim-minimal (/bin/vi) rather than vim-enhanced (/usr/bin/bim). The vim-minimal package doesn't seem to support cmd-line history. The libgpm.so.1 console mouse library is required to use vim-enhanced. Applies when: Linux OS, Linux Terminal Emulation correct, also relates to command complete <Tab>.
about the author
Krissy is an enthusiastic member in a growing trend of linux geek girls. The females place in computer technology is not well defined and very few are exploring this realm. Krissy specializes in documentation for various linux related projects and her contributions are highly valued. Krissy has a linux related web site and is a member of lazygirl.net.
Robotz.com Developer's Project
developer@robotz.com