Linux Learning 6th day (self-study) vim use

Source: Internet
Author: User
Tags modifier switches

Linux Learning 6th day (self-study) vim use

Time: 20180721


Directory

Vim

Mode switching

Exit file

Cursor movement

Move between rows

Vim's editing commands

Vim Visualization mode

Undo Edit

Flip Screen operation

Last-line mode in VIM

Content delimitation

Find

Find and replace

Window Property Definition

Multi-file Mode operation

Multi-Window Mode




Vim Editor

VI IMprove, VI version

This is a very popular file editor software in a Linux system.


Vim's three modes of operation


1. Edit mode is also called command mode, keyboard operation is often understood as edit command

2. Input mode enter content in text file

3. Last line mode vim built-in command line interface, execute VIM's built-in command


Mode switching

1. ESC input mode switch to edit mode

2. Switch from edit mode to input mode I, a, O, I, A, O, C, R, R

3. Edit mode switch to last line mode:


Note: Input mode cannot be switched directly to the last line mode


Exit file

: Q,: q!,: Wq,: X,: wq!,: W/path/file

Edit mode save exit shortcut key ZZ


Cursor movement

Moving between characters H J K L

Move between words W e b

Move in line ^ $0

Move between sentences ()

Move between paragraphs {}

Move between rows

G 1G GG


Vim's editing commands

X Delete the character at the cursor location

d Delete command, combined with the use of the cursor relay character, delete the jump range of characters

W, B, E, $, 0, ^

DD deletes the cursor in the row

#dd Delete multiple rows

P Paste Paste

The P buffer is pasted at the bottom of the line where the current cursor is located, if the entire row is stored.

Otherwise, paste to the back of the current cursor

P buffer If the entire row is stored, paste it above the line where the current cursor is located,

Otherwise paste at the front of the current cursor

Y yank copy, combined with cursor jump characters, to copy the characters within the jump range

W, B, E, $, 0, ^

Y Copy Line

C change changes, combined with the cursor jump character use, modify the jump range of characters

W, B, E, $, 0, ^

CC C deletes the entire line at the cursor and then into the input mode


Vim Visualization mode

V The character passed by the cursor

V the line that the cursor walks through


Note: Often combine editing commands with D, C, y


Undo Edit

U undo undo Previous Action

#u undo the actions of the last # times


Undo the previous undo action Ctrl+r


Flip Screen operation

Ctrl+f a screen to the end of the file

Ctrl+b a screen to the file header

Ctrl+d half screen to the end of the file

Ctrl+u half screen to file header


Last-line mode in VIM

1. Content Delimitation Startpos,endpos

# Jump to # # line

#,# from the left # line to the end of the # line on the right

#,+# from the left # line, plus the number of rows represented by the # line on the right

. When moving forward

$ last line

% full text, equivalent to 1,$

/pat1/,/pat2/from the first time the PAT1 pattern is matched to a row, until the first time it is matched by PAT2 mode

To the end of the line


How to use:

followed by an edit command C, D, Y can be attached directly to the address range after use

W/path/file to save the selected content to the specified file

R/path/file reads the specified file contents into the currently open file

2. Find

/pattern from the current cursor at the end of the file

? PATTERN looks at the file header from the current cursor location

N finds the next matched text in the same direction as the command

N finds the next matched text in the opposite direction of the command

3. Find and replace

s to complete the find-and-replace operation in mode

s/Find mode/content/modifier to replace


The lookup mode can use regular expressions

The content to be replaced cannot use patterns, only references such as \1,\2, etc., can be used

You can also use & to refer to the entire content found in the previous lookup

Modifier

I ignore case

G global substitution, by default one line replaces only the first occurrence

4. Window Properties Definition

Set NU Display line number

Set Nonu Cancel line number

Set AI autoindent enable auto indent

Set Noai Cancel Auto Indent

The set IC ignores character case

Set Noic does not ignore the case of characters

Syntax On|off syntax highlighting

Set Hlsearch|nohlsearch Search highlighting


Note: The Window property definition in the last row mode is valid only for the current vim process, and can be modified permanently to modify the following

Configuration file to define global/ETC/VIMRC user ~/.VIMRC


5. Multi-file mode (open multiple files at once)

: Next switches to the next file

:p revious Switch to the previous

: Last switch to final

: First switches to a

: Wqall Save all files and exit


6. Multi-Window Mode

Multiple files open more than one file at a time and appear in multiple Windows Vim-o a.txt b.txt

-O Horizontal Split

-O Vertical Split

Toggle Ctrl+w,arrow between windows (arrow keys)


Single File

Ctrl+w,s Horizontal split to split the current file horizontally into two windows (easy to see)

Ctrl+w,v Vertical Split splits the current file vertically into two windows


Linux Learning 6th day (self-study) vim use

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.