- VI Options
- VI Moving around
- VI Basic Editing
- VI Pattern Matching
- Ex Commands
- Some Cool Things
1. VI options
A VI editor is a screen editor (Secretly married to another editor Ex, Both these editors are virtually indistinguishable, Ex is a line editor though, just for information, I wont dig too much details though, i want to keep this material short and smart).
A VI editor can be invoked in following ways:
Open an existing file to edit or create a new file
vi filenameOpen an existing file to edit at the last line
vi + filenameOpen an existing file to edit at the nth line
vi +n filenameOpen an existing file to edit at the pattern
vi +/pattern filename2. VI Moving Around
Its quite hard to categorize VI commands as one always needs to come before the other, But i will still try and stick to the categories, whenever you need something jump to appropriate section and look up for a command, if you think there something missing here, feel free to add it in here.
To move to the COMMAND mode:
esc
ARROW Keys:move left
hmove down
jmove up
kmove right
l
Move by WORD:
Move to the start of next wordwMove to the start of previous word
bMove to the start of nth word forward from current cursor position
nwMove to the start of nth word backword from current cursor position
nb
Move by SENTENCE:
Move to the start of next sentence)Move to the start of previous sentence
(Move to the start of nth sentence forward from current cursor position
n)Move to the start of nth sentence backword from current cursor position
n(
Move by PARAGRAPH:
Move to the start of next paragraph}Move to the start of previous sentence
{Move to the start of nth sentence forward from current cursor position
n}Move to the start of nth sentence backword from current cursor position
n{
MORE Ways:
Move to the beginning of the line:0Move to the End of the line:
$Move to the first non-white space charecter in the line:
^Move the cursor to the top of the screen:
HMove the cursor to middle for the screen:
MMove the cursor to the End of the Screen:
LGo to the bottom of the page:
ctrl - GSCROLLING:
Scrolling back one window (Remember B for back):Ctrl - BScrolling back half window (Remember U for up):
Ctrl - UScrolling forward one window (Remember F for forward):
Ctrl - FScrolling back half window (Remember D for down):
Ctrl - D
3. VI Basic EditingVI comes with a rich set of commands for editing, indenting, altering, creating files, I might have left out a lot of commands from here, especially ones from VIM (VI improved), honestly this is so because my experience is mostly on VI and not on VIM, so if anyone wants to add to this list, feel free to do so.
Basic stuff:
Insert text under the current cursor position:
iInsert text into the beginning of the current line:
IAppend text after the current cursor position:
aAppend text at the end of the current line:
AOpen a new line under the current line:
oOpen a new line above the current line:
O
Cut, Copy and Paste:Yank the whole line:
yyYank a word:
ywYank n lines:
nyyYank n words:
nywDelete the charecter under the cursor, store in in the general buffer:
xDelete n charecters under the cursor:
nxDelete a whole line and store it in general buffer:
ddDelete n lines:
nddDelete words:
dwDelete n words:
ndwDelete from the current cursor position to the end of line:
DDelete charecter before current cursor position:
XPaste the contents of the the buffer after the current cursor position:
pPaste the contents of the buffer before the current cursor position:
P
A note on VI Buffers:VI buffers can visualised to function similar to MS Word's clipboard, understanding clipboard is a key to effective use of VI and get rid of common repetitive typing, VI has 26 buffers, great!! but what are they? They are like little memmory units where you can store chunks of your text. Look at this like, there's one buffer for each alphabet in English language so each buffer is name a,b,c,d ...so on until z.
yeah, so this would mean you can store 26 chunks of text at anytime and paste it anywhere you want, now thats some advanced stuff that the normal editors cannot handle, and one of the reason why VI is so popular, its light, fast and functional, a little weird though but totally lovable.
so if you want to store some three lines of code somewhere then go to command mode type something like this
"a2yyso this would mean 2 lines of text is stored in buffer a, in order to get it back you can simply use
"apThats simple ... huh??
So any of the following commands should work to store pieces of data in a buffer.
Store two words in the buffer b
"b2ywStore all the text from current cursor position to the end of the line in buffer c
"cDOkay thats it about VI buffers, if you wanna add something here, feel free to add it and if you have any questions or need more clarity then ask me to add that information in here.
4. Ex Commands
The following are Ex commands that you may use in VI Editor
Quit VI
:qQuit without saving
:q!Save the file:
:wSave and Quit:
:wqWrite to the filename specified:
:w filenameThe good old find and replace:
:(range)s/pattern/replace/optionsShow number of the lines:
:set nuAUto-indent the code:
:set aiNumber of lines per window:
:set wi=nTab to space:
:set tabstop=nSet as Read-Only:
:set roShow current line number:
:.=Show total number of lines:
:=Copy and paste:
:(range) co (destination)Delete:
:(range) d Substitute:
: (range) s///options (count)

1 comment:
Interesting to know.
Post a Comment