The use of Linux vim

Source: Internet
Author: User

Vim and Emac are the most popular two text editing tools in the Linux world, focusing on learning one, tentatively using Vim as the Learning object. In this article, some basic operations will no longer be introduced, only the most commonly used commands and settings, operating system Ubuntu 12.04.

Vim's default configuration is not to display line numbers, syntax highlighting, smart indentation and other functions, in order to better work, you need to manually set up a configuration file. VIMRC, which is typically placed in the user root directory, is used as a user-defined profile. /ETC/VIM/VIMRC is a global configuration file, modifying this file will change the vim configuration for all users.

Since it is an editor, the Chinese input method is also indispensable, click on the link to install Chinese input method.

  

Related configurations, you can refer to the powerful Vim configuration file to make programming more casual.

1. Common VIM commands

/PAT: Search forward Pat

? Pat: Search backward for Pat

Move the cursor to the word you want to search (variable name, function name, and so on), for example, test, and then press * (complete match the words below the cursor), VIM will automatically generate a complete search word for test. #为向上完整匹配光标下的单词.

x: Used to delete a single character

DD: Delete a row

Remove annoying ^m: text-editing files in different environments are interpreted differently for line breaks. DOS system, line terminator is \ r \ n, Linux, line terminator is \n,mac, line terminator \ r. Because of this difference, annoying ^m can occur when you edit a file in another system in one system.

U: Undo action from previous step

:(n,m) s/a/b (/g) replaces a with B, between the n~m rows. $s represents the last line

0: Move to the beginning of a line

$: Move to the end of a line

To open a file on a window on Linux, you can use the Dos2unix command to convert the file.

     

Debugging and compiling with VIM

Using Vim's Quickfix mode, you can start the compilation in Vim, if the compiler error, Vim will be based on the compiler output error message, automatically jump to the first error, after the modification, using shortcut keys, you can jump to the next error place, and then modify.

The principle of the Quickfix mode is to get information about the error from the compiler's compiler output information, save it in a list of locations, and then provide a series of commands to jump through the list of these locations.

In order to use Quickfix, you first define the command MAKEPRG that compiles your program,

Then execute: Make will compile.

When using: Make, VIM automatically calls the commands defined by the MAKEPRG option to compile and redirects the compilation information to a temporary file, and when the compilation error occurs, Vim reads the error message from the temporary file, forming the Quickfix list and jumping to where the first error occurred.

The commands that are often used in Quickfix mode are:

: CC                : HELP:CC ) : CP                : HELP:CP ) : CN                : HELP:CN ) : Cl                : Help:cl ) : CW                : HELP:CW ) : Col               : Help:col ) : Cnew              : Help:cnew )

Detailed reference points for this.

  

Problem Description:

When using the notebook keyboard, with VI in edit mode, when the upper and lower left and right, there is ABCD and add line.

Cause of the problem:

Vim is the upgrade version of the program, about the keyboard mapping above, the old VI for the small keyboard up and down will be interpreted as ABCD, the new version of Vim to be compatible with the old version VI script, added VIM compatibility mode, but now there is no need to use the VI compatibility mode.

Workaround:

Set in VI: Set NOCP revert to a mode that is incompatible with the old version vi, or add this command to the. VIMRC in the user directory set NOCP can resolve such problems.

The use of Linux vim

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.