Command Mode

This is the default mode of vi editor. In this mode, most navigation and browsing of file content is performed. Besides the navigation of file content, we also perform cut, delete, copy, and paste operations in Command Mode. The following table describes the popular navigation operations of Command Mode:

KEY

USAGE

Move by character

Arrow keys

For moving the cursor up, down, left, and right

j or <enter>

For move the cursor one line down

k

For move the cursor one line up

h or Backspace

For move the cursor one character left

l or Space

For move the cursor one character right

Move by word

w

For moving the cursor to the beginning of the next word

b

For moving the cursor to the previous word

e

For moving the cursor to the end of the current word

Move by line

0 or ^

For moving the cursor to the beginning of the line

$

For moving the cursor to the end of the line

Move by sentence

(

For moving the cursor to the beginning of the previous sentence

)

For moving the cursor to the end of the next sentence

Move by paragraph

{

For moving the cursor to the beginning of the previous paragraph

}

For moving the cursor to the end of the next paragraph

Move by screen

Ctrl + F or Page Down

For moving forward one screen

Ctrl + B or Page Up

For moving backward one screen

Ctrl + D

For moving down half a screen

Ctrl + U

For moving up half a screen

H

First line on screen

M

Middle line on screen

L

Last line on screen

Move inside whole document

:0 or 1G or gg

For moving to the beginning of a file

:$ or G

For moving to the last line of a file

:n or nG

For moving to the nth line

 

Next, we will see how we to perform cut, delete, copy, and paste operations in Command Mode. The deletion of a character puts the text in an unnamed temporary buffer. The deleted character stored in a temporary buffer can be pasted at other places. Hence, we can say that a delete and paste operation is similar to a cut and paste operation.

The copying of character is known as yanking in context of vi editor. Copying (yanking) is performed using the yank y command. The following table describes various cut, copy, delete, and paste operations in vi editor:

KEY USAGE

Deleting/cutting single characters

x

Deletes a character at the current cursor position

Nx

Deletes the N-1 character on the right-hand side, starting at the current cursor position

3x

Deletes a total of three characters, starting with the character currently under the cursor position, followed by the next two on the right-hand side

X

Deletes a character to the left of the cursor

Deleting/cutting larger chunks

dw

Deletes the word at the current position up to the next space or next punctuation

db

Deletes one word backward

d$

Deletes the line from the current cursor position to the end of the line

d^ or d0

Deletes the line from the current cursor position to the beginning of the line

dG

Deletes from the current line to the end of the file

dgg

Deletes from the current line to the beginning of the file

D

Deletes the rest of the current line

dd

Deletes the current line

Ndd or dNd

Deletes N lines from the current line

Copying/yanking text (puts text into a temporary buffer)

yw

Yanks (copies) a word forward

yb

Yanks (copies) a word backward

y$

Yanks (copies) the line from the current cursor position to the end of the line

y^ or y0

Yanks (copies) the line from the current cursor position to the beginning of the line

yy

Yanks (copies) the current line and puts it in a buffer

Nyy or yNy

Yanks (copies) N lines and puts them in a buffer

p

Pastes the contents below the current line (the yanked line or lines from the buffer)

P

Pastes the contents above the current line

u

Undoes the previous operation

Ctrl + R

Redoes the last undo operation

Typing vimtutor at the prompt launches a concise, yet comprehensive, tutorial for beginners. This tutorial is short and to the point, to make beginners proficient in using vi editor.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.230.82