Vim Plug-in Installation

Source: Internet
Author: User
Tags autoload mkdir parent directory sorted by name centos git clone

Reproduced a VIM plug-in installation strategy

Original source: http://littlewhite.us/archives/212


C + + is the highest proportion of the programming language, and Vim is designed for the programmer to develop the editor, when the combination of the two will bring us what effect.

For users who do C + + development on Windows, vs for them to do a lot of work, syntax highlighting, automatic indentation, smart tips, and so on, when you happy use VS, please remember that this is a billing software, although in my greater China is widely used in Microsoft's pirated software, But as a programmer we should know that this is not the right behavior, and then go----------------------------------------

Vim plugin Installation tutorial on the Internet has been countless, but the quality is also uneven, many are reproduced in other places copy, and did not specify the use of the environment, many people found unable to install the work, and finally make a mess, today the purpose of this article is only two: 1, make installation simple; 2. Guaranteed to work.

The premise of reading this article is that you have at least used vim to know the basic operation. The following is the beginning of the topic. Installation Environment CentOS Release 6.3 (Final) VIM 7.2

This article's plug-in installation in the above environment, incidentally will also mention the installation of other platforms. preparatory work

Since most vim plug-ins can be found on the GitHub, and the installation, removal, and upgrade of the plugin via git are extremely simple, we need to first install the Git tool, and if you don't know git and GitHub, you can start by Google

CentOS Installation

sudo yum install git

Ubuntu installation

sudo apt-get install git

Mac installation
Since the Mac does not have the same package management tools as Yum and Apt-get, a similar package management tool needs to be installed first, which is a very helpful installation package management tool for installing some Linux commands homebrew

Ruby-e "$ (curl-fssl https://raw.github.com/Homebrew/homebrew/go/install)"
Installing Git through brew
Brew Install Git

I will need to install the plugin and configuration files on the GitHub, if you do not want to bother to understand the installation of each plug-in, you can directly download all plug-ins to use, the project address Https://github.com/handy1989/vim, You can back up and install all plug-ins at once by following these commands (note that the ls-a is hidden from the vim directory downloaded from git, and can be viewed)

MV ~/.VIMRC ~/.vimrcbak
mv ~/.vim ~/.vimbak
git clone https://github.com/handy1989/vim.git
mv VIM/.VIMRC Vim/.vim ~/
First plugin

In order not to let the plugin after the installation of the directory appears messy, we are very necessary to install a plug-in management plug-ins, so that the function of several plug-ins, here only recommend a pathogen

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

Installation
You can install it through git, or you can download the plugin file directly, because this plugin has only one file, we choose the latter, and the plugin's documentation is also used in this way.

Mkdir-p ~/.vim/autoload ~/.vim/bundle && 
curl-lsso ~/.vim/autoload/pathogen.vim Https://tpo.pe/pathogen.vim

Then, there is no then, the plugin is finished. Does it feel so easy! But don't worry, we have to do some configuration of plug-ins, with vim open ~/.VIMRC, enter the following three line class capacity

Execute pathogen#infect ()
syntax on
filetype plugin indent on

Save exit, this plug-in installation configuration is completed, how to verify that the plug-in has not been effective, do not worry, there are opportunities to verify the latter. Let's start by talking about what a vim plugin is.

This is what your ~/.VIM directory structure should be like.

├──autoload
│└──pathogen.vim
└──bundle

Visible ~/.vim Directory is there are two directories, where AutoLoad put is the pathogen plug-in, the so-called plug-in is actually a script, when Vim starts, it will automatically load the ~/.vim/autoload directory script, because you ~/. VIMRC is configured with execute Pathogen#infect (), so it's going to automate the execution of this function in the script, and as to how this function is implemented, we don't have to worry about it, so the function is to load all the plugins you've installed in the ~/.vim/bundle directory. , pathogen management method is roughly like this, and we also see that the Vim plug-in is actually a script file, a bit richer will have a description of the document and other content, and then we met to explain. Auto-pairs

