Você está na página 1de 5

VI COMMANDS

Wednesday, July 08, 2015

11:59 AM

<<<<<<<<<<BASIC VI COMMANDS>>>>>>>>>>>>>>>>>>
esc(twice)

=> Enters into the command mode

:w

=> Saves the content

:q!

=> quit without saving

:wq or ZZ

=> Quit with saving

:w filename => save the current file into an another new file
:e filename => Edit a file within vi
<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>
<<<<<CURSOR CONTROLS>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>
[<<<Moving up/down by line>>>>>>]
j

=> Move the cursor down one line

=> move the cursor up one line

[<<<Moving left/right by character>>>]


h

=> move the cursor to the left one character

=> move the cursor to the right one character

[<<<Moving to start/end of line>>>>>]


0 (zero) => Positions cursor to beginning of a line
$

=> Positions cursor to end of a line

:0 (zero) => Moves cursor to first line in a file


:$

=> Moves cursor to last line in a file

[<<<Moving forward/backward by a word>>>>]


w

=> Positions cursor to the next word

=> Positions cursor to the previous


word

[<<<Moving to top/bottom/middle of the screen>>>]


H

=> Move to top of screen

=> Move to middle of screen

=> Move to bottom of screen

nL

=> Moves to nth line from the bottom of the screen

=> Moves cursor to first non-blank column

Linux_VI Page 1

=> Moves the cursor to end of the next word or punctuation

:[n]

=> Moves cursor to line n

<n>l

=> Moves cursor to column n

<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<SCREEN CONTROL>>>>>>>>>>>
<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>
CTRL + f

=> Move forward one full screen

CTRL + b => Move backward one full screen


CTRL + d => Move forward half a screen
<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<EDITING FILES>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>
i

=> Insert text before current cursor location

=> Insert text at beginning of current line

=> Insert text after current cursor location

=> Creates a new line for text entry below current location

=> Creates a new line for text entry above cursor location

=> Insert text at end of current line

:f

=>Displays the name of the file

<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<DELETING FILES>>>>>>>>>>
<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>
x

=> Deletes the character under the cursor location

=> Deletes the character before the cursor location

dw

=> Deletes from the current cursor location till end of that word

d$ or D

=> Deletes from the current cursor location till end of that line

d^

=> Deletes from start of line till one position before current
cursor location

dd

=> Deletes the line the cursor is on

:line no1, line no


2d

=> Deletes lines from line no 1 to line no 2

:g/^/+d

=> Deleting every 2nd row

<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>
<<<<<<<<<<COPYING>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
yy

=> Copies the current line

=> puts the copied text before the


cursor
Linux_VI Page 2

cursor
p

=> puts the copied text after the


cursor

:<line1>,<line2>t< destination (line number


under which it needs to be pasted)>

=>copies a specific set of lines and


pastes it under a specific location

<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>
<<<<<<<FIND COMMANDS>>>>>>>>>
<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>
?

=> Find a word going backward

=> Find a word going forward

To perform case insensitive search, add '/c' after the end of the search term.
To scroll through only the search term:
n=Forward scrolling
N=backward scrolling
<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>
<<<<<<<MISC. COMMANDS>>>>>>>>
<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>
:s/search/replace/g

=> Find and replace a word everywhere in the line

:line1,line2s/search/replace/g

=>Find and replace a word between lines1 and


lines2

:%s/search/replace/g

=> Find and replace a word everywhere in the file

:s/\<whole word to be
substituted\>/replace/g

=>Finds and replaces the whole word

:s/^/<string>/g

=> Inserts string at the beginning of all lines.

=> Join the current line with the next one.

=> Switches the case of the character under the


cursor

V~

=> Toggles the case of entire line under cursor

g~$

=> Toggles the case of all the character from point


of cursor to end of the line.

:set number (or) :set nu

=> Turn line numbering ON

:set nonumber (or) :set nonu

=> Turn the line numbering OFF

:.=

=> Shows the current line number

:ab <abbreviation> <word or


phrase>

=> Define the abbreviation for a word or a phrase

:ab

=> List all abbreviations

:abc

=> removes all abbreviations

=> Undo

CTRL + R

=> Redo

:edit (or) :e

=> Manually refresh a file

:$-9,$w <file_name>

=> write the last 10 lines to a file

Linux_VI Page 3

:read <filename> or r
<filename>

=> Insert another file contents inside the vi editor:

<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>
<<<<<<<MULTIPLE WINDOWS>>>>>>>
<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
CTRL + w(2 times)

=> Move cursor to another window (cycle)

:split filename

=> split window and load another file

:vsplit filename

=> vertically split window and load another file

:hide

=> close current window

10 (+) ^w (+) +

=> Increases the size of the current window by 10 lines

10 (+) ^w (+) -

=> Decreases the size of the current window by 10


lines

CTRL + w + up or down
arrow

=> Move cursor to another window

vi -o multiple_file_names

=> start vi with files in a horizontal split

vi -O multiple_file_names

=> start vi with files in a vertical split

:wqa

=> Close all windows after saving

:noh

=> Temporary disable search highlighting until next


search

<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<VI TABS>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
vi -p <file1>
<file2> ... <file n>

=>Opens n files in separate tabs

:tabe (or) :tabnew =>Opens an empty tab


:tabnew
<file_name>

=>Opens file in a new tab

:tabfir

=>Moves to the 1st opened tab

:tablas

=>Moves to the last opened tab

:tabn

=>Moves to the next tab

:tabp

=>Moves to the previous tab

:tabs

=>Provides a summary of open tabs

<n>gt

=>Switches to the nth tab

gt

=>Switches to the next tab. Wrap around from last to first tab.

gT

=>Switches to the previous tab. Wrap around from first to last


tab.

:tabclose <n>

=>Closes the nth tab

:tabonly

=>Closes all the tabs except the current one


Linux_VI Page 4

:tabonly

=>Closes all the tabs except the current one

:tabclose

=>Closes the last tab

:tabdo < vi editor =>Executes the vi command in each tab page


command>
*Note: When an error is detected in one tab page, further tab
pages, will not be visited. The last tab page ( or where an error
occurred becomes the current tab page)
Command must not open or close page or reorder them
:tab split

=>Copy the current window to new tab of its own

<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>
<<<<<<<USING MARKS>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
Marks allows to record a cursor position and return back to that spot later.
Usually lower case letters (a-z) will be used. If a new mark is made with the same
name as previous one, the previous marker is lost.
m<letter>

=> Adds a mark to the cursor at the specified cursor location

`<letter>

=> Jumps to the cursor place where the mark is made

'<letter>

=> Jumps to the line where the mark is made

:delmarks <letter> => deletes the specified marker


:delmarks!

=>deletes all lower case marks for the current buffer

vi ~/.vimrc => Can be used for setting the default appearances of vi. For instance, one can set the line
numbers on by default.

Linux_VI Page 5

Você também pode gostar