This is how I use vim to write code--Plug-ins

Source: Internet
Author: User
Tags compact diff lua svn

The previous article introduced a simple way to edit vim. Mastered the basic operation of VIM, but also a handy text editor, after all, is much weaker than the IDE. Powerful vs, code tree, code jump, function browsing, auto-completion, code debugging and other functions are the core reasons why we abandon the text editor to embrace the IDE. This article will introduce my long-term dependence on the plug-in, and the basic use of methods, so as to really fully use the VIM environment to do development.

First of all, it is very troublesome to manually manage the plug-in, after trying a painful manual management experience, I decisively cleared the local plug-in folder, began to use Vundle, a very convenient vim plug-in manager. Vundle itself is also a vim plug-in, only need to be configured in the VIMRC inside can be easily installed, updated, delete plug-ins, very useful.

Vundle installation please refer to Https://github.com/VundleVim/Vundle.vim

Once installed, you can add a variety of plugins on GitHub at your own whim. It is recommended that I feel very necessary and easy to use several plug-ins, and attached my configuration items.

Nerdtree Plugin ' Scrooloose/nerdtree '

File directory tree plug-in, open the Directory tab can easily browse the project directory, switch files, create, delete and move files.

My Special configuration:

Let g:nerdtreechdirmode=2 this setting makes the current working directory consistent with the Nerdtree root directory, so that you can quickly switch the working directory, with the subsequent plug-in settings, so that the search and other operations more handy.

Nerdtree is very simple to use, command line input: Nerdtree or: Nerdtreetoggle can be opened to close the Nerdtree window, but generally recommended to configure the shortcut in VIMRC, I use CTRL + N (first letter, good remember). Moves in the Nerdtree window, and is consistent in the General editing window. Press down? Key, you can switch quickly to help. Here's a list of the most common shortcuts.

The U/shift+u root directory is moved to the upper directory, which retains the current root as an expanded state.

Shift+c sets the current directory as the root node.

Shift+r Refresh the current root directory, because refreshing the root directory is also relatively fast, so I always refresh the root directory.

Enter to expand or collapse the directory, if it is a file can open the file directly, more intuitive.

O/I/S three shortcut keys are used to open the current file. Just O is displayed in the previous window, I is a vertical splitter window display, S is a horizontal split window display. The latter two shortcuts are useful when you want to reference the contents of a file.

With the above shortcut keys, you can basically simply use the nerdtree.

CTRLP Plugin ' Ctrlpvim/ctrlp.vim '

The plugin implements fast file lookups and jumps like sublime. When the project is large, it is very convenient to jump files.

Let G:ctrlp_working_path_mode = ' wa ' uses CTRLP in any file in the working directory, searches the entire working directory for files, and can find other files in the project directory at any time in a large project.

Let g:ctrlp_custom_ignore={
\ ' dir ': ' \v[\/]\. (GIT|HG|SVN) $ ',
\ ' file ': ' \v\. (exe|so|dll|xls|xlsx|doc|docx|meta|bytes|ppt|pptx) $ ',
\ }

CTRLP ignores directories and files, which can be set according to your own project needs.

CTRLP shortcut key is very good to remember, is ctrl+p, press will jump out of the corresponding search window, enter the file name to search, enter to open the file. The same ctrl+s,ctrl+v can be opened by splitting the window. When you have a search for multiple files, you can use Ctrl+j/ctrl+k to move up and down to select files.

Taglist Plugin ' Vim-scripts/taglist.vim '

Tag list plugin, you can quickly see the current file tags, functions, variables and so on.

Let tlist_show_one_file=1 displays only one file label at a time, and when the project is large, it will be slow to open the label for all files.
Let Tlist_use_right_window=1 open to the right of the window by default, since Nerdtree already occupies the left window, taglist to the right to avoid conflicts.
Let Tlist_gainfocus_on_toggleopen=1 open the cursor to the TagList window, so that you can directly move the cursor to the corresponding tab jump, or you can directly press Q to exit the TagList window.
Let tlist_close_on_select=1 close the TagList window when the label is selected, and personal preferences taglist only appear when you want to jump.

