Linux learning (eight) - Linux - Vim editor

Vim editor

A, Vi introduction

VI editor is a standard editor for Unix and Linux systems all similar to the Notepad editor for Windows systems, any version of Unix and Linux systems, Vi editor is exactly the same. Vi is the most basic Linux text editor. About Vi and Vim editor is in Linux, but Vim is an upgraded version of Vi, Vi for text editor, and Vim more suitable for writing code.

Two, Vim introduced three models

There are three modes (defined here uncertain) Vim in: Command ModeEdit modeLine mode.
Command mode : You can not directly edit files in this mode, but you can enter shortcuts do something. (Deleting lines, line copy, move the cursor, paste, etc.) [The default is to open the file after entering the pattern]
Line mode : You can edit the contents of the file in this mode
Edit mode : you can enter commands to operate the bottom line (replace, search, save, quit, revocation, highlighting, etc.) on the file
Vim's Open:
syntax 1 : #vim file path
meaning: open the file specified
syntax 2 : #vim+Digital file path
meanings: open the specified file, and move the cursor to the specified line
syntax . 3 : #vim+/Keyword file path
meanings: open the specified file, and highlight keywords
grammar 4 : #vim File Path File Path 1 2 3 ~~~ file path
meaning: open multiple files
Vim exit strategy:
1, enter::q(Pure exit)
2, type::wq(Save and exit)
3, enter::q!(Force quit, the operation of the modified not saved)
4, enter::x (Exit in case of unmodified; save and exit in the case of making changes, butDo not use uppercase X, X represents the file encryption)
Difference wq and x: if the file has not been modified, use wq exit, file modification time will be updated; but if the file has not been modified, using x conduct exit, file modification time will not be updated.
It is recommended that the use of x save and exit.

Third, the command mode

This mode is to open the file immediately see the model, that is, open the file command mode.
1, movement of the cursor
① move the cursor to the first line: Key: ^
② cursor to end of the line: Key: $
③ move the cursor to the first line: Key: GG
④ move the cursor to the last line: Key: G
⑤ scroll:
Up scroll: press ctrl + b PgUp or
scroll down: press ctrl + t or PgDn

2, copy
① copy cursor line
copy: yy
Paste: P
② to cursor Conduct (including the current row), copy the specified number of rows down
replication: Digital yy
Paste: P
③ Visualization replication
replication: first ctrl + v or V or v, and then press the arrow keys ↑ ↓ ← → to select the block area needs to be copied, there are pressing, copy
and paste: p

3, cut / remove
① cut / remove the line cursor
keys: dd (shift after deleting the next line)
② to Conduct cursor (including the current row), cut down / delete the specified line number
keys: Digital dd (shift after deleting the next line)
③ cut / delete the contents of the cursor after the current line, but not on the next line after deleting shift
key: D (delete the current row will be blank line)
④ visualized delete
button: first ctrl + v or V or v, and then press the arrow keys ↑ ↓ ← → to select the block area to be deleted and press the delete selected region row represents D, d represents delete selected block region

4, undo / redo
Undo: Input: u (not command mode) or u
Recovery: ctrl + r (resume or cancel the previous undo operation)

5, moving the cursor quickly
① quickly move the cursor to a specified row
key: G number
② subject to the current cursor moves up / down n rows
keys: Digital ↑ or ↓ digital
③ subject to the current cursor left / right n OK
button: digital digital → ← or
fast-moving mode in the line mode ④: move to a specified row
key: enter English ":" (colon), followed by the number of the input line number, press enter

Switching between four modes

Command line mode → Mode: Input :(Colon);
line mode → Command Mode: Press ESC; double-esc, delete all the command line mode;
command mode → editing mode: Press i, a and the like;
edit mode → Command Mode: Press it esc;

Fifth, the last line mode

Entry mode: enter the command mode, press the ":" or "/" (Find) to enter the
exit strategy:
A press esc
b, double-click esc
c, delete the last line of all input character
or description above the exit method.
1, search / find
input:/Keywords
such as, bin location search keywords in the file. You can enter / bin, there will be highlighted in the document bin display
A search result in the upper switching element / lower: N / n
To cancel the highlight, then input: nohl

2. Replace
①: s / keyword search / new content
meaning: Replace the cursor lineFirst placeEligible content
②: s / keyword search / new content / g
meaning: Replace the cursor line all in compliance with the contents of the conditions
③:% s / keyword search / new content
meaning: to replace the entire document every RowFirst placeMatching content
④:% s / keyword search / new contents / g
Meaning: replacing the entire contents of the document qualified
wherein,% represents the entire document, g represents a global (Global)
. 3, line number display
Input: " : set nu "(nu: number )
To cancel the display, enter": the SET nonu "(nonu: not number the)
4, in front of a command to open multiple files, switching documents in line mode
to view the current open file name: ": files"; and displayed% a #. Where% a represents the currently open file, the # represents an open file
mode switching file:
① If you need to specify the name of the switch file, enter: ": open open file name"
② can use other commands to switch on a file / next file
input: ": bn" is switched to the next file (back next)
input: ": bp" switch to a file (bank prev)

Sixth, the edit mode

Entry mode: i (insert), a ( after)
Withdrawing: esc
after entering enter the following command file for editing:
I: before the character cursor is initially inserted into
a: Insertion begins after the character cursor
o: the cursor bottom row starts a new line starts insertion
I (uppercase i): the first start inserting the cursor line, If the line spaces are inserted after the space
a: start inserting the end of line of the cursor line
O: the cursor line above a new line to start inserting
S: delete cursor line and start insert

Seven expansion

1, Vim is disposed
Vim arranged in three ways:
A file open configuration when the (temporary) in the input line mode.
B personal profile (~ / .vimrc, if no new own).
C globally. profiles (vim comes, / etc / vimrc),

After entering the edit ① New good personal profiles
② be configured in the configuration file
, such as display line numbers: set nu
After configuring vim to open the file will always display the line number
If for the same configuration items, personal configuration file exists, the personal profile prevail if the personal profile this one does not exist, the global configuration file prevail.
2, using Vim in the calculator
when suddenly need to use when editing the file calculator to calculate some formulas, at this time need to use a calculator, but need to exit, vim itself incorporates a simple calculator.
. A enter the edit mode
b pressing the key "ctrl + R", and then enter the "=", then the cursor becomes the last row.
C content of the input to be calculated, press Enter.
3, color coding
displayed: ": syntax on "
Close display:": syntax off "

Before turning Coloring:
Here Insert Picture Description
After opening Coloring:
Here Insert Picture Description

Released eight original articles · won praise 0 · Views 181

Guess you like

Origin blog.csdn.net/weixin_41396903/article/details/104876661