Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
My Basket
Teorías de la Administración £2.00
CFA Level 2 - Corporate Finance£6.25
Agency Law£1.50
Total£9.75
Or: Edit My Basket
Title: Vi editor for linux
Description: Linux vi editor - various modes of vi editor
Description: Linux vi editor - various modes of vi editor
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
UNIX - THE VI EDITOR TUTORIAL
http://www
...
com/unix/unix-vi-editor
...
com
There are many ways to edit files in Unix and for me one of the best ways is using screen-oriented
text editor vi
...
Now a days you would find an improved version of vi editor which is called VIM
...
The vi is generally considered the de facto standard in Unix editors because −
It's usually available on all the flavors of Unix system
...
It requires very few resources
...
You can use vi editor to edit an existing file or to create a new file from scratch
...
Starting the vi Editor
There are following way you can start using vi editor −
Command
Description
vi filename
Creates a new file if it already does not exist, otherwise opens existing
file
...
view filename
Opens an existing file in read only mode
...
A tilde represents an unused line
...
So now you have opened one file to start with
...
Operation Modes
While working with vi editor you would come across following two modes −
Command mode − This mode enables you to perform administrative tasks such as saving
files, executing commands, moving the cursor, cutting yanking and pasting lines or words, and
finding and replacing
...
Insert mode − This mode enables you to insert text into the file
...
The vi always starts in command mode
...
To come in
insert mode you simply type i
...
Hint − If you are not sure which mode you are in, press the Esc key twice, and then you'll be in
command mode
...
Getting Out of vi
The command to quit out of vi is :q
...
If your file has been modified in any way, the editor will warn you of this, and not let you
quit
...
This lets you exit
vi without saving any of the changes
...
You can combine the above command with
the quit command, or :wq and return
...
When you are in
command mode, type ZZ and it will do the equivalent of :wq
...
For example, if
you wanted to save the file you were working as another filename called filename2, you would
type :w filename2 and return
...
Moving within a File
To move around within a file without affecting your text, you must be in command mode
pressEsctwice
...
j
Moves the cursor down one line
...
l
Moves the cursor to the right one character
position
...
Most commands in vi can be prefaced by the number of times you want the action to occur
...
There are many other ways to move within a file in vi
...
Here are some more commands you can use to move around the file −
Command
Description
0 or |
Positions cursor at beginning of line
...
w
Positions cursor to the next word
...
(
Positions cursor to beginning of current sentence
...
E
Move to the end of Blank delimited word
{
Move a paragraph back
}
Move a paragraph forward
[[
Move a section back
]]
Move a section forward
n|
Moves to the column n in the current line
1G
Move to the first line of the file
G
Move to the last line of the file
nG
Move to nth line of the file
:n
Move to nth line of the file
fc
Move forward to c
Fc
Move back to c
H
Move to top of screen
nH
Moves to nth line from the top of the screen
M
Move to middle of screen
L
Move to botton of screen
nL
Moves to nth line from the bottom of the screen
:x
Colon followed by a number would position the cursor on line number
represented by x
Control Commands
There are following useful command which you can use along with Control Key −
Command
Description
CTRL+d
Move forward 1/2 screen
CTRL+d
Move forward 1/2 screen
CTRL+f
Move forward one full screen
CTRL+u
Move backward 1/2 screen
CTRL+b
Move backward one full screen
CTRL+e
Moves screen up one line
CTRL+y
Moves screen down one line
CTRL+u
Moves screen up 1/2 page
CTRL+d
Moves screen down 1/2 page
CTRL+b
Moves screen up one page
CTRL+f
Moves screen down one page
CTRL+I
Redraws screen
Editing Files
To edit the file, you need to be in the insert mode
...
I
Inserts text at beginning of current line
...
A
Inserts text at end of current line
...
O
Creates a new line for text entry above cursor
location
...
X
Deletes the character before the cursor location
...
d^
Deletes from current cursor position to the beginning of the
line
...
D
Deletes from the cursor position to the end of the current line
...
As mentioned above, most commands in vi can be prefaced by the number of times you want the
action to occur
...
I would highly recommend to exercise all the above commands properly before proceeding
further
...
Here
are the relevant commands −
Command
Description
cc
Removes contents of the line, leaving you in insert mode
...
r
Replaces the character under the cursor
...
R
Overwrites multiple characters beginning with the character currently
under the cursor
...
s
Replaces the current character with the character you type
...
S
Deletes the line the cursor is on and replaces with new text
...
Copy and Past Commands
You can copy lines or words from one place and then you can past them at another place using
following commands −
Command
Description
yy
Copies the current line
...
p
Puts the copied text after the cursor
...
Advanced Commands
There are some advanced commands that simplify day-to-day editing and allow for more efficient
use of vi −
Command
Description
J
Join the current line with the next one
...
<<
Shifts the current line to the left by one shift width
...
~
Switch the case of the character under the cursor
...
U
Restore the current line to the state it was in before the cursor entered
the line
...
Typing 'u' again will re-do the change
...
A count joins that many lines
...
:f filename
Renames current file to filename
...
:e filename
Opens another file with filename
...
:e #
Use to toggle between two opened files
...
:p
In case you open multiple files using vi, use :p to go to previous file in
the series
...
:r file
Reads file and inserts it after current line
:nr file
Reads file and inserts it after line n
...
For a string search, the / and ?
commands are used
...
These two commands differ only in the direction where the search takes place −
The / command searches forwards downwards in the file
...
The n and N commands repeat the previous search command in the same or opposite direction,
respectively
...
Character
Description
^
Search at the beginning of the line
...
...
*
Matches zero or more of the previous character
...
[
Starts a set of matching, or non-matching expressions
...
>
See the '<' character description above
...
The
f and F commands search for a character on the current line only
...
The t and T commands search for a character on the current line only, but for t, the cursor moves
to the position before the character, and T searches the line backwards to the position after the
character
...
To use
these commands you have to come in command mode then type :set followed by any of the
following options −
Command
Description
:set ic
Ignores case when searching
:set ai
Sets autoindent
:set noai
To unset autoindent
...
:set sw
Sets the width of a software tabstop
...
:set wm
If this option has a value greater than zero, the editor will automatically
"word wrap"
...
To run a command, you only
need to go into command mode and type :! command
...
When you press any key orthecommand ′ sescapesequence, you are returned to your vi session
...
Here is the simple syntax −
:s/search/replace/g
The g stands for globally
...
IMPORTANT
Here are the key points to your success with vi −
You must be in command mode to use commands
...
You must be careful to use the proper case capitalization for all commands
...
Loading [MathJax]/jax/output/HTML-CSS/jax
Title: Vi editor for linux
Description: Linux vi editor - various modes of vi editor
Description: Linux vi editor - various modes of vi editor