How do I build the IDE with VIM?

Source: Internet
Author: User
Tags autoload git clone

Transferred from: http://harttle.com/2015/11/04/vim-ide.html

A year ago I switched from vim to Webstorm because of the powerful refactoring capabilities of Webstorm and the Super Search feature. The advantages of Webstorm when it comes to multi-file editing and refactoring are obvious.

Recently got the HHKB, from the keyboard to the touch panel switch is still very troublesome, so the need for Vim editor came again. In addition to Webstorm often suspended animation, I decided to re-enable VIM. It also re-created my vim so that it can meet all of my needs in the IDE. This article will describe the whole process, perhaps some help. First:

, the following console is done through Tmux. Tmux configuration and usage see: Using the command line gracefully: Tmux terminal multiplexing.

Preparatory work

Install Git, Homebrew (if you're a Mac), and install a new version of Vim (>=7.3). The general Linux distribution will be pre-installed with VIM, you need to check the VIM version:

$ vim --versionVIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jul  4 2015 01:13:13)MacOS X (unix) versionIncluded patches: 1-712Compiled by Homebrew

If the above command fails, then you need to install a vim~ here that provides Vim's basic shortcut key memo.

Os x
$ brew update$ brew install vim
Linux
apt-get install vim   # ubuntupacman -S vim         # archlinuxyum install vim       # centos
Vundle

Vundle is a git-based vim plug-in management tool and is currently the most recommended tool. Before I .vim manually maintained a variety of plugins, the directory structure looks like this:

|- doc/|  |- emmet.txt|  |- NERDCommenter.txt|  |- ...|- plugin/|  |- emmet.vim|  |- NERDCommenter.vim|  |- ...|- autoload/|  |- emmet.vim|  |- NERDCommenter.vim|  |- ...|- ftplugin/

After using Vundle, it becomes this:

|- bundle/|  |- emmet/|  |  |- doc/|  |  |- autoload/|  |- NERDCommenter/|  |  |- doc/|  |  |- autoload/|- ftplugin/

ftplugininside of it is my configuration, such as the shortcut keys for compiling and running. Also, if you are synchronizing vim configuration with Git, you can bundle/ join .gitignore .

So how to install Vundle?

git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Then .vimrc add the Vundle configuration to your:

set nocompatible              " requiredfiletype off                  " requiredset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()Plugin ‘gmarik/Vundle.vim‘call vundle#end() " requiredfiletype plugin indent on " required

Then run in Vim :PluginInstall (or run in Bash vim +PluginInstall ). You only need to add a row Plugin ‘xxx‘ and run it to :PluginInstall install the plugin automatically.

Pane Management

To make vim an IDE, you need to be familiar with how Vim creates panes and how to switch between panes. :spYou can split the current pane horizontally, and :vs you can split the current pane vertically. You can repeat multiple times to create a complex pane layout:

C-w, C-wYou can switch to the next pane, switch to the pane below, switch to the upper pane, switch to C-w, j C-w, k C-w, h the left pane, and C-w, l switch to the right pane. I have set up more convenient shortcuts for these operations, such as CTRL+J switch to the following panes:

<C-J> <C-W><C-J>

Multi-file management can use multiple panes, or you can use the buffer method. For example vim a.js b.js , you would open two files simultaneously in buffer. Use :ls to list the files in the current buffer, and then use the number keys to switch. You can also use the :b 2 switch to a second file in buffer.

Folded

Some people prefer code folding, and I'll make a list of how to gracefully fold the code. First .vimrc Add the configuration in:

set foldmethod=indentau BufWinLeave * silent mkview " 保存文件的折叠状态au BufRead * silent loadview " 恢复文件的折叠状态nnoremap <space> za " 用空格来切换折叠状态

When you turn on indent to collapse the code, opening a file will reveal that the indented content is all folded up. So we introduce a simplefold to more intelligently fold:

‘tmhedberg/SimpylFold‘

Don't forget to run it :PluginInstall .

Auto-complete

Automatic completion of course is used YCM:

‘Valloric/YouCompleteMe‘

Then configure it, YCM is omnifunc automatically complete with vim mechanism, so you need to install a VIM plugin that provides the interface for the language you want to support omnifunc .

In another blog, I have described in detail the automatic completion, grammar check and other configurations.

