In my previous blog post, “Getting Started with Vim configuration”, I only briefly introduced the basic configuration of Vim and several commonly used plugins. However, in the later use of Vim, I found that the configuration of Vim is not very easy to use, especially the minibuffer, Taglist, and FileExplore directly conflicts. It is also cumbersome to manage plug-ins. This post is about addressing these two issues and trying out some more coders suitable for the plugin.

Introduction to the

The original intention of using Vim was not only the power of its plug-ins, but also the more important aspect of being suitable for installing 13. But as we got to know more about Vim, we realized that it was so powerful for a reason, as evidenced by the following comments:

  • There are only three editors in the world, EMACS, VIM, and others
  • VIM is the God of editors, EMACS is God’s editor
  • EMACS is actually an OS which pretends to be an editor

According to the problems in daily use of the configuration in the previous blog post, the solution is given here. For conflicts between plug-ins, the tagbar is used instead of the Taglist, while the bundle plug-in is used for plug-in management. There are many practical and convenient plug-ins for Vim.

Efficient plug-in

Vim’s plug-ins are numerous and powerful, very powerful. The add-on address is here.

vundle

Vundle is used to manage the vim plug-in plug-in, it makes efficient use of Git, making viM plug-in installation, update and uninstall are managed by vundle, so that users from vim installation and configuration out.

  1. Install vundle

    git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
    Copy the code
  2. Manage Vim plug-ins using Vundle

    1. Select the plug-in you want to use in Vim Script

    2. Add Plugin plugin_name to Vim configuration file.vimrc

    3. Run the vundle initialization command :PluginInstall, and the plug-in is installed

    4. Common commands

      # Update plugin
      :PluginInstall!
      # Clear plugins that are no longer used
      :PluginClean
      List all plugins
      :PluginList
      # Find plugins
      :PluginSearch
      Copy the code
    5. Vundle Configuration in. Vimrc

      "File type test close [must] (/ usr/share/vim/vim74 / filetype vim)
      filetype off
      "Set Runtime Path to include Vundle path and initialize
      set rtp+=~/.vim/bundle/Vundle.vim
      "Set the plugins installation address
      call vundle#begin('~/.vim/bundle/')
      "Install Vundle and let it manage plug-ins [must]
      Plugin 'gmarik/Vundle.vim'
      
      """"""""""""""""""""""""""""""""""
      "Vundle"
      "The plugin is on Github
      " Plugin 'tpope/vim-fugitive'
      "Plugin from http://vim-scripts.org/vim/scripts.html page
      " Plugin 'L9'
      "Git plugin, but the plugin is not on Github
      " Plugin 'git://git.wincent.com/command-t.git'
      "Plugins on local machine" (i.e. when working on your own plugin)
      " Plugin 'file:///home/gmarik/path/to/plugin'
      " The sparkup vim script is in a subdirectory of this repo called vim.
      " Pass the path to set the runtimepath properly.
      " Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
      "Use user names to avoid plugin conflicts ie.l9
      " Plugin 'user/L9', {'name': 'newL9'}
      """"""""""""""""""""""""""""""""""
      
      "All plugins added before end [must]
      call vundle#end()            
      "File types corresponding plug-in [must] (/ usr/share/vim/vim74 / ftplugin vim)
      filetype plugin on
      "Indented file corresponding to the file type
      filetype indent on
      Copy the code

The-NERD-tree

NERDTree, one of Vim’s most commonly used plug-ins, displays directories and file structures while Vim is running. It is similar to the file browser to the left of TextMate, but much easier to use. You can quickly browse files and switch between files and folders without leaving the keyboard in your hand. An example is shown in the following figure:

  1. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle')
    [The nerd-tree] displays The file directory in The Vim edit window.
    Plugin 'The-NERD-tree'
    call vundle#end()  
    
    """"""""""""""""""""""""""""""""""
    "The NERD - tree configuration
    """"""""""""""""""""""""""""""""""
    "Do not display cached files, intermediate files
    let NERDTreeIgnore=[ '.pyc$'.'.pyo$'.'.obj$'.'.o$'.'.so$'.'.egg$'.'^.git$'.'^.svn$'.'^.hg$' ]
    "Exit vim when only one NERDTree window is left
    autocmd bufenter * if (winnr("$") = =1 && exists("b:NERDTreeType") &&b:NERDTreeType= ="primary") | q | endif
    "
            
              Open/close the file manager
            
    nnoremap <silent> <F9> :NERDTreeToggle<CR>
    Copy the code

