VIM usage skills

xiaoxiao2021-03-06  36

(Reprint): vim tips Posted by cnyifeng in 2002/9/26 04:35:25 (3023 read) Author: a wind (Lanzhou University high-performance computer lab cnyifeng@263.net) would have to write what you want Daquan , But I thought about it, I feel that I've written it, I have no sense, so I decided to write a skill, I will have a row, if you have discovered this there is no skill, you can contact I put your skills, in fact, Vim's use is the same as the use of Emacs, but everyone tends to use one of them and degrading the additional one. It does not make each other, it is like a family. Out of two factions, what is this? I only use Vim, more than Emacs, I just try it, I can only say that Emacs is not suitable for me, but I don't object to others. Ok, let me talk about it, let me know the skills: Note: Anyone who is extracted from other articles will indicate the source, to indicate the name I will write 1: In Vim, you want to edit it. File simple encryption 2: Repeat Enter the same character 3: Place the line number in the file 4: Insert the file name into the file 5: Write the C / C program with Vim 6: Automatic complement 7: Sort by a text 1: In VIM, simply encrypt the edited file in VIM, simply encrypt the edited file, you can type ": x" in command line mode, then enter the password string when prompted "Enter the Encrypt Key" It can be encrypted. But don't forget to save! It will be found in the bottom of the screen with "[Crypted]" in the bottom of the screen. Next time you open the encrypted file, you will ask you to enter the mouth string. 2: Repeat the same character, we may want to enter the same character multiple times, Vim's insert function can complete this work command 80i = ^ ESC can enter 80 characters =, of course, 80A = ^ ESC can also Complete the above functions. Note: The ^ ESC here is the ESC button on the upper left side of the keyboard. 3: In the file in the file, we sometimes want to place the line number into the file, while the Vim provides the function: SET NU can only display the line number, can not edit or place it into the file, the following macro Command script row_num.vim can complete this feature. :% s / ^ / ^ I / Row of each line Add a Tab character: $ 到 文件 文件 行 行: Let end = line ("." Last line number ==> Variable End, function line function It is the line number of the designated line, and the parameters "." Indicates the current line: 1 to the first line of the file "----------------------- -----------------: Let Num = 1 1 ==> Counter: while num <= end: let line = getLine (".") Take the front of the content == > Variables line: let line = substitude (line, $, num, "") In front of the variable line: Call setLine (".", Line) Write the contents of the variable line back to the current line: down One line: Let Num = Num 1 counter plus one: endwhile loop execution until the end of the file "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ 4: Insert the file name inserted in the editing state, use Ctrl R% to enter the file name you are editing. 5: Write the C / C program vi with VIM is the most common text editor under Unix.

Vim (VI Improved) is its enhancement. Some people often take VIM and Emacs, VIM, although there are so many features like Emacs, but more convenient than Emacs. People who have used Emacs will definitely feel annoyed for some shortcuts of Emacs, sometimes I want to have eight hands. Vim's learning curve is not as long as Emacs, just look at VIM's own vitutor, approximately 20 minutes to master VIM usage. For the C / C programmers under UNIX, I recommend you to write programs using the combination of Vim CTags. Among them, I listened to me slowly. (The introduction of VIM below is mainly for version 5.6) VIM supports the language-making guidance and automatic indentation VIM will automatically set syntax according to the number of files, such as: *. C, *. CPP, *. CC, etc. Syntax highlighting. Some reserves in C / C , such as: if, for, incrude, etc., there will be different colors, which will reduce the possibility of programmers to make mistakes. It is relatively easy to read the program. Use the following command to view help from VIM: ": h syntax", ": h syn-qstart", ": h syntax-printing". Vim also supports automatic indentation according to the GNU, so that the code written by the programmer is more readily read, and it is also conducive to the cultivation of programming style. Use the following command to view the help of automatic indentation in VIM: ": h cindent", ": h cinoptions", ": h cinoptions-value", ": h cinkeys", ": h cinwords". Use the CTAGS program with the CTags Vim. Although CTAGS can also support other editors, it officially supports only VIM. CTags can help programmers easily browse source code. Use the following command to create a "tags" file in the root directory of the source code: [/ home / brimmer / src] $ ctags -r "-r" means recursion creation, which includes all subdirectory in the source code root directory. The source program is below. A list of "tags" files include these objects: l Definition of the value L function of the macro L enumeration variable defined by #define, prototype, and declared L name space (Namespace) L variable (including definition And Statement) L-class, structure (STRUCT), enumeration type (ENUM), and Union (UNION) L class, structural and joint member variables or functions Vim use this "tags" file to locate these tags Object, hereby introduce how to locate these objects: 1) Use the command line. Plus "-t" parameters when running Vim, for example: [/ home / brimmer / src] $ Vim -t foo_bar this command opens the file defining "foo_bar" (variable or function or other), and positions the cursor Go to this line. 2) The most convenient way to use the ": ta" command in the VIM editor, for example: Ta foo_bar 3) is to move the cursor to the variable name or function name, then press "Ctrl-]. Return the original place with "Ctrl-O". Note: When running VIM, you must run in the directory where the "tags" file is located. Otherwise, use the ": set tags =" command to set the ": set tags =" command when running the VIM, so that VIM can find the "Tags" file.