Project Tree

This must be one of the greatest benefits that the IDE can provide, and in vim you can use Nerdtree to display the file tree, which has a very large number of shortcuts, so it's as good as Vim.

‘scrooloose/nerdtree‘" 这个插件可以显示文件的Git增删状态Plugin ‘Xuyuanp/nerdtree-git-plugin‘

Here are some of my nerdtree configurations:

"CTRL + N Open/close map<c-N>: Nerdtreetoggle<cr>"Automatically loads the project tree when vim is open without parameters AutocmdStdinreadpre *LetS:std_in=1autocmdVimenter *If ARGC()==0 &&!exists("S:std_in")| Nerdtree|endif"Close the project tree pane when all files are closed autocmd Bufenter *If(Winnr("$") = = 1 && exists("B:nerdtreetype") && B: Nerdtreetype = = "PRIMARY") | Q | endif"Do not show these files let nerdtreeignore=[' \.pyc$ ', ' \~$ ', ' Node_modules ' ] "Ignore files in nerdtree" does not display additional information on the project tree, such as help, what to prompt for let nerdtreeminimalui=1  
Global Search

Webstrom's global search was the main reason I used it, and now the global search is always a sudden crash, and that's the main reason I'm giving up webstorm and turning to vim.

Analyticals defeat Xiao

Install CTRLP:

‘kien/ctrlp.vim‘

Then press C-P it to search globally. Use C-j , C-k page up and down to <Enter> open the selected file. Again, here are some useful configurations:

let g:ctrlp_working_path_mode = ‘ra‘set wildignore+=*/tmp/*,*/node_modules/*,*.so,*.swp,*.zip let g:ctrlp_custom_ignore = {‘dir‘: ‘\v[\/]\.(git|hg|svn)$‘, ‘file‘: ‘\v\.(exe|so|dll)$‘}
Shear Plate

The shear plate must be the pain of all vim users. But! Under Mac you only need to set:

set clipboard=unnamed

All of the content you copy in Vim will be on the system Clipboard. When copying content in Vim, you can switch to copy mode to prevent automatic indentation and completion. My shortcut keys are <F9> :

set pastetoggle=<F9>
Status bar

Have you noticed my cool status bar? Install a powerline:

‘Lokaltog/powerline‘, {‘rtp‘: ‘powerline/bindings/vim/‘}

In addition, some settings are required to correctly display the powerline icon:

set guifont=Inconsolata\ for\ Powerline:h15let g:Powerline_symbols = ‘fancy‘set encoding=utf-8set t_Co=256set fillchars+=stl:\ ,stlnc:set term=xterm-256colorset termencoding=utf-8

Then import the powerline font in the System font library, and if it is a Mac, you can use font book to import it. Then you need to set the Non-ascii font for Terminal (iTerm) to Powerlinesymboles:

Comments, anti-comment

Nerdcommenter is a great tool that supports a very great number of languages:

‘scrooloose/nerdcommenter‘   " commenter: \cc \cu

Then press \cc to comment on the current navigation \cu , to reverse the comment, \c<space> to toggle the comment. Where \\ it can be set:

let mapleader=‘;‘
Loremipsum

Haha, if you haven't seen the word in the title, you can skip it. In front-end development, it is often necessary to add placeholders to make the page look content and to be like a person, loremipsum (Latin) is usually the starting character of these placeholders. For example, the following paragraph:

Sodales eget, leo. Sed ligula augue, cursus et, posuere non, mollis sitamet, est. Mauris massa. Proin hendrerit massa. Phasellus eu purus. Donec estneque, dignissim a, eleifend vitae, lobortis ut.

Install a loremipsum:

‘vim-scripts/loremipsum‘ 

I've also added a bit of setup to make it easy to control length:

<Esc><Esc>:Loremipsum 20<CR>inoremap Ipsum <Esc><Esc>:Loremipsum 70<CR>

This results in a placeholder with a Lorem length of 20 words when entered, and a placeholder with a length of 70 when entered Ipsum .

Reference Links:

    • https://realpython.com/blog/python/vim-and-python-a-match-made-in-heaven/
    • Https://coderwall.com/p/yiot4q/setup-vim-powerline-and-iterm2-on-mac-os-x

How do I build the IDE with 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.