Project Address
Https://github.com/jiangmiao/auto-pairs (interested to see)

Function
Automatically match parentheses, quotes, and more

Installation

git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs

This will download the Auto-pairs project file on GitHub to the ~/.vim/bundle/auto-pairs directory

Test
Open a file randomly, enter the opening parenthesis ' (', see if the right parenthesis is automatically appearing, and then remove the left parenthesis and see if the right parenthesis is also deleted. Of course, the function is far more than these, but commonly used on these points. Nerdtree

Project Address
Https://github.com/scrooloose/nerdtree

Function
Show Directory tree

Installation

git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle

At this point ~/.vim/bundle/nerdtree should have the following directories and files

AutoLoad
Doc
lib
nerdtree_plugin
plugin
readme.markdown
syntax

These directories are the VIM default plug-in directory, if we do not load plug-ins through the pathogen, we need to create the corresponding directories in the ~/.vim directory, and the nerdtree corresponding files to the corresponding directory, so that each directory will place multiple plug-ins content, such as ~/. Vim/doc will be placed in all the plug-ins of the group of documents, and we manage through the pathogen, the contents of each plug-in are placed in the same directory, such as the contents of the Nerdtree plug-ins here we downloaded to the ~/.vim/bundle/nerdtree, Delete this directory directly to remove the plugin, if the subsequent plug-ins are updated, in this directory through the git command can also be easily updated to the latest version.

Open vim, enter in command line mode: helptags to load the Help group document of the plug-in, or use: helptags help_dir load the group document of the specified directory, where Help_dir is the directory where you need to load the plugin help group documents, such as this is ~/.vim/ Bundle/nerdtree/doc

Test
Use VIM to open a file, enter in the command line mode: Nerdtree, and then return, the window left the VIM working directory tree appears, as shown in the following figure

Place the cursor in the Nerdtree window and press '? ' To view help, the Nerdtree operation is simple, usually put the cursor on a directory/file, through a button to operate, listed below a few common buttons and their corresponding operations

File-related Actions
o  : Open the file in the previous window where the cursor is located and place the cursor in the newly opened window go
: Preview file with cursor resting in nerdtree window
T  : Open File in new tab and activate
GT: Open file in new tab, cursor left in nerdtree window
i  : Horizontal split Open file
GI: Horizontal split preview
s  : Vertical split Open File
GS: Vertical split preview

directory tree related operations
o  : Expand/Close Directory
o  : recursively expand directory. Use caution, if there are more directory levels, it will be slow to open
x  : Close parent directory
C  : Toggle cursor directory to root
u  : Toggle directory tree root directory for upper directory
u  : Toggles the root of the directory tree to the upper directory and keeps the state of the old directory tree
R  : Refreshes the current directory
R  : Refreshes the current root directory (which is used after the new file is added)
CD: Switch the VIM working directory to the directory where the cursor is located (Command mode: PWD can view the current working directory)

To facilitate the opening of the Nerdtree, we can set the shortcut key, open the ~/.VIMRC, insert the following line

Map <C-n>:nerdtree<cr>

This way, when you turn on VIM, just enter CTRL + N to open nerdtree minibufexplorer

Project Address
http://www.vim.org/scripts/script.php?script_id=159

Function
Display the Open buffer

Installation
In the 6.3.2 version, for example, the corresponding version of the download link can be found according to the project address

Mkdir-p ~/.vim/bundle/minibufexplorer/plugin && wget "http://www.vim.org/scripts/download_script.php?src_ id=3640 "-O ~/.vim/bundle/minibufexplorer/plugin/minibufexpl.vim

Test
Using VIM to open a file, you can not see the Minibufexplorer window, because the default is only a buffer does not display the window, in the command-line mode through: VSP filename open another file (or with Nerdtree browse open other files), See if there is a minibufexplorer window at the top of the window, as shown below