Because the search within the vim file is very convenient, the use is relatively small. Enter to open, select the appropriate label, enter jump.

CTRLSF Plugin ' Dyng/ctrlsf.vim '

Look at the name guess use, is the global search plugin, with a certain set and shortcut keys, to achieve and vs in the same search experience. The installation of the plug-in is slightly cumbersome and requires an ACK or AG dependency. You can use Https://github.com/k-takata/the_silver_searcher-win32 directly for a compiled version of Windows. Put the execution file in the Vim directory.

Let G:ctrlsf_ackprg= ' AG ' is said to have a higher efficiency of AG.

Let g:ctrlsf_default_view_mode= ' compact ' by default, the Ctrlsf form is much like the sublime search, each result has a pre-and post-context, and the individual prefers a VS-style preview, both of which can be switched at any time by M.

Let g:ctrlsf_auto_close=0 settings do not automatically close, search string is not like search tags, often need to open a look.
Let g:ctrlsf_case_sensitive= ' no ' case insensitive, in order to query faster, default set to case insensitive search.
Let g:ctrlsf_ignore_dir=[' tags '] ignore partial directories
Let g:ctrlsf_default_root= ' CWD ' is set to search under the current working directory, and Nerdtree is consistent.

The above configuration, coupled with the shortcut key configuration, any location press ctrl+f, you can search the current word globally, but also delete the current content, enter the content to find (because of this less demand, so there is no separate shortcut key). Special characters, such as spaces in the middle of a search, can be wrapped in single quotation marks on the outer side.

Youcompleteme Plugin ' Valloric/youcompleteme '

The most difficult to install is the most important plug-ins, auto-complete plug-ins, without this plug-in case, Vim comes with the neocomplete can be used simply, but there is no ycm powerful.

Let g:ycm_min_num_of_chars_for_completion=2 set a minimum of 2 characters to trigger the completion
Let g:ycm_semantic_triggers={
\ ' C ': ['--', '. '],
\ ' lua ': ['. ', ': '],
\} The symbols that trigger semantic analysis are basically comparable to VS and have a good complement to the scripting languages such as Lua.

The function I think does not need shortcut keys, a few letters will automatically jump out of the prompt.

The above is my daily work in the use of all the plug-in. At the beginning, always feel what plug-ins are good, loaded with a lot of plug-ins, because some plug-ins will have key conflicts and so on, while using one side to delete, finally left a few plug-ins. Some projects special needs, you can write some simple vimscript function, with the shortcut key. After two years of use, basically did not feel that there is any shortage, fully capable of coding work. The article finally affixed to my Windows system on the VIMRC, you can refer to the use as appropriate.