The-NERD-Commenter

This plug-in is also a must – have, mainly automatically annotating content. When you are XML naturally is XML annotation, when you are Java naturally is Java annotation rules. An example is shown in the following figure:

  1. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle/')
    "Quickly add/remove comments
    Plugin 'The-NERD-Commenter'
    call vundle#end()  
    
    """"""""""""""""""""""""""""""""""
    "The NERD - Commenter configuration
    """"""""""""""""""""""""""""""""""
    "A space is automatically added to the comment. Compulsive disorder is mandatory
    let g:NERDSpaceDelims=1
    "Mm intelligent judgment add/unannotate
    map mm <leader>c<space>
    Copy the code

ctrlp

This is a file finder plugin that is similar to NERDTree, but with some differences. An example is shown in the following figure:

  1. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle/')
    "File search"
    Plugin 'kien/ctrlp.vim'
    call vundle#end()  
    
    """"""""""""""""""""""""""""""""""
    "CTRLP configuration
    """"""""""""""""""""""""""""""""""
    "Set the local working directory of CtrlP. 0 indicates that the function is not set
    let g:ctrlp_working_path_mode=0
    "The CTRLP window is at the bottom
    let g:ctrlp_match_window_bottom=1
    "The maximum height of the CTRLP window is 15 lines
    let g:ctrlp_max_height=15
    "Window
    let g:ctrlp_match_window_reversed=0
    "Number of files recently opened
    let g:ctrlp_mruf_max=500
    "Record but remove duplicate soft links
    let g:ctrlp_follow_symlinks=1
    "
            
              Starts file search
            
    let g:ctrlp_map = '<c-f>'
    "Ctrlp Start file lookup
    let g:ctrlp_cmd = 'CtrlP'
    "Equivalent to MRU function, show recently Opened Files
    map <c-p> :CtrlPMRU<CR>
    "Ignore the following file types
    set wildignore+=*/tmp/*,*.so,*.swp,*.zip
    "Ignore the following file directories
    let g:ctrlp_custom_ignore = {'dir':  '/].(git|hg|svn|rvm)$'.'file': '(exe|so|dll|zip|tar|tar.gz)$'}
    Copy the code

ctags

Ctags can establish the source tree tag index (a tag is a place where an identifier is defined, such as a function definition), so that programmers can quickly locate functions, variables, macro definitions, and other places to see the model during programming.

  1. Install the Exuberant – CTags tool

    sudo apt-get install exuberant-ctags
    Copy the code
  2. Create C++ code base index

    1. Download the libstdc++ header file, including C++ STL, streams, etc.

    2. Decompress it to the ~/.vim/tags directory and run the ctags command

      ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ cpp_src
      mv tags ~/.vim/tags/cpptag
      Copy the code
    3. Set in.vimrc

      set tags+ = ~ /.vim/tags/cpptag
      Copy the code
  3. Create the Gcc code base index

    1. After build-essential is installed in Ubuntu, there will be C/C++ headers in the /usr/include/C ++ directory.

      sudo apt-get install build-essential
      Copy the code
    2. Copy /usr/include/c++/4.8 to ~/.vim/tags/ GCC and run the ctags command

      Cp -r /usr/include/c++/4.8 ~/.vim/tags/ GCC ctags -r --c++-kinds=+p --fields=+iaS --extra=+q GCC mv tags ~/.vim/tags/gcctagCopy the code
    3. Set in.vimrc

      set tags+ = ~ /.vim/tags/gcctag
      Copy the code

cscope

Cscope, an application used by programmers to help them write and track code, mainly in C programs. Originally developed at Bell LABS and operated on pdP-11, it was developed by Joe Steffen.

  1. Install the CScope tool

    sudo apt-get install cscope
    Copy the code
  2. Create the GNU C library index

    1. Download the glibc file, which is the GNU published LIbc library, the C runtime. Glibc is the lowest level API in a Linux system, and almost any other runtime depends on Glibc.

    2. Decompress it to the ~/.vim/tags directory and run the cscope command

      cd. ~ / vim/tags/glibc 2.22 cscope - RbqCopy the code
    3. Set in.vimrc

      """"""""""""""""""""""""""""""""""
      "Cscope configuration
      """"""""""""""""""""""""""""""""""
      if has("cscope")
          "Sets the cscope command location
          set csprg=/usr/local/bin/cscope
          "Set QuickFix to display cScope's results
          set cscopequickfix=s-,c-,d-,i-,t-,e-
          "First search tags tag file in search cScope database
          set csto=1
          "Using a Cstag query means searching the CScope database and tags tag files at the same time
          set cst
          "Do not display whether the database was added successfully
          set nocsverb
          "
          if filereadable("cscope.out")
          "Add the cScope database in the current directory
          cs add cscope.out
          else
          "Add vim's own cScope database
          "Gnu C database
          cs add~ /.vim/tags/glibc-2.22/cscope.out ~/.vim/tags/glibc-2.22
          endif
          "A message is displayed indicating that the database is added successfully
          set csverb
      endif
      
      "Mapping shortcuts"<C-_>For G, press first"Ctrl+Shift+-"And then press it again very quickly"g"
      "Find this C symbol (you can skip comments)
      nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
      "Look for this definition
      nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
      "Find the function that called this function
      nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>
      "Find this string
      nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>
      "Find this egrep mode
      nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>
      "Find this file
      nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
      "Find the file that contains this file
      nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
      "Find the function called by this function
      nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>
      Copy the code

tagbar

The TagBar plugin is similar to the TagList plugin, but it is better than TagList and works perfectly with NERDTree.

  1. The advantage of the tagbar

    • Display a list of functions that support header files

    Careful readers may notice that the Tagbar also differentiates the visibility level of functions by using + — # and colouring

    • Object oriented support is better

    The TagList also lists classes, but it’s still pretty unintuitive overall

    • Automatic reconstruction based on file modification time

    This is where the taglist experience is bad, and it can be done with this timestamp

  2. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle/')
    "Replace tagList plugin [tagbar]
    Plugin 'majutsushi/tagbar'
    call vundle#end()  
    
    """"""""""""""""""""""""""""""""""
    "The tagbar configuration
    """"""""""""""""""""""""""""""""""
    "Automatically focus when started
    let g:tagbar_autofocus=1
    "
            
              Turns on/off the Tagbar
            
    nnoremap <silent> <F10> :TagbarToggle<CR>
    Copy the code

rainbow

This plugin is also required. The main function of this plugin is to color the pairs of (){}[], which makes it easy to see the scope of the parentheses

  1. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle/')
    "Parentheses show enhancements
    Plugin 'luochen1990/rainbow'
    call vundle#end()  
    
    """"""""""""""""""""""""""""""""""
    "Rainbow configuration
    """"""""""""""""""""""""""""""""""
    "Rainbow activation
    let g:rainbow_active = 1
    Copy the code
  2. Add auto start to Rainbow

    if (exists('g:rainbow_active') && g:rainbow_active)
        auto syntax * call rainbow#hook()
        auto colorscheme * call rainbow#show()
        "The following command causes Rainbow to be turned on when vim starts
        autocmd VimEnter * nested call rainbow#toggle()
    endif
    Copy the code

syntastic

This is a very useful plug-in, it can be real-time syntax and coding style check, use it to almost do code after compiling error. It also incorporates static checking tool: Lint to make your code even better. Even more powerful, it supports nearly a hundred programming languages and acts as a full-fledged real-time compiler. When an error occurs, it is very convenient to jump to the error. An example is shown in the following figure:

  1. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle/')
    "Semantic highlighting
    Plugin 'scrooloose/syntastic'
    call vundle#end()  
    
    """"""""""""""""""""""""""""""""""
    "Syntastic configuration
    """"""""""""""""""""""""""""""""""
    "Semantics are checked when you first open and save
    let g:syntastic_check_on_open = 1  
    "Set error prompt 'x'
    let g:syntastic_error_symbol = 'x'  
    "Set warning prompt '! '
    let g:syntastic_warning_symbol = '! '  
    "An error message is displayed when the mouse is on the wrong line
    let g:syntastic_enable_balloons = 1  
    "Save and exit without semantic detection
    let g:syntastic_check_on_wq = 0
    "If there is a compilation error, the error window is displayed. If there is no compilation error, the error window is not displayed
    let g:syntastic_auto_loc_list = 1
    "Errors always populate the error window
    let g:syntastic_always_populate_loc_list = 1
    Copy the code

YouCompleteMe

YouCompleteMe completes the code completely at the compiler level and is no weaker than Visual Assist. It is based on LLVM/ Clang, a compiler supported by Apple to replace GNU/GCC, because YouCompleteMe has compiler support, and no longer like the previous plug-in based on text to match, so the accuracy is so high. Moreover, it is a C/S architecture. It creates a server side on the native side, uses Clang to parse the code, and then returns the results to the client. Therefore, it solves the problem that VIM is single-threaded, which causes various plug-ins to be extremely slow to complete. The experience reaches the Visual Assist level.

In addition to completion, YouCompleteMe also has a very important role: code jump, can also achieve compiler level accuracy, comparable to Visual Assist and Source Insight. An example is shown in the following figure:

  1. Installing Required Software

    sudo apt-get install clang llvm cmake python python-dev
    Copy the code
  2. Manually compile

    cd ~/.vim/bundle/YouCompleteMe
    ./install.sh --clang-completer
    Copy the code
  3. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle/')
    "Autocomplete
    Plugin 'Valloric/YouCompleteMe'
    call vundle#end()  
    
    """"""""""""""""""""""""""""""""""
    "YouCompleteMe configuration
    """"""""""""""""""""""""""""""""""
    "Set the path to the YCM configuration file
    let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
    "Enable keyword syntax detection
    let g:ycm_seed_identifiers_with_syntax = 1
    "Automatic trigger completion
    let g:ycm_auto_trigger = 1
    "YCM trigger conditions
    let g:ycm_semantic_triggers= {\'c' : ['- >' , '. '], and \'cpp,objcpp' : ['- >'.'. '.'... '], and \'java,javascript,python,scala' : ['. '], and \'ruby' : ['. '.'... '], and \}"Don't ask every time. Ycm_extra_conf.py location
    let g:ycm_confirm_extra_conf=0
    "YCM also collects identifiers from tags files
    let g:ycm_collect_identifiers_from_tags_files=1
    "No pop-up prompts when typing comments
    let g:ycm_complete_in_comments=0
    "Prompt when entering a character
    let g:ycm_complete_in_strings=1
    Copy the code

If YouCompleteMe is installed, you can not use < Tab > to complete automatically, but you can only use up/down arrow key + Enter to select. Vimrc is set to paste mode. This pattern masks all mappings and abbreviations. (Same problem with ultisnips)

ultisnips

This plugin is also a must. The main function of this plugin is to quickly enter fixed blocks of code, such as copyright notices at the beginning of files,#ifndef... #def... #endifWith this macro definition, Markdown writes the head information of Jekyll’s blog post. The key is to follow your own habitsCustom code blocks”So that you don’t have to follow the IDE habit of cultivating yourself. The dynamic effect is as follows:

  1. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle/')
    " ultisnips
    Plugin 'SirVer/ultisnips'
    " Snippets are separated from the engine
    Plugin 'honza/vim-snippets'
    call vundle#end()  
    
    """"""""""""""""""""""""""""""""""
    "Ultisnips configuration
    """"""""""""""""""""""""""""""""""
    "If you use Valloric/YouCompleteMe, don't set it to < TAB >
    let g:UltiSnipsExpandTrigger="<c-j>"
    "Pre-selected footage
    let g:UltiSnipsJumpForwardTrigger="<C-f>"
    "Selected segment
    let g:UltiSnipsJumpBackwardTrigger="<C-b>"
    "Use :UltiSnipsEdit to open the segment definition file time screen location
    let g:UltiSnipsEditSplit="vertical"
    Copy the code
  2. Custom code blocks

We noticed that when installing Ultisnips, we installed Honza’s Vim – Snippets in addition to installing itself, and one of its main functions was to provide a large number (currently 80) of program snippets such as C, Python, Markdown, Make, sh, SQL, etc. And those snippets are in the.vim/bundle/vim-snippets/ Snippets folder. In addition, we can customize our own code blocks. It is recommended to put them in the.vim/UltiSnippets directory (the same level as the bundle). On the one hand, the code blocks under.vim/bundle/vim-snippets/snippets are other people’s Git projects. On the other hand, files under.vim/UltiSnippets can override the configuration in vim-Snippets, which is more suitable for DIY purposes. There are few resources available online to suggest how to write Snippets: * View the code in.vim/bundle/vim-snippets/snippets * view the ultisnips help document with: Help snippets * Blog post customize the sample in your own code block

Sh ## head Snippet head "Jekyll Post header" b # b means begin (Snippet should be expanded only at the Beginning of a line) -- Layout: default title: ${1:blog_name} category: [${2:cate1,cate2}] comments: true date: '! Y - v strftime (" % % m - H: % d % % m: % S ") ` - ${0} # for the location of the TAB lodged endsnippet ` ` `Copy the code

tabular

This is a must-have plugin for Virgos and code farmers, because when you see code/text clutter – equals, colons, tables, etc. The Tabular plugin solves this problem perfectly. Just type the command, as shown in the legend below:Tabularize /*(* represents the symbol for alignment)

  1. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle/')
    "The alignment TAB
    Plugin 'godlygeek/tabular'
    call vundle#end()  
    
    """"""""""""""""""""""""""""""""""
    "Tabular configuration
    """"""""""""""""""""""""""""""""""
    "We're still learning the ropes
    Copy the code

vim-markdown

Vim-markdown is a plug-in for semantic highlighting and rule matching of native and extended MarkDown syntax.

  1. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle/')
    "Markdown semantics highlighted
    Plugin 'plasticboy/vim-markdown'
    call vundle#end()
    
    """"""""""""""""""""""""""""""""""
    "Tabular configuration
    """"""""""""""""""""""""""""""""""
    "Vim identifies MD
    autocmd BufNewFile,BufReadPost *.md set filetype=markdown
    let g:vimmarkdownfoldingdisabled=1 "Unfold code
    let g:vimmarkdownnodefaultkeymappings=1 "Cancel the default key mapping
    let g:vimmarkdownmath=1 "Use mathematical notation
    let g:vimmarkdownfrontmatter=1 "Highlight YMAL frontmatter
    Copy the code

[Markdown-preview][Markdown-preview]

Markdown-preview is a plugin that translates markDown files opened by Vim into HTML for display in the browser. The highlight of this plugin is that it is updated in real time.

  1. Installation and configuration in Vim

    call vundle#begin('~/.vim/bundle/')
    "Markdown sync display
    Plugin 'iamcco/mathjax-support-for-mkdp'
    Plugin 'iamcco/markdown-preview.vim'
    call vundle#end()
    
    """"""""""""""""""""""""""""""""""
    "Markdown - preview. Vim configuration
    """"""""""""""""""""""""""""""""""
    "Set the command to start the Chrome browser
    let g:mkdp_path_to_chrome = "open -a Google\\ Chrome"
    "Set this to 1 and the browser automatically opens when the markdown file is opened
    let g:mkdp_auto_start = 1
    "Set this to 1 and the preview window opens when editing Markdown. If not, it opens automatically
    let g:mkdp_auto_open = 1
    "The preview window closes automatically when switching buffer. If set to 0, it does not close automatically when switching buffer
    let g:mkdp_auto_close = 1
    "Set to 1 to update preview only when saving the file or exiting insert mode. Default to 0 to update preview in real time
    let g:mkdp_refresh_slow = 0
    "Set this to 1 and all files will be previewed using MarkdownPreview. By default, only markDown files will be previewed
    let g:mkdp_command_for_global = 0
    Copy the code

emmet-vim

Emmet’s predecessor was Zen Coding, which was a front-end plug-in. Official support for many software, such as Sublime Text, Notepad++, Dreamweaver, Eclipse, Adobe Brackets, etc. It was developed by Yasuhiro Matsumoto of Japan. It is a great tool for front-end developers to save a lot of repetitive coding effort. Given the lack of front-end development, this is just a mark.

reference

  1. Fun Vim game
  2. Vim Study Guide
  3. vim plugin
  4. Vim Script
  5. Vim configuration and description — IDE programming environment
  6. Efficient Vim plug-ins
  7. VIM mnemonic diagram
  8. Vimer’s program world
  9. vimium
  10. youcompleteme
  11. syntastic
  12. python IDE
  13. ultisnips
  14. Customize your own code blocks
  15. Front-end development artifact Emmet
  16. Emmet tutorial
  17. Align artifact – Tabular
  18. vim-markdown

If this article has helped you, or you are interested in technical articles, you can pay attention to the wechat public number: Technical tea Party, can receive the relevant technical articles in the first time, thank you!

This article was automatically published by ArtiPub, an article publishing platform