Vim note (6) -- a comprehensive introduction to vim, vim -- vim

Source: Internet
Author: User

Vim note (6) -- a more comprehensive introduction of vim (for example, vim -- vim)

Vim configuration file

~ /. Vimrc user's default configuration file ~ /. Vim/plugin/user's default script file storage directory ~ /. Vim/ftplugin/directory for storing script files of the user's default file type

 Programming support provided by vim

  Text Information (line number, file name, etc.) code indent syntax highlighting quick locating markup location full-text search complete multi-file editing multi-window editing function list file list function jump syntax incorrect character set encoding binary viewing

And so on...

Test vim

Run the vim command as root on the terminal to display the vim homepage.

: R filename reads the content of a file and writes it to the current editor.

Press I to enter the insert mode

After editing: w save

After editing, Press esc to exit insert mode and enter normal mode.

Enter sh to go to shell.

Compile and run

Text Information Configuration

Set nu (written to the configuration file. vimrc) displays the row number. Ctrl-g (use commands in normal mode) to display the file information and the current line. Statusline. vim (plug-in) adds the bottom status bar.

Code indent Configuration

Filetype on (written to the configuration file. vimrc) makes vim sensitive to the file type. Autocmd FileType c, cpp, h: setlocal cindent cinoptions =: 0, g0, t0 (written to the configuration file. vimrc) to set the c indent style. For details, see h cinoptions-values. Autocmd FileType c, cpp, h: setlocal et sta sw = 4 sts = 4 tabstop = 4 (written to configuration file. vimrc) sets the indentation distance to four spaces. = (Use commands in normal or visual mode) typographical code according to the indent style. <(Use commands in visual mode) indent to the left.> (Use commands in visual mode) indent to the right.

Syntax highlighting

Filetype plugin on (written to the configuration file. vimrc) the syntax highlighting plug-in for various languages has been added to the installed vim. You only need to open the plug-in related file types.

Quick Positioning

Gd (use commands in normal mode) jumps to the local variable definition. GD (use commands in normal mode) jumps to the global scalar definition. * (Use commands in normal mode) search for and jump to the word where the cursor is located. G * (use commands in normal mode) is similar to *, but the search target does not contain the \ <and \> word boundary symbols. # (Use commands in normal mode) search for and jump to the word where the cursor is located. G # (use commands in normal mode) function is close to #, but the search target does not contain the \ <and \> word boundary symbols.

Mark location

M {a-zA-Z0-9} (using commands in normal mode) makes a tag at the current position, marking a name that can use any character between a-z or A-Z, such as entering ma, is to mark the current position as. Note that a-z is a single file tag and cannot be used across files, while a A-Z0-9 is a global tag and can be used across files. '{A-zA-Z0-9} (use command in normal mode) jumps to the tag of this file. : Marks [{a-zA-z0-9}] (use command in normal mode) to view the content of the specified tag, view all without writing a tag number. : Delm {a-zA-z0-9} (use command in normal mode) to delete a tag.

Full-text search

