Common Vim/Vi operations (version 2)

Source: Internet
Author: User

Common Vim/Vi operations (version 2)

Colleagues around you are either using vim or Emacs. If you use ultraedit, you are embarrassed to say hello to others. What plug-ins are there? syntax highlighting and spelling check, everything that can be opened to it is a word: Cool.

If you say so, you have to learn how to do it for half a year. Half a year! It's far from getting started. It's good to learn to move the cursor. You don't have to worry about it, it's just moving around !!!

Vim/Vi Introduction

Vi is installed by default for all Linux/UNIX systems, and vim is installed by default for mainstream Linux systems.

Vim/Vi is a powerful full-screen text editor, the most common text editor on Linux/UNIX. It is used to create, edit, and display text files; vi supports almost all languages.

Vim/Vi has no menu and only commands.

Official Website: www.vim.org

Vim/Vi Working Mode

INSERT command

Command function

A attaches text behind the cursor

A adds text at the end of the line

I insert before the cursor

I insert text at the beginning of the line

O Insert a new row under the cursor

O Insert a new line to the cursor

Locating command

Command function

H shifts one character to the left

J. Move one row down

K move one row up

L move one character to the right

$ Move to the end of a row

0 move to the beginning of the row

H move to the top of the screen

M moves to the center of the screen

L move to the bottom of the screen

Quick Positioning

Command function

: Set nu display row number

: Set nonu cancel row number

Move gg to the first line

Move G to the last row

NG to n

: N to row n

DELETE command

X: Delete the cursor character

Nx Delete n characters

Dd deletes the row where the cursor is located, and ndd deletes n rows.

DG deletes all rows from the current row to the end of the file, including the current row

D. Delete the content from the cursor position to the end of the line.

: N1, n2d Delete n1 ~ N2 row

Copy command

Yy and Y copy the current row

Nyy, nY copy n rows

Dd: Cut the current row. ndd: Cut the current row and the next n rows.

P paste under the current row

P [uppercase] pasted on the current row

Replace or cancel command

R replaces the character at the cursor

R replaces the character from where the cursor is located until Esc ends.

U cancel the previous operation. First, you have not saved the file. The file is still in memory and has not been synchronized to the hard disk.

Replace or SEARCH Command

/String: searches for the specified string backward. case-insensitive: set ic is ignored during search. Cancel: set noic

N turning back

N forward from the back

: % S/old/new/g Replace the specified string in full text, and old is the keyword to be replaced.

: N1, n2s/old/new/g Replace the specified string within a certain range

: % S/old/new/c Replace the specified string in full text, but will ask

Save and exit

ZZ: wq shortcut

: W new_filename save as the specified file

: Wq! Forcibly Save the modification and exit [root/file owner]

: Q! Do not save and exit

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.