Linux development environment to build and use - Linux common editor vim

  

vi editor is the most commonly used text editor in Linux system, vi has the reputation of the editor of the Linux world in almost all Linux distributions Contains the vi program.
vi works in character mode, does not require a graphical interface, is very suitable for remote and embedded work, is a very efficient text editor, although there are many graphical interface editors available on Linux, but the function of vi is Those graphics editors can't match. What is vim?

vim is an upgraded version of vi, it is not only compatible with all the instructions of vi, but also has some new features, such as vim can be undone unlimited, support keyword auto-completion, can highlight your code with different colors . Vim is generally hailed as the best of the class vi editors.

official website: http: //www.vim.org/download.php

When using vim, ctags tool universal need assistance. Ctags is a tool for reading code in vim. It is a very powerful vim plugin. When you browse the code, you can jump between functions, variables, and so on.

Official website: http://ctags.sourceforge.net/

Preparations

Installing vim, ctags:

sudo apt-get install vim

sudo apt-get install ctags

& lt; img data-cke-saved-src = " http: //www.2cto.com/uploadfile/Collfiles/20150408/2015040809482968.jpg" src = " http: //www.2cto.com/uploadfile/Collfiles/20150408/2015040809482968.jpg" alt = " " http: = " " www.2cto.com = " " kf = " " ware = " " vc = " " " = " " target = " _blank " & gt; vcWyvc7EvP6jqM /C1NjWsb3TteO797y0v8mjqaOs1MvQ0L3Fsr28tL /Jzeqzyc /g06bF5NbDoaM8L3A + CjxwPjxpbWcgc3JjPQ == " http: //www.2cto .com /uploadfile /Collfiles /20150408 /2015040809482971.jpg " alt = " \\ " & gt;

vim simplest and most common operations

following, vim or vi command is used equivalent.


Let me introduce you to the simplest and most common operations (open files, edit files, save files). If you don't delve into it, learn these operations.


Open files with vi

vi filename: Open or create a new file and place the cursor at the beginning of the first line

If the file does not exist , will create a new file, as follows:



If the file exists, it is to open the file, open the file, press “i” enter the insert mode, Can be edited:


Due to the configuration of vim, resulting in the above column, press “F9” to achieve hidden display column switching.


By default, open files cannot be edited directly:


Press “i” to enter insert mode, you can edit :


vi +n filename: Open the file and place the cursor at the beginning of the nth line



Save File (one way):

Be sure to exit insert mode first, then shift + zz (press “shift” + press twice) to save the current file.

Detailed use of vim

The vim editor has 3 modes of operation (the name of the mode is not important, I can't tell the difference, know what to do in each mode):

1, vi insert mode vi When creating a non-existent file, enter insert mode by default vi Put the input characters as the body content in the file being edited


Vi Edit mode vi When you open an existing file, you enter the edit mode by default. In this mode, you can enter the insert mode, control the movement of the screen cursor, select text, copy, paste, cut, delete, and search.


3, vi Last line mode (command mode) In edit mode, press “shift” + “ : ” Enter Similar to edit mode, save, save, find Tasks


Mode Switch:

Switch from edit mode to insert mode

i Insert from the current position of the cursor

a Insert from the next character at the current position of the cursor

o Insert a blank line at the bottom of the cursor position and insert it

I Insert the body from the beginning of the line where the cursor is located

A Insert the body from the end of the line where the cursor is located

O Insert a blank line in the upper line of the cursor position, and then insert

Switch from edit mode to last line mode (command mode )

& ldquo; shift & rdquo; + & ldquo;: & rdquo;

the insert mode, the mode switching command to edit mode

Esc (two command mode to edit mode Esc)

Insert mode and command mode cannot be converted directly

Delete and modify text in edit mode

1, u Undo more than before Minor revision.

2, [n]x deletes n characters after the cursor.

3, [n]X Delete the first n characters of the cursor.

4, [n]dd deletes the n lines from the current line (accurately, it is cut, and the cut is not deleted).

5, [n]yy copy n lines starting from the current line.

6. p Insert the contents of the pasteboard into the current line.

7. Perform the last operation

8. Shift +zz (hold down shift and press z twice) Save and exit the current file

Copy in edit mode< Br>

yw copy a word

dw cut a word

cw modify a word

block select command

v: select by character< Br>

d: Clip the selected content to the clipboard.

y: Copy the selected content to the clipboard.

c: Clip the selected content to the clipboard and enter the insert mode

(n)shift + > The selected content moves to the right by a tab

(n)shift + <The selected content moves to the left by one tab

Moves the cursor in edit mode

[n]G: Positions the cursor at the beginning of the nth line

G: Position the cursor at the end of the file

gg: Position the cursor at the beginning of the file

Find in edit mode

/String: From the beginning of the cursor to the end of the file Find the string.

n: Repeat the last search command in the same direction

N: Repeat the last search command in the reverse direction

Common Last Line Mode Command

File Storage Class

:wSave current file

:w file Save current file as file

:q Exit vi

:wq Save current file, exit

:x Same as above

:q! Do not save the file and exit

Multi-line cut and copy in normal mode

Copyright © Windows knowledge All Rights Reserved