Record some simple and practical Vim usage

Source: Internet
Author: User

Lsof-I: 6789

Check which processes occupy port 6789

1.

Suppose there is such a sentence # include "sockettask. H"

If you want to view the file content, place the cursor above and enter the command GF ~ Note

 

 

2.

: Q: Quit. Q: What? Is to view the input command history

 

 

3. Register command

 

Run the Q command, followed by the register name (A is assumed to be a), to start recording your command input, and finally enter Q to end the Command record;

Use @ A to repeat the command you just recorded

 

 

4. CTRL + D Ctrl + U is the half screen, while Ctrl + B Ctrl + F is the whole screen.

 

 

5. h move the cursor to the first line of the screen

M moves to the middle row

L move to the last row

 

 

6 VI-r file or View File. open the file only.

 

 

7. Restore deletion: each time you delete some content, the content is saved in the buffer zone. There are a total of 9 such buffers, and the recently deleted ones are saved in the buffer zone 1.

"The 2 p command is to paste the content of Buffer 2. Note that there is a quotation mark before it.

 

 

8. copy to the buffer: "There is a quotation mark before dyy. Copy the current row to the D buffer." DP paste the content of the d buffer.

"A7yy copies the current seven rows to buffer.

 

 

9 bookmarks: The MX command name the current position as bookmarks X, and X is any letter. 'X' is to locate bookmarks x

 

 

10 In Colon mode:/pattern/d to delete a matched row

: G/pattern/d delete all matched rows

 

 

11 edit multi-file VI file1 file2

: N switch File

 

 

12 another method of copying and pasting

: 1, 5ya a copy the first 5 rows to buffer

: PU a paste the content of buffer

 

 

 

13 confirm upon replacement

: 1, $ S/old/new/GC

 

 

 

14 characters not used in command mode: g k q v

Consider the letters when using map.

 

 

 

15: set list

The tab in the text is displayed as ^ I, and the ending character is displayed as $

 

 

 

16. Keyword auto-completion

) CTRL x + ctrl L, find a matched line in this file, and automatically complete

) CTRL x + ctrl N, find a matching keyword in this file, and automatically complete

) CTRL x + ctrl I, find a matching keyword in this file and the include header file, and automatically complete

) CTRL x + ctrl P, search for a matching keyword in this file, and automatically complete

) CTRL x + ctrl F, find a matching file name, and automatically complete

) CTRL x + ctrl D: Find the matching macro definition in this file and the include header file, and automatically complete

 

Is to move to the first letter of the word, and E is to move to the end of the word. The letter minus sign is to move to the first line of the previous line.

 

DG deletes from the cursor position to the end of the file,

Copy YG from the cursor position to the end of the file

 

 

18 visual mode

V enters this mode. Aw selects a word;

In visual mode, commands in command mode are still useful ~

 

////////////////////

Vim Manual