Let's explain what's called Buffer,vim. Creates a buffer for each open file, which is stored in memory for fast loading the next time the file is opened, such as we browse through the Nerdtree and open multiple files, even if some of the files you quit editing, Its buffer is still there, in the command mode, we enter: LS can see the open buffer list, each line before the number corresponding to the number of buffer, by input: b N, where n represents the buffer number, you can open the corresponding buffer. corresponding to the screenshot above, we opened two files, at this time minibufexplorer window shows two buffer, even if we close a file, the two buffer still exist, the cursor moved to the name of a buffer, carriage return can open the corresponding buffer, Press D to delete the buffer, the specific operation can directly read the plug-in file, the path for ~/.vim/bundle/minibufexplorer/plugin/minibufexpl.vim

Configuration
Add the following command to the ~/.VIMRC file

Let G:minibufexplmaxsize = 2

This configuration means that the maximum height of the Minibufexplorer window is 2 rows, the default is no limit, you open enough buffer, one will continue to grow, in order to facilitate reading I generally set it to 2, other configurations are not used, need to use when you can refer to the plug-in file, and in ~/. Add configuration ctags+taglist+omnicppcomplete in VIMRC

Next to the blockbuster, front is just some of the basic operation of the window, is to facilitate the browsing of files, we read C + + code to be able to quickly locate functions, variables, similar to VS and other functions provided by the IDE Ctags

This is not a plug-in, but executable program, is used to index the code, easy to find, some Linux version is ctags, if not, install as follows

sudo yum install ctags

Ubuntu Installation Method

sudo apt-get install Ctags

Mac is also ctags, but that's not easy to use and can be reinstalled

Brew Install Ctags

If the installation fails, see if it is because the/usr/bin/ctags file already exists, you can go first MV and then execute

To create an index: in the root directory of your code, execute the following command, will generate a tags file, at this time in the code root directory to open a file (vim default only load working directory tags file), put the cursor on a function or structure name, press ctr+] can jump to the definition of the name, If multiple options appear, you can enter a number to select the corresponding jump place, press Ctr+o to return to the position before the cursor

Ctags-r--sort=yes--c++-kinds=+p--fields=+ias--extra=+q--language-force=c++
TagList

TagList is a vim plug-in, can be the code within the functions, variables, etc. by law, easy to find

Download Address
http://www.vim.org/scripts/script.php?script_id=273, or download and install directly as follows

CD ~/.vim/bundle && wget "http://www.vim.org/scripts/download_script.php?src_id=19574"-O taglist.zip & & Unzip taglist.zip-d TagList

This generates the ~/.vim/bundle/taglist directory, which is structured as

TagList
├──doc
│└──taglist.txt
└──plugin
    └──taglist.vim

Where the plugin directory is the plugin file, the doc directory is the description document. Turn on VIM and enter it in command-line mode: Helptags ~/.vim/bundle/taglist/doc can load a description document and enter Help Taglist.txt to display a description document

Configuration
Open ~/.VIMRC and enter the following

Let Tlist_show_one_file=1    "only show a file of taglist let
tlist_exit_onlywindow=1  " When TagList is the last window to automatically exit let
Tlist_use_right_window=1 "On the right Display taglist window let
tlist_sort_type=" name "   " tag sorted by name

These lines of configuration look at the name to know what the meaning, behind the quotation mark is the description, in the Vim configuration file, double quotes represent annotations, similar to the C language of the/

Test
Open a file, enter in the command line mode: Tlisttoggle can display TagList window, with nerdtree effect as follows
Omnicppcomplete

This is a syntax complement for C + + Plug-ins, you can complete the functions, namespaces, class members, and so on, and most of the IDE is similar, not the same is the IDE for you do a lot of things you do not know, and Omni need to rely on tags file, you need to use ctags command to generate

Download Address

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.