Who said Vim is not an IDE? (3)

Source: Internet
Author: User
Tags autoload format definition
ArticleDirectory
    • Pathogen
    • Nerdtree
    • Command-T
    • Powerline
Common plug-ins

Vim has formed its own ecological environment because it has an open plug-in system. To improve development efficiency, developers have compiled tens of thousands of plug-ins for VIM. We can choose any one as needed, you can also develop your own plug-ins Based on the vimscript language.

Each plug-in is a script file suffixed with vim. The language for compiling the plug-in generally uses vimscript. Vimscript is owned by VIM.Programming LanguageWe will introduce it later. Although vimscript can do almost anything for VIM, there are still some scenarios where it is better and faster to use other languages. With this in mind, VIM developers have designed interfaces for other scripting languages to write Vim plug-ins, such as Perl, Python, and Ruby, we will demonstrate how to use python to compile the vim plug-in for the go language and execute goProgram.

There are four types of commonly used plug-ins:

    1. General Plug-In: applies to all types of files. When using vim, you can use the plug-in command to call out. For example, commandt, a plug-in used to quickly locate files, can be started using : commandt , and is applicable to any type. This type of plug-ins are generally stored in the. Vim/plugin/directory.
    2. file type plug-in: applies to files of specific types, such as C, Java, and XML. The plug-in function is enabled only when you edit a specific type of file. This type of plug-in is generally stored in the. Vim/ftplugin/directory. For example, we often use xmledit to edit XML, HTML, JSP, and other files. After this plug-in is installed, when editing the XML file, type , after is completed, xmledit automatically adds a closed tag for you. , if you enter the last >, the tag is automatically expanded to facilitate the input of sub-tags or text content. In this case, if you use Vim to open a TXT file, these functions will disappear. Of course, the xmledit function is far more simple than that. We will introduce it in detail later.
    3. syntax plug-in: as the name suggests, syntax plug-ins mainly provide syntax highlighting for programming languages, which are generally placed in. vim/syntax. Vim already provides syntax highlighting for most languages by default. For some newer languages, developers need to write plug-ins that support syntax highlighting, such as go language.
    4. compiler plug-in: Compiler plug-ins written in different languages are mainly used to set compiler options for relevant languages. For example, you can write compiler plug-ins for C, C ++, Java, Python, etc. The plug-in content is not complex and the main definition is "errorformat" (incorrect format definition) and "makeprg" (compile programs and parameters. You can use : Make to compile the files being edited.

After learning about the basic concepts of VIM plug-ins, it is easier to understand these commonly used plug-ins.

Pathogen

We will first introduce the plug-in pathogen for managing the plug-in.

1,

Https://github.com/tpope/vim-pathogen

2. Function Description

A plug-in package usually has multiple functions. Each file is placed in a different directory according to the vim path Convention. The General Plug-in is placed under plugin, And the syntax highlighting plug-in is placed under syntax, automatically load the plug-in under autoload, put the file type plug-in under ftplugin, and put the encoding format plug-in under indent ...... if you are a heavy plug-in user, you will find in. there will be a bunch of folders in the vim main directory. Whether you want to install new plug-ins or delete old plug-ins, It is very troublesome. You have to find the relevant Vim files in each folder.

Pathogen is a plug-in for managing plug-ins. It is mainly used to solve the above problems. Pathogen uses the bundle concept to manage plug-ins. If you are familiar with osgi or OS X, you will not be unfamiliar with bundle. Osgi encapsulates Java programs and resource files in the form of bundle, while most applications in OS X are bundle. It is the concept of bundle that enables osgi to dynamically manage Java components, most of OS X installation programs are "Green installation ".

Pathogen. VimCreate a bundle file in the directory. All plug-ins are managed in the directory. When Vim is started, it will automatically execute the vim script in the folder contained in the runtimepath (RTP) List. pathogen will./Vim/bundleThe plug-ins in the folder under are recursively loaded to RTP in a certain order, so that the plug-in managed by pathogen takes effect when Vim is started.

With pathogen. VimThere are only three folders in the folder: autoload, bundle, and Doc. Other ins will be installed in the bundle Folder ,:

Unless otherwise stated, all the plug-ins mentioned later are installed using the pathogen method. I will use the nerdtree plug-in as an example to describe the installation method.

3. Installation
    1. In. VimCreate the autoload and bundle directories under the folder
    2. Obtain the pathogen. Vim file and copy it to the autoload directory.
    3. In. VimrcAdd the followingCode:

      Call pathogen # infect ()
4. Instructions for use

None

5. Notes

After the new plug-in is installed in the bundle directory, if the plug-in contains doc, run: HelptagsTo generate online help tags.

Nerdtree

When we introduced pathogen, we used a figure to show the directory structure of the plug-in, which was implemented based on the nerdtree plug-in.

1,

Https://github.com/scrooloose/nerdtree

2. Function Description

Nerdtree is one of the most common plug-ins in Vim. It can display directories and file structures when running vim, similar to the file browser on the left side of textmate, but it is more convenient to operate, you can quickly browse files without leaving the keyboard and switch between files and folders.

3. Installation
    1. Enter. Vim/bundleDirectory
    2. RunGit clone git: // github.com/scrooloose/nerdtree.git
    3. After the download is complete, a folder named nerdtree will be added under the bundle. All the related plug-ins are in this folder.
    4. Run in VIM: HelptagsTo generate online help tags for nerdtree
4. Instructions for use

Open vim and enter: NerdtreeTo call out the file directory in the current directory where the vim command is executed. For ease of use, I have defined the shortcut key in. vimrc. You can use Ctrl + T to open the nerdtree, And you can define the shortcut keys you are used.

Nerdtree provides a variety of keyboard operations to browse and open files. I will briefly introduce some common shortcut keys:

 
Like editing a file, move the cursor through h j k l to locate o to open or close the file or directory. If it is a file, the cursor appears in the open file and the go effect is the same as above, however, the cursor remains in the file directory. Similar to the preview function of the file content, I and s can be split horizontally or vertically to open the file, previously added G-like go function T Open t in the tab t open P to the upper directory P to the root directory K to the first node J in the same directory to the last node in the same directory M Displays the file system menu (add, delete, and move operations )? Help Q close

For more operation methods, can I use? View Detailed Help information.

Command-T 1,

Https://wincent.com/products/command-t

2. Function Description

Command-T is a plugin for Fast File Browsing Based on Ruby and C extensions. It is similar to textmate's go to file (command + T outbound) function, or eclipse's open Resource (command + Shift + r) function, you can quickly locate and open the file through fuzzy match.

3. Installation
    1. Download the VBA file from the latest version, the latest version is 1.4, so the installation file is a command-t-1.4.vba
    2. In~ /. Vim/bundleCommand-T
    3. Open command-t-1.4.vba with vim
    4. Run: Usevimball ~ /. Vim/bundle/command-T
    5. Go to the ruby directory and compile the C extension.

      Cd ~ /. Vim/bundle/command-T/Ruby/command-T Ruby extconf. RB make
4. Instructions for use

Input: commandt to go to the file quick locating function ,:

    1. CTRL + J/K select files up and down, select files, and press enter to open the file
    2. CTRL + t open the file as a tab
    3. CTRL + S/V can open files in a horizontal or vertical split window
    4. CTRL + C Exit this mode

This plug-in also has a common command,: CommandtbufferYou can browse the buffer file and open it again. The operation method is the same as above.

5. Notes

The Vim version must support Ruby extensions. We can enter: Ruby 1Check ifE319: Sorry, the command is not available in this versionIs not supported.

If the above problem occurs, we need to compile Vim that supports Ruby by ourselves. If it is too troublesome, we can directly install vim-NOx with Ruby support. The installation command in Ubuntu is as follows:Sudo apt-Get install vim-NOx.

RunRuby extconf. RbIf the mkmf package cannot be found during the command, you need to install the ruby-dev package. The installation command in Ubuntu is as follows:Sudo apt-Get install ruby1.8-Dev.

Powerline 1,

Https://github.com/Lokaltog/vim-powerline

2. Function Description

Powerline is a very beautiful status bar plug-in of VIM. After Powerline is installed, an enhanced status bar will appear at the bottom of VIM. When Vim is in normal, insert, block, and other States, the status bar shows different colors, and the status bar also displays the current editing file format (uft-8, etc.), file type (Java, XML, etc.) and the cursor position, like to install.

:

3. Installation
    1. Enter. Vim/bundleDirectory
    2. RunGit clone git: // github.com/lokaltog/vim-powerline.git
    3. In. VimrcSet the status bar topic

      "Powerline {set guifont = powerlinesymbols \ for \ Powerline set nocompatible set t_co = 256 Let G: powerline_symbols = 'fancy '"}
4. Instructions for use

After the installation, open Vim again and you will find that there is a colored status bar at the bottom.

the fourth article is about ctags, taglist, foldmethod, xmledit, visualmark, and vim-markdown, the fifth part is about Python and go plug-ins, the sixth part is about Vim programming skills, and the seventh part is ......

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.