Sunday, November 16, 2014

vim command linux

Leave a Comment
vim command is operator 2 mode: normal mode, insert mode.Vim is an editor to create or edit a text file.

Note: 

Pressing <ESC> to return Nomarl mode to performing commands the below:

Moving the cursor:

To move the cursor, press key:

h: move left
j: move below
k: move top
l: move right

Motion the curson:

type w to move the cursor words forward
type e to move the cursor to the end of the word forward
type 0 (zero) to move to the start of the line.

Exiting VIM:

press <ESC> key ---> type :q!<ENTER> to not save all changes.
press <ESC> key ---> type :wq<ENTER> to save the changes.

Text editing - insertion:

press i key insert before the cursor
press A key appended text after the line

Deletion commands:

To delete a word, press dw 
To delete the character at the cursor type: x
To delete a whole line, type dd

The undo command:

press u key to undo the last commands
press U (capital U) to undo all the changes on a line
type CTRL-R to redo the commands (undo the undo's)

The replace command:

type r key then the character you want EX: type ra to replace the character at the cursor with a

Cursor location and file status:

Type CTRL-G to show your location and file status: type G to move the bottom of file and Type gg to move to the start of the file

The search command:

Type /<a phrase><ENTER> ex /huuphang-->ENTER press.
To search for the same phrase again, type n
To search for thesame phrase in the opposite direction, type N

Matching parentheses search:

type % to find a matching ),], or }. place the cursor on any (,[, or {, then type % character

The substitute command:

To substitute phang for the first huu in a line, type  :s/huu/phang
To substitute phang for all 'huu's on a line type  :s/huu/phang/g
To substitute phrases between two line #'s type  :#,#s/huu/phang/g
To substitute all occurrences in the file type  :%s/huu/phang/g
To ask for confirmation each time add 'c'  :%s/huu/phang/gc

How to execute an external command:

Type :!<external command> ex: :!ls

Writing files:

type :w filename

Selecting text to write:

move the cursor to line, type v then :w filename

Retrieving and merging files:

To insert the contents of a file, type :r filename

Copyright by: www.linuxoperatingsystem.info http://goo.gl/kMscJ4

0 comments:

Post a Comment