Vim Text Editor

Source: Internet
Author: User

Three main modes:

Command mode (default): Move cursor, cut/paste text

Insert (Edit) mode: Modify text

Extended Command mode: Save, exit, etc.

ESC key to exit the current mode

ESC key always returns to command mode


Mode conversion:

Command mode---insert mode

I:insert, enter at the cursor position

I: Input at the beginning of the line where the current cursor is located

A:append, enter after cursor location

A: Enter at the end of the line at the current cursor

O: Opens a new line below the line where the current cursor is located

O: Opens a new line above the line where the current cursor is located


Insert mode----> Command mode

Esc

Command mode----> Extended mode

:

Extended mode----> Command mode

Esc


Extended mode:

: Q exit

: q! Force exit, discard the modifications made

: Wq Save Exit

: X Save exit


Command mode:

shift+^: Jumps to the first non-whitespace character at the beginning of a line;

0: Jump to the beginning of the line

shift+$: Jump to end of line

#G, extension mode: #: Jump to line specified by #

G: Last line

1G, GG: First line


Command mode Flip screen operation

CTRL+F: Flip a screen to the end of the file

CTRL+B: Flip a screen to the file header


Character editing:

X: Delete the character at the cursor;

#x: Delete the # characters at the beginning of the cursor


Delete command:

D: Delete command, can be combined with the cursor jump character, to achieve range deletion;

d$: Delete to end of line

d^: Delete to non-empty header

D0: Delete to the beginning of the line

DD: Delete the line where the cursor is located

#dd: Multi-line deletion

D: Always delete from the current cursor position to the end of the line, leaving blank lines, equivalent to d$


Copy command:

y^: Copy to non-empty header

y$: Copy to end of line

Y0: Copying to the beginning of the line

YY: Copying rows

#yy: Copying Multiple lines

Y: Copy Entire row


Paste command (P, paste):

P: If the buffer is an entire row, paste the current cursor below the row, or paste it at the end of the current cursor.

P: If the buffer is an entire row, the current cursor is pasted above the row, otherwise, it is pasted to the front of the current cursor position.


Address delimitation:

: Start_pos,end_pos

#: The specific # line, for example, 2 means line 2nd;

#,#: From the left # indicates the line start, to the right # indicates the end of the line

#,+#: The start of the line from the left #, plus the number of rows on the right # representation

: 2,+3 = 2 to 5 rows

.: When moving forward

$: Last line

., $-1 current line to penultimate line

%: Full text, equivalent to 1,$


Extended mode: Find and replace

S: Complete the Find and replace operation in extended mode

Format: s/What to look for/replace with content/modifiers

What to look for: Available modes

Replace with: cannot use mode, but can use \1, \2, ... You can also use the "&" reference to find the entire contents of the previous lookup

Modifier:

I: Ignore case

G: global substitution; By default, each row replaces only the first occurrence of the

GC: Global substitution, asking before each replacement

Find separators in substitutions/can be replaced with other characters, such as

[Email protected]/[email protected]/[email protected]

s#/boot#/#i


Instance:

1. Copy the/etc/rc.d/init.d/functions file to the/tmp directory, and add a # number to the beginning of the line beginning with a blank character for each line of/tmp/functions with the Find replacement command

[Email protected] ~]# cp/etc/rc.d/init.d/functions/tmp/

[Email protected] ~]# vim/tmp/functions

Execute in Extended mode:

:%[email protected]^[[:space:]]\[email protected]#&@

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/AF/wKioL1esNZaybxGfAAAdyhJ0wv4664.png "title=" 22.png "alt=" Wkiol1esnzaybxgfaaadyhj0wv4664.png "/>


650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/B0/wKiom1esNhKQ-UqJAAAhcFMKY-Q169.png "title=" 23.png "alt=" Wkiom1esnhkq-uqjaaahcfmky-q169.png "/>

2, replace the/etc/sysconfig/init in/tmp/functions file is/var/log;

[Email protected] ~]# vim/tmp/functions

Execute in Extended mode:

:%[email protected]/etc/sysconfig/[email Protected]/var/[email protected]

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/85/B0/wKiom1esN03RRereAAAltHCjdhk411.png "title=" 24.png "alt=" Wkiom1esn03rrereaaalthcjdhk411.png "/>


650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/85/B0/wKiom1esN1zh0l8LAAAf2p-YRD4859.png "title=" 25.png "alt=" Wkiom1esn1zh0l8laaaf2p-yrd4859.png "/>


This article from "Progress a little every day" blog, declined reprint!

Vim Text Editor

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.