: Vimgrep (use commands in normal mode) full-text search. The function is the same as the grep command, but supports multi-file jump location in vim. Usage: vimgrep Regular Expression file. Files support wildcards. For example, *. c Represents all. c files. If you want to perform recursive search, you can use **/* to search all files. : Cl listing result: cc (command in normal mode) Current result: cn (command in normal mode) next result: cp (command in normal mode) previous result: cw (use commands in normal mode) re-open the search result window

Multi-file editing

Vim f1 f2 ...... Fn (use commands in shell) to open multiple files. : E file name (use commands in normal mode) to open a new file in vim. : Ls (use commands in normal mode) list of all open files. : Bn (use commands in normal mode) to the next file. : Bp (using commands in normal mode) to the previous file. : B # Or ctrl-6 (using commands in normal mode) to the nearest previous file. Set autowriteall (written to the configuration file. vimrc) If you hate opening a new file every time, vim will require you to save it, you can set Automatic saving.

Multi-Window editing: Sp file name (command in normal mode) Horizontal Split Window (multi-line window ). : Vsp file name (command in normal mode) Vertical Split Window (Multi-column window ). Ctrl-w h (use commands in normal mode) move the cursor to the Left window. Ctrl-w j (use the command in normal mode) to move the cursor to the next window. Ctrl-w k (use commands in normal mode) move the cursor to the previous window. Ctrl-w l (use commands in normal mode) move the cursor to the right window. Ctrl-w + (use commands in normal mode) the current window size increases. Ctrl-w-(use the command in normal mode) the current window size becomes smaller. Ctrl-w o (use commands in normal mode) only displays the current window.

Function listTaglist. vim () List ins. Let Tlist_Use_Right_Window = 1 (written to the configuration file. vimrc). If you want to display the list on the right, add this configuration. The default value is left. : Tlist (use commands in normal mode) to display the function list. D (used in the taglist window) deletes files from the list. + (Used in the taglist window) Expand the file. -(Used in the taglist window) collapse the file. = (Used in the taglist window) collapse all files. X (used in the taglist window) shows or hides the normal window.

File ListNERD_tree.vim (plug-in) Horizontal Split Window (multi-row window ). Let NERDTreeWinPos = 'right' (written to the configuration file. vimrc). If you want to display the file tree on the right, add this configuration. The default value is left. : NERDTree (use commands in normal mode) to display the file list.

Function jumpCtags (software, which must be installed separately) software that generates multilingual tag files. Ctags-R *. c (use the command in shell) to generate the tag of all. c files in the current path.-R indicates recursion. : Ta tag or [g] ctrl-] list tags (multiple tags) or jump to tags (single tag ). Ctrl-t returns the upper level. : Tags: list tag stacks.

Syntax Error: Make (use commands in normal mode) executes the external make command, displays all compilation warnings and errors, and can be located in vim. : Cl listing result: cc (command in normal mode) Current result: cn (command in normal mode) next result: cp (command in normal mode) previous result: cw (use commands in normal mode) re-open the search result window

View binary files (Update Binary files to binary files in view of differences)

: Range! Xxd (use commands in normal mode) converts part of the specified range to the binary file reading mode. : Range! Xxd-r (use commands in normal mode) converts part of the specified range back to the character reading mode.

Character Set EncodingLet & termencoding = & encodingset fileencodings = UTF-8, gbk, and cp936 (written to the configuration file. vimrc) are supported by multiple character encodings. : Set fileencoding (use commands in normal mode) to set the file character encoding.

Supplement

Ctrl-p (use the command in insert mode) to jump out of the completion menu. Ctrl-n (after the completion menu is displayed) The next result. Ctrl-p (after the completion menu is displayed) the previous result. Ctrl-y (after the completion menu is displayed) Select the current result. Ctrl-x ctrl-f (use command in insert mode) file name completion. The header file contained in ctrl-x ctrl-I (use the command in insert mode. Ctrl-x ctrl-] (use the command in insert mode) ctags (described below) symbol completion. Ctrl-x ctrl-o (use the command in insert mode) omni completion, you need to set the omnifunc variable.

Other vim commands (refer to vi (vim) Tutorial)

Open, save, and close a file:

Vi filename // open the filename file w // save the file w vpser.net // save it to the vpser.net file q // exit the editor. If the file has been modified, run the following command: q! // Exit the editor without saving: wq // exit the editor and save the file

Insert text or line:

A // Add text I to the right of the current cursor position // Add text A to the left of the current cursor position // Add text I to the end of the current row // add text at the beginning (first line of non-null characters) O // create a new row on top of the current Row o // create a new row under the current row R // Replace (overwrite) the current cursor position and several subsequent texts J // merge the row where the cursor is located and the next row as a line (still in command mode)

Move the cursor:

Use up, down, left, and right direction keys

Command mode: h to left, j down, k up, l to the right. Space key to the right, Backspace to the left, Enter to the next line first,-to move to the previous line first.

Delete:

X // Delete the current character nx // Delete the n-character dd starting from the cursor // Delete the ndd of the current row // Delete the n rows including the current Row u // cancel the previous operation U // undo all operations on the current row

Search:

/Vpser // search for a vpser string under the cursor? Vpser // search for the vpser string n from the cursor // search for the previous search action N // search for the previous search action

Jump:

N + // jump n rows n-// jump n rows nG // jump to n rows G // jump to the bottom of the file

Set row number:

: Set nu // display row number: set nonu // undisplay the row number

Copy:

Yy // copy the current row to the cache, or use "ayy copy," a as the buffer, and a can be replaced with any letter from a to z, you can complete multiple replication tasks. Nyy // copy the n rows of the current row to the buffer. You can also use "anyy replication," a is the buffer, and a can also be replaced with any letter from a to z, you can complete multiple replication tasks. Yw // copy the characters starting from the cursor to the end of the word. Nyw // copy the n words starting from the cursor. Y ^ // copy the content from the cursor to the beginning of the line.

Y $ // copy the content from the cursor to the end of the row. P // paste the content in the clipboard after the cursor. If the preceding custom buffer is used, we recommend that you use "ap" for pasting. P // paste the content in the clipboard before the cursor. If you use the custom buffer above, we recommend that you use "aP for pasting.

Replace:

: S/old/new // replace the old: s/old/new/g that appears for the first time in the row with new // replace all old: n in the row with new, m s/old/new/g // use new to replace all the old values in the n to m rows: % s/old/new/g // replace all old files in the current file with new

Edit Other resources:

: E otherfilename // edit the file named otherfilename.

Modify the file format:

: Set fileformat = unix // modify the file to unix format. For example, ^ M will appear in the text file under Windows in linux.

Objective answer

C parameters are passed by value. One function of a pointer is to achieve similar reference effects. In addition, you can use a pointer to directly operate the memory!

Sun he explained:

Each thread has a fixed stack size. Generally, the stack of the main thread is usually 8 MB by default, and the memory is referenced by pointers. The stack memory is usually used and the stack is limited, it is also affected by the lifetime. Therefore, there are more scenarios where the heap is used than the stack. Some things have a long lifetime. If more than one function is called, The heap memory is used.

This article is intended to help you.

 

 

 

 

: Http://www.vim.org/scripts/script.php? Script_id = 273 the "Tag List" plug-in is a source code browser plug-in compiled for VIM. It must be supported by ctags. You can List functions, global parameter lists, and macros on the left. ( 1、download the taglist.zip file and decompress it to $ HOME /. under the vim directory or $ HOME/vimfiles or $ VIM/vimfiles directory, after this step, you should have these two files (the directory structure should be retained) plugin/taglist. vim-taglist plug-in file doc/taglist.txt-document (HELP) file 2. enter $ HOME /. run vim in command line mode in VIM/doc, $ HOME/vimfiles/doc, or $ Vim/vimfiles/doc ":Helptags. "Command to process the taglist help file. If you do not have this step, you will not be able to get the taglist help prompt 3. If the ctags tool is not in your PATH search PATH, you need to go to $ HOME /. in vimrc, set the Tlist_Ctags_Cmd variable to indicate the ctags path. 4. If you are running VIM of the terminal/console version and terminal does not support changing the window width, you need to change the window width at $/HOME /. vimrc sets the 'tlist _ inc_winwidth' variable to, restarts vim6, and you can use it in vim command line mode ":TlistToggle"To open/close the taglist window, you can use ":Help taglist"Command to get more information about using the taglist plug-in

 

 

Installation and Use of NERDTree
NERDTree from: http://www.vim.org/scripts/script.php? Script_id = 1658 A, install. 1. After decompression, copy the plugin/NERD_tree.vim file ~ /. Vim/plugin. Copy the doc/NERD_tree.txt file ~ Under/. vim/doc 2, open vim and load the document. : Helptags ~ /. Vim/doc/NERD_tree.txt for later help, as long as: h NERD_tree.txt. B. It is commonly used. 1. label. 1-1. Open a directory. : NERDTree ~ /Share/abc 1-2, mark it. : Bookmark your_mark_name_of_abc 1-3. Open this tag. : NERDTree your_mark_name_of_abc has the same effect as 1-1. 2. Quickly help the cursor to press? Key.

 

Remove highlight

Method 1: nohlsearch Method 2:/awertgvcxz (search for a string that certainly does not exist) after a highlighted search (: set hlsearch) is set, you can permanently disable the highlighted display by: set nohlsearch, you can also use nohlsearch to temporarily disable highlight. The highlight will be automatically restored during the next search.

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.