1. Quick Start *: syn-qstart **: syn-enable **: syntax-enable:        :syntax enableIn fact, it only executes the following command        :source $VIMRUNTIME/syntax/syntax.vimIf the vim environment variable is not set, VIM tries to find the path using other methods (see | $ vimruntime | ). You can always find it. If not, you can set the vim environment variable as the directory where the vim-related files are stored. For example, if your syntax file is in the "/usr/Vim/vim50/syntax" directory, set $ vimruntime to "/usr/Vim/vim50 ". Before starting vim, you must set it on the shell. *: Syn-on **: syntax-on * ": syntax enable" command keeps your current color settings. In this way, you can use the ": highlight" command to set the color you like before and after using this command. If you want Vim to overwrite your own by default, you only need to use:        :syntax on*: Hi-normal **: highlight-normal * if you are running in the GUI environment, you can get a black white text:        :highlight Normal guibg=Black guifg=WhiteFor more information about the color terminal, see |: Hi-normal-cterm |. For how to set your own syntax coloring, see | syncolor |.Note:: MS-DOS and syntax files on windows<CR><NL>End each row. On UNIX<NL>End. This means you need to select the appropriate file for your system. However, on MS-DOS and windows, if the 'fileformats' option is not empty, the correct format is automatically selected.Note:: When you use reverse video ("gvim-FG white-BG black"), the default value of 'background' is not set until the GUI window is opened. This occurs after | gvimrc | is read, and the default highlighted error is used. To set the default value of 'background' before enabling highlight, the following command is contained in the | gvimrc | file: ": Gui:: Gui "opens the window and sets the default value of 'background': Syntax on "enable syntax highlighting, use 'background 'to set the colorNote:: Use ": Gui" in | gvimrc | means "gvim-F" will not be opened on the front-end! In this case, you must use ": Gui-F ". You can use this command to switch the opening/closing of the syntax   :if exists("syntax_on") | syntax off | else | syntax enable | endifTo put it in the ing, you can use:   :map <F7> :if exists("syntax_on") <Bar>        /   syntax off <Bar>        / else <Bar>        /   syntax enable <Bar>        / endif <CR>[Use | <> | note method, input according to the original meaning] Details: the ": Syntax" command is implemented using an execution File Script. To understand what it has done, check the following files:Command file: Syntax enable $ vimruntime/syntax. VIM: syntax on $ vimruntime/syntax. VIM: syntax manual $ vimruntime/syntax/manual. VIM: syntax off $ vimruntime/syntax/nosyntax. see also for VIM | syntax-loading |.
2. Syntax file *: syn-files * the syntax and highlight commands of a language are usually stored in a syntax file. The naming convention is :"{name}. Vim ". Where,{name}Is the name or abbreviation of a language (once in the DOS file system, the name limit of 8.3 characters must be applied ). For example, the C. Vim Perl. Vim java. Vim html. Vim CPP. Vim Sh. Vim CSH. Vim syntax file can contain any ex command, just like the vimrc file. However, only commands applicable to specific languages should be placed in it. If the language is a superset of another language, it can contain files corresponding to that language. For example, CPP. Vim can contain the c. Vim file:   :so $VIMRUNTIME/syntax/c.vim. Vim files are usually loaded using automatic commands. For example:   :au Syntax c     runtime! syntax/c.vim   :au Syntax cpp   runtime! syntax/cpp.vimThese commands usually appear in the $ vimruntime/syntax/synload. Vim file. If you have multiple files, you can use the file type as the directory name. All "*. Vim" files in this directory will be used. Example :~ /. Vim/after/syntax/C/One. Vim ~ /. Vim/after/syntax/C/Two. vim creates your own grammar file * mysyntaxfile *. Once you create your own syntax file, VIM automatically calls it when using ": syntax enable, perform the following operations: 1. create your own user runtime directory. Generally, place it in the first item of the 'runtimepath' option. UNIX example:        mkdir ~/.vim2. Create a "Syntax" directory. On Unix:        mkdir ~/.vim/syntax3. Compile the vim syntax file. Or download from the Internet. Then write it to your syntax directory. For example, for the syntax of the "mine" language:        :w ~/.vim/syntax/mine.vimNow you can manually start the syntax file:        :set syntax=mineIn this case, you do not need to exit vim. If you want Vim to detect the file type, see | New-filetype |. If you want to set up a system for multiple users without adding the same syntax file to each user, you can use other directories in 'runtimepath. Add the existing syntax file * mysyntaxfile-add *. If you are satisfied with the existing syntax file, simply add or modify some highlighted items. follow these steps: 1. create a user directory in your 'runtimepath. 2. Create the directory "after/syntax ". On Unix:        mkdir ~/.vim/after        mkdir ~/.vim/after/syntax3. Write a Vim script that contains the commands you want to use. For example, to change the color in the C Syntax:        highlight cComment ctermfg=Green guifg=Green4. Write the file into the "After/syntax" directory. Use the name of the syntax and add ". Vim ". For our c Syntax:        :w ~/.vim/after/syntax/c.vimThat's all. The next time you edit the c file, the Comment color will not be the same. You don't even need to restart vim. Replace the saved syntax file * mysyntaxfile-replace * if you do not like the version of the published syntax file, or you have downloaded the new version. You can use the preceding steps | mysyntaxfile |. Make sure that the syntax file you write is in the 'runtimepath' location earlier. Vim only loads the first found syntax file. Naming Conventions * Group-name ** {group-name} ">{group-name}The ** e669 ** W18 * highlight or syntax group name must contain ASCII letters, numbers, and underscores. For example, using a regular expression: "[a-zA-Z0-9 _] *". To allow each user to select their preferred color series, many languages should use the same highlight group name. The following is the recommended group name (if syntax highlighting works correctly, you should be able to see the actual color, except for "Ignore ): * Comment v any comment * constant v any constant string v a String constant: "This is a string" character v a character constant: 'C', '/N' number v a numerical constant: 234, 0xff Boolean v a boolean constant: True, false float v a floating point constant: 2.3e10 * identifier v any variable name function V function name (including the method name of the Class) * Statement V any statement such as conditional V if, then, else, endif, switch, repeat V for, do, while, label v case, default, operator v "sizeof", "+", "*" and other keyword v any other keywords exception v try, catch, throw * preproc v universal preprocessing command include v preprocessing command # include define v preprocessing command # define macro V is equivalent to define precondit v pre-processing commands # If, # else, # endif, etc. * Type V int, long, Char, and other storageclass v static, register, volatile, and other structure V struct, union, Enum, and other typedef v A special character tag v in a typedef * Special v constant of any special symbol specialchar V can be used hereCTRL-]Delimiter V needsNote:Special Character debug v debugging statement * underlined V needs to highlight the text, HTML link * ignore v left blank, hidden * error v any wrong construction * todo v any special needsNote:Mostly the names marked by the todo fixme and xxx * keywords are the main group, while others are the secondary group. For the main group, the "syntax. Vim" file contains the default highlight settings. The secondary group is linked to the primary group. Therefore, they have the same highlight settings. However, you can use the ": highlight" command to change the default values of all groups after the "syntax. Vim" file.Note:The name of the highlighted group is case insensitive. "String" and "string" can be used to represent the same group. The following names are reserved words and should not be used as group names: None all allbut contains contained
Highlighted colors:
If you do not have the root permission, copy C. Vim ~ Under the. Vim/syntax directory.
Highlight Function Name:
syn match cFun display "[a-zA-Z_][a-zA-Z_0-9]/{-1,}/s/{-0,}(/{1}"ms=s,me=e-1                                                   hi def link cFun Special
Highlight a valid identifier:
syntax match cUserword display "/<[a-zA-Z_][a-zA-Z_0-9]*/>[^(]"ms=s,me=e-1highlight def link cUserword Comment
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.