Vim Basic usage

Source: Internet
Author: User

Vim Basic Usage

Modal editor

Mode:

Edit mode: Command mode

Keyboard operations are often understood as editing commands

Input mode

Last-line mode: Vim built-in command interface, execute VIM command

Open File

VIM [option] ... [File] ...

Mode conversion:

Edit mode--Input mode

I: Convert to input mode in front of cursor

A: Convert to input mode at the rear of the cursor

O: Create a blank line below the cursor line and convert to input mode

I: The beginning of the line

A: The beginning of the line

O: Create a new blank line above the line of your cursor

Input mode--edit mode

Esc

Edit Mode--last-line mode

:

Last-line mode--edit mode

Esc

Exit File:

: q! Do not save exit

: Wq Save Exit

: X Save exit

ZZ does not save exit

Edit text:

Cursor Movement:

#{hjkl}: Jump # Characters

Move between words:

W: The next word in the first word

E: The ending of the current or next word

B: The current word or the first word

In-line movement

^: first non-whitespace character at the beginning of a line

0: The absolute beginning

$: absolute end of line

Move between rows

#G: Jump straight to Line #

G: Last line

Edit command:

X: Delete the character at the cursor location

D: Delete command

Use the cursor jump character to remove the characters within the cursor jump range

DD: Delete cursor in the row

d:d$, delete the character after the cursor

Note: The last deleted content will be saved to the buffer

P:paste, paste

Line level:

P: Paste above the current line

P: Paste below the current line

Less than line level

P: Paste at the rear of the current cursor line

P: Paste in front of the line where the current cursor is located

Y:yank, copy

Use the cursor jump character to copy the characters within the cursor jump range

Y:yy

C:change, modify

Use the cursor jump character to modify the characters in the jump range

First delete, then convert to input mode

Cc,c: Delete the entire line where the cursor is located and then convert to input

Undo Action:

U:undo, Undo

#u: Undo Recent # Operations (50)

Revocation of previous revocation: Ctrl+r

Repeat the previous command:.

last-line mode:

Inline Jump:

#: Specify the number of rows

$: Last line

Content delimitation

Startpos,endpos

#: Line #

.: When moving forward

$: Last line

%: Full text, equivalent to 1,$

Commands such as c,d,y can be attached directly to the address range after use

W/path/to/somefile: Saving content in a selected range to a file

R/path/from/sonmefile: Reads the contents of the specified file to the specified location

s/Find mode/content to be replaced/gi

%s/echo/i/gi

Find mode: You can use regular expressions

What to replace: You cannot use a pattern, you can use only references

G:global, full line replacement

I: Case insensitive

All content that the reference matching pattern matches to can be used &

Practice:

Copy/etc/rc.d/init.d/functions to/tmp directory

Replace/etc/sysconfig/init in/tmp/functions file with/var/log

:%s#/etc/sysconfig/init#/var/log#gi

Practice:

1. Copy the/etc/grub.conf to tmp directory and delete the white space characters from the beginning of the/tmp/grub.conf file

:%s#^[[:space:]]\{1,\}# #gi

2. Copy the/etc/rc.d/rc.sysinit to/tmp directory and add # to the beginning of the line with at least one white-space character in the/tmp/rc.sysinit file

:%s/^\ ([[: Space:]]\+\)/#\1/gi

:%s/^[[:space:]]\+/#&/gi

3. Remove the # and white space characters from the beginning of the line with the # Sign in the/tmp/rc.sysinit file, followed by at least one white-space character

:%[email protected]^#[[:space:]]\{1,\}@@

4. First # # of lines for the first three lines of the/tmp/grub.conf file

: 1,[email protected]^@#@

5. Change the enable=0 and gpgcheck=0 in the/etc/yum.repos.d/centos-media.repo file to the last 0 of the two lines to 1

%[email protected]\ (enable\|gpgcheck\) [email protected]\[email protected]

Vim Visualization mode

V: The character passed by the cursor

V: The line that the cursor traversed

Text lookup:

Usage with less command

/pattern

? pattern

Flip Screen:

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

CTRL+B: Flip a screen to the file header

Ctrl+d: Turn half screen at the end of the file

Ctrl+u: Turn half screen to file header

J: Go down one line

K: Want to go on a line

Multi-file Mode:

: Next Next file

:p revious A previous file

: Last File

: First File

: Wqall Exit Save All

Multi-Window Mode:

Multiple files

-O: Split horizontally two windows

-O: Vertical split of two windows

Ctrl+w,arrow

Single File:

Ctrl+w,s: Horizontal Split

Ctrl+w,v: Vertical Split

Window property settings:

: Set NU Displays line number

: Set Nonu suppress line numbers

: Set AI Auto Indent

: Set Noai Cancel Auto Indent

: Set IC ignores character case

: Set SM display automatically matches parentheses

: syntax off syntax highlighting off

Configuration file:

Global:/ETC/VIMRC

Users: ~/.VIMRC


This article is from the "Bran" blog, make sure to keep this source http://branguo.blog.51cto.com/9768383/1599262

Vim Basic usage

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.