SOURCE $VIMRUNTIME/vimrc_example.vimsource $VIMRUNTIME/mswin.vimbehave mswinset diffexpr=mydiff () function Mydiff () Let opt = '-a--binary ' if &diffopt =~ ' icase ' | Let opt = opt. '-I ' | endif if &diffopt =~ ' Iwhite ' | Let opt = opt. '-B ' | endif let arg1 = v:fname_in if arg1 =~ ' | Let arg1 = ' "'. Arg1. ' ' ' | endif Let arg2 = v:fname_new if arg2 =~ ' | Let arg2 = ' "'. Arg2. ' ' ' | endif Let Arg3 = v:fname_out if Arg3 =~ ' | Let Arg3 = ' "'. Arg3. ' ' ' |        endif if $VIMRUNTIME =~ ' if &sh =~ ' \<cmd ' if Empty (&shellxquote) Let L:shxq_sav = ' Set shellxquote& endif Let cmd = ' "'. $VIMRUNTIME. ' \diff ' ' else let cmd = substitute ($VIMRUNTIME, ' ', ' "', '). ' \diff "' endif else let cmd = $VIMRUNTIME. ' \diff ' endif silent execute '! '. Cmd. ‘ ‘ . Opt. Arg1. ‘ ‘ . Arg2. ' > '. Arg3 if exists (' L:shxq_sav ') let &shellxquote=l:shxq_sav endifendfunction "Vundle-----------------------------------------------------------------------set nocompatible "be improved, requiredfiletype off "Required" set the runtime path to include Vundle and Initializeset rtp+= $HOME/vimfiles/bundle/vundle.vim/call Vundle#begin (' $HOME/vimfiles/bundle/') "Let Vundle manage Vundle, Requiredplugin ' Vundlevim/vundle.vim ' Plugin ' Scrooloose/nerdtree ' let G:nerdtreechdirmode=2plugin ' Vim-scripts/taglist.vim ' let Tlist_show_one_file=1let Tlist_ Use_right_window=1let tlist_gainfocus_on_toggleopen=1let tlist_close_on_select=1plugin ' Ctrlpvim/ctrlp.vim ' let G: Ctrlp_working_path_mode = ' wa ' let g:ctrlp_custom_ignore={\ ' dir ': ' \v[\/]\. ( GIT|HG|SVN) $ ', \ ' file ': ' \v\. (exe|so|dll|xls|xlsx|doc|docx|meta|bytes|ppt|pptx) $ ', \}plugin ' Vim-scripts/a.vim ' Plugin ' Dyng/ctrlsf.vim ' let G: Ctrlsf_ackprg= ' AG ' let G:ctrlsf_auto_close=0let g:ctrlsf_case_sensitive= ' no ' let g:ctrlsf_default_view_mode= ' Compact ' let g:ctrlsf_ignore_dir=[' tags ']let g:ctrlsf_default_root= ' cwd ' Plugin ' VallOric/youcompleteme ' Let G:ycm_min_num_of_chars_for_completion=2let g:ycm_semantic_triggers={\ ' C ': [', ', '. '],\ ' Lua ': ['. ', ': '],\} ' all of your Plugins must be added before the following Linecall vundle#end () ' Requiredfi Letype plugin indent on "required" Endvundle-----------------------------------------------------------------------Set backspace=2 "more powerful Backspacingset encoding=utf-8set fileencodings=ucs-bom,utf-8,chineseset langmenu=zh_cn. Utf-8let $LANG = ' zh_cn. UTF-8 ' source $VIMRUNTIME/delmenu.vimsource $VIMRUNTIME/menu.vimcolorscheme desertsyntax enablesyntax onset lines=50 columns=200 linespace=1set background=darkset guifont=consolas:h11:cansiset foldenableset foldmethod=manualset Tabstop=4set shiftwidth=4set softtabstop=4set autoindentset noundofileset nobackupset noswapfileset ignorecaseset Hlsearchset incsearchset showmatchset wildmenuset rulerset laststatus=2set numberset exrcset secureset cursorlineset Tags=tags; " Set guioptions-=m "Menu Barset guIoptions-=t "ToolbarSet guioptions-=r" Scrollbarset guioptions-=lmap <silent> <C-j>:resize+5<cr> Map <silent> <C-k>:resize-5<cr> map <silent> <C-h>: Vertical Resize-5<cr>map < Silent> <C-l>: Vertical resize+5<cr>map <silent> <C-Up>: Resize-5<cr>map <silent > <C-Down>:resize+5<cr> map <silent> <C-Left>: Vertical Resize-5<cr>map <silent > <C-Right>: Vertical resize+5<cr>map <silent> <C-tab>: Tabn<cr>map <silent> <C-n>: Nerdtreetoggle<cr>map <silent> <C-m>: Tlisttoggle<cr>nmap <C-f> <plug >ctrlsfcwordpathvmap <C-f> <plug>ctrlsfvwordpath "open folder of current Filefunction folder () silent Exec "!explorer". Expand ("%:h") Endfunctionnmap <silent> <S-e>: Call Folder () <CR>

  

This is how I use vim to write code--Plug-ins

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.