Quickly correct the error in the Vim editor to compile the program with ": make", of course, the premise is that there is a Makefile file in the current directory. After running ": make", if there is an error in the program, it will be displayed. At this time, the cursor will automatically point to the first place, and you can also see the wrong prompt. Then, you can correct the mistake without manually finding the wrong line. Remember the following useful commands: L ": CL" List the error L ": CN" Let the cursor point to the next error L ": cp" Let the cursor point to the upper error L ": CNEW" starting from the beginning. You can even let you Vim recognizes other compilers instead of the GCC error prompt. This is useful for programmers for developing embedded systems because they are likely to use not GCC but other compilers. By setting the value of "ErrorMMAT", you can identify the error prompt of the compiler. Because different compilers' error prompts are different, if it is not used to be GCC, it is necessary to reset. The value of "errorformat" is a string, its format and the SCANF of the C language acquaintance. The value of GCC's "ErrorMMAT" is:% F:% L: /% M. Where "% f" indicates that the file name, "% L" represents the line number, "% m" indicates an error message. Use ": h errormat" to view detailed help information. Use ": H Quickfix", ": h make", ": h makeprg", ": h errorfile" to view other information. Useful shortcuts The following shortcuts are very helpful to programmers: Move cursors in the function [[Go to the previous "{"]] to the next "{" {transfer in the first column Go to the previous space} to the next idlk GD to the local variable of the current cursor, * Go to the word next appearance of the words referred to in the current cursor # to the previous cursor fingers Local parentheses matching% of parentheses, brackets and braces matching. It depends on what the current cursor points to what symbols. Other VIM profiles are ".vimrc", use this file to configure VIM. Vim's graphical interface is called GVIM. Vim also has a version used for Windows platforms. Copyright Description This skill is copyrighted by the author brimmer (brimmer@linuxaid.com.cn) and www.linuxaid.com.cn. 6: Automatically supplement this skill in your writing program is very useful, use Ctrl n in editing state, of course, you must first enter a small part of the front, if you can't use Ctrl n to choose Correct match, when your program variable is very long, this command is very useful. 7: Sort by a text, for example, the following paragraph Version.o pch.o getopt.o util.o getopt1.o inp.o patch.o backupfile.o you want to sort them, according to the alphabetical order Several people can do: A: Move the cursor to the row B: Use the MA flag to change behavior AC: Move the cursor to the last row D: Use the command "! 'Asort" to complete the sort (attention These steps are done in non-input mode.) Explain the various purposes below. "!" Indicates that the command will be executed, "'a" indicates the line from the current channel flag,' sort 'is the execution instruction.

转载请注明原文地址:https://www.9cbs.com/read-62324.html

New Post(0)