Vim Program Editor Usage summary

Source: Internet
Author: User

Vim Program Editor VI and VIM VI: is a word processor

All UNIX like systems will have a VI text editor built in

Many of the software's editing interfaces will actively call VI

Premium version of Vim:vi. is a program development tool

According to the file extension or the beginning of the file to determine the contents of the file, automatically call the program's syntax, color to display the program code

Vi. use of three different modes

General mode

Search and replace, delete characters, delete/copy/paste entire rows

Edit mode

Edit File Contents

Command-line mode

That is, exit VI

General mode common buttons
Cursor movement

G

Move to the last line of the file

N+g

Move to the nth line of the file

N+↑

Move N rows up

N+↓

Move Down n rows

[Ctrl]+[f]

Page Down

[Ctrl]+[b]

Page UP

0 or [home]

Move to the beginning of the line

$ or [end]

Move to end of line

Find and replace

/word

Query down Word

? word

Query up Word

N

Repeat the previous query

N

Reverse repeating previous query

: n1,n2s/word1/word2/g

Between N1 and N2 lines, replace word1 with Word2 and do not ask

: 1, $s/word1/word2/g

From the first line to the last row, replace word1 with Word2, without asking

: 1, $s/word1/word2/gc

From the first line to the last row, replace Word1 with Word2, asking

Line number

: Set Nu

Show line Numbers

: Set Nonu

Do not display line numbers

General Mode---> Edit mode

I

Insert at CURSOR location

I

Inserts the first non-whitespace character in the row of the cursor

A

Inserts the next character prompt at the cursor location

A

Insert the last Word prompt the line where the cursor is located

O

Insert a new line on the next line of the cursor

O

Insert a new row at the top of the line where the cursor is located

R

Replaces only the character of the cursor once

R

Always replace until [ESC]

General Mode---> command line mode /tr>

:q!

:wq

save exit

:w[filename]

:r[filename]

reads the file data of filename and adds it to the line following the cursor

:n1, N2 w [filename]

n1 to N2 row saved as filename

:! Command

temporarily leave VI to command-line mode and execute command

. swp file

Simultaneous editing by multiple people

Find the corresponding person to negotiate

Unknown cause

Not sure if it's useful

Recover

Open the. swp file and choose whether to save it yourself

Note:. swp files are not automatically deleted and need to be deleted manually

Determine useless

Delete

Vim's function block selection

V

Character selection, anti-white selection of characters to be passed

V

Row selection, and the line to be passed is reversed to the white selection

[Ctrl]+v

Block selection, choose in a fast way, as shown on the left

Y

Copy anti-white area

D

Remove anti-white area

Multi-file editing

Premise:

Open multiple files at the same time

VI file1 file2

Switch files in general mode

: N

Compiling the next file

: N

Edit Previous file

: Files

List all the files that Vim is currently open

Multi-Window function

: SP [filename]

Opens a new window with two windows for the same file without the filename parameter

[Ctrl]+w+↑

Press the method: Press [Ctrl] and W first, then release, then press ↑

Move to the window below

[Ctrl]+w+↓

Move to the top window

[Ctrl]+w+q

Close the window

Vim environment settings and logging

~/.viminfo

VIM will take the initiative to record previous operations

: Set All

Review all current environment setting values

: Set

Show the parameters of your own changes

: Set Nu

Show line Numbers

: Set Nonu

: Set Hlsearch

Find the string highlighting

: Set Nohlsearch

: Set Autoindent

Auto Indent

: Set Noautoindent

: Set Backup

Save the backup file automatically. Default does not save automatically

: Set Nobackup

: Set Ruler

Show status description in lower right corner

: Set Noruler

: Set Showmode

Whether to display the lower left corner status description

: Set backspace= (012)

Whether to allow backspace deletion.
0/1--Delete the characters that have just been entered, unable to delete the original text;
2--can delete any character

: Syntax on

Display colors based on syntax

: Syntax off

: Set Bg=dark

Set basic tones

: Set Bg=light

Other VIM usage precautions Chinese code

Linux Default supported language data

/etc/sysconfig/i18n

View Current Bash language encoding

Echo%lang

Modify language encoding

Lang=zh_cn.big5

Dos vs. Linux break characters

DOS (Windows) break line characters are ^M$,CR and LF

Linux under only $, that is, only LF

Dos2unix [-kn] file [new file]

-K

Keep file original mtime (file content Modification) time

-N

Keep old files, make new files

File language encoding Conversion

Iconv-f Original code-t new code filename [-o newfile]

--list

List the language data supported by Iconv

-F

The original code

-T

New Code

-O

Keep old files, make new files

Vim Program Editor Usage summary

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.