Introduction to Vim Configuration

As the saying goes, "Workers must first sharpen their tools if they want to do their jobs well." As a professional code farmer, how can you not treat your programming weapon-the VIM editor! Maybe readers would say that the weapon of programming should not be the integrated tools of various languages? Like VS for writing C/C++ programs, Codeblock (cross-platform) software, like Eclipse for writing Java programs (now there are plug-ins that support C/C++/Python), like PyCharm for writing Python programs, etc. These humanized development integrated environments are powerful and easy to use. But success is also here, and failure is also here. This article will introduce the Vim editor and its basic entry-level configuration in detail.

Introduction

As the saying goes, "Workers must first sharpen their tools if they want to do their jobs well", and as a professional code farmer, how can he treat his programming weapon-VIM editor well! Maybe readers would say that the weapon of programming should not be the integrated tools of various languages? Like VS for writing C/C++ programs, Codeblock (cross-platform) software, like Eclipse for writing Java programs (now there are plug-ins that support C/C++/Python), like PyCharm for writing Python programs, etc. These humanized development integrated environments are powerful and easy to use. But I think success is also here, and failure is also here.

  1. Function redundancy
    Now the integrated environment tools for programming are very powerful, but we don't use many functions. Instead, it takes a long time to start each time. Therefore, the integrated environment is not suitable for professional code farmers. We often say that what suits us is the best, especially the programming tool, after all, it does not leave our hands every day.
  2. Customization is too low
    Basically, every integrated development tool does not leave much customization space for users, and users can only get used to the popular usage provided by software vendors. For users who are familiar with multiple languages, it has to master multiple development integration environments, and it is better to use Vim to solve everything.
  3. The mixed use of the mouse and keyboard
    . Personally, I feel that efficient programming still requires hands-on keyboards, and must be proficient in the use of some basic shortcut keys.

The basic Vim is a text editor, but its power lies in its huge plug-ins. These plugins allow Vim to do a lot of awesome things, which is a bit like Google browser. Like code completion, error jump, highlighting, etc., Vim has corresponding plug-ins to deal with, users can understand and combine freely. Therefore, the entry threshold for Vim is still quite high, mainly because you have more commands to learn. Here is a website that recommends playing games and remembering commands and a Vim learning guide . In addition, creating a Vim environment that suits you will greatly save time, and you can sharpen your knife without accidentally cutting wood. Let's take a look at the basic entry-level Vim plugin configuration .

basic configuration

  1. Install vim, scripts, doc

    sudo apt-get install vim vim-scripts vim-doc
    

    Tips:

    • vim vim software, the installation directory is /usr/share/vim
    • vim-scripts Basic plugins for vim, including syntax highlighting, etc. The installation directory is /usr/share/vim-scripts
    • vim-doc vim help file, but in English
  2. Chinese Help Document

    1. Download the latest version of the vim Chinese help document
    2. Unzip the doc folder to the ~/.vim directory
  3. Configure ~/.vimrc file

    Configuring personalized .vimrc (do not know the command can be used :help commandto view Chinese help file)

Useful plug-ins

There are many plugins in Vim, and they are very powerful and very powerful. The plug-in address of the official website is here , but many of its plug-ins have been transferred to Github.

  • ctags
    ctags can establish the tag index of the source tree (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, etc. to view the prototype during programming.

    1. Install exuberant-ctags tool

      sudo apt-get install exuberant-ctags
      
    2. Create C++ Code Base Index

      1. Download libstdc++ header files, including STL and streams in C++.

      2. Unzip to the ~/.vim/tags directory and execute the ctags command

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

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

      1. After the build-essential is installed in ubuntu, there will be C/C++ header files in the /usr/include/c++ directory.

        sudo apt-get install build-essential
        
      2. Copy the files in /usr/include/c++/4.8 to the ~/.vim/tags/gcc folder and execute 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/gcctag
        
      3. Set in .vimrc

        set tags+=~/.vim/tags/gcctag
        
  • The taglist
    window that appears on the right side of the screen is the taglist window, from which you can see all the tags defined in the file: macros, definitions, variables, functions, etc.; by clicking a tag, you can jump to the position defined by the tag; A certain type of tag is folded for easy viewing.

    1. Install taglist

      vim-addon-manager install taglist
      
    2. Configure in .vimrc

      """"""""""""""""""""""""""""""""""
      " 标签列表的设置
      """"""""""""""""""""""""""""""""""
      " 启动vim后,自动打开taglist窗口
      let Tlist_Auto_Open=1  
      " 高亮显示当前标签列表中的标签
      let Tlist_Auto_Highlight_Tag=1
      " 添加新文件后,标签列表将自动更新
      let Tlist_Auto_Update=1
      " 显示标签域--类
      let Tlist_Display_Tag_Scope=1
      " 如果taglist窗口是最后一个窗口,则退出vim
      let Tlist_Exit_OnlyWindow=1
      " Taglist窗口里可折叠
      let Tlist_Enable_Fold_Column=1
      " 只显示当前文件的标签,折叠其他文件的标签
      let Tlist_File_Fold_Auto_Close=1
      " 多个文件间切换时,标签列表也更新为当前文件
      let Tlist_Show_One_File=1
      " 标签列表显示在Buffer区的右边
      "let Tlist_Use_Right_Window=1
      " 单击标签列表中的标签将定位到标签定义处
      let Tlist_Use_SingleClick=1
      
    3. Description of custom shortcut keys

      • <F10> Open/close label list
  • winmanager
    WinManager is used to manage file browsers and buffers. WinManager version 2.0 or higher can also manage other IDE type plug-ins, but users are required to add some auxiliary variables and hooks to the plug-ins to support WinManager (the help document has related instructions).

    1. Install winmanager

      vim-addon-manager install winmanager
      
    2. Configure in .vimrc

      """"""""""""""""""""""""""""""""""
      " 文件管理器
      """"""""""""""""""""""""""""""""""
      " 进入vim后自动打开winmanager
      let g:AutoOpenWinManager =1
      " 设置要管理的插件
      let g:winManagerWindowLayout='FileExplorer|TagList'
      " 如果所有编辑文件都关闭了,退出vim
      "let g:persistentBehaviour=0
      " <F9>打开/关闭文件管理器
      nnoremap <silent> <F9> :WMToggle<CR>
      
    3. Description of custom shortcut keys

      • <F9> Open/close file browser
  • minibufexplorer
    MiniBufferExplorer is used to browse and manage buffers. If only one file is opened, it will not be displayed on the screen. After opening multiple files, it will automatically appear on the screen. Vim also has its own buffer management tools, but only commands such as :ls, :bnext, :bdelete, etc. are neither easy to use nor intuitive.

    1. Install minibufexplorer

      vim-addon-manager install minibufexplorer
      
    2. Configure in .vimrc

      """"""""""""""""""""""""""""""""""
      " 缓冲区管理
      """"""""""""""""""""""""""""""""""
      " 用<C-h/j/k/l>切换到上下左右窗口
      let g:miniBufExplMapWindowNavVim = 1
      " 用Ctrl+箭头切换到上下左右窗口
      let g:miniBufExplMapWindowNavArrows = 1
      "let g:bufExplorerMaxHeight=30
      " 只有一个buffer,MiniBufExplorer这栏也会出现
      "let g:miniBufExplorerMoreThanOne=0
      " normal模式下<Tab>移动到下一个buffer,<C-Tab>上一个
      nnoremap <silent> <Tab> :bn<CR>
      nnoremap <silent> <C-Tab> :bp<CR>
      " 不要在不可编辑内容的窗口(如TagList)中打开选中的buffer
      let g:miniBufExplModSelTarget = 1"
      
    3. Description of custom shortcut keys

      • <Tab> Move to the next buffer
      • <C-Tab> Move to the previous buffer
  • Quickfix
    through the quickfix command set, you can compile the program in Vim and jump directly to the error location for correction. You can then recompile and make corrections until the error no longer occurs. Because quickfix is ​​already integrated in vim, just configure it.

    1. Configure in .vimrc

      """"""""""""""""""""""""""""""""""
      " QuickFix设置
      """"""""""""""""""""""""""""""""""
      " 按下<F2>,执行make
      nnoremap <F2> :TlistToggle<CR> :make<CR><CR><CR> :copen<CR> :TlistToggle<CR>
      " 按下<F12>,执行make clean
      nnoremap <F12> :make clean<CR><CR><CR> :cclose<CR>
      " 按下<F3>,光标移到上一个错误所在的行
      nnoremap <F3> :cp<CR>
      " 按下<F4>,光标移到下一个错误所在的行
      nnoremap <F4> :cn<CR>
      
    2. Description of custom shortcut keys

      • <F2> make current program
      • <F10> make clean current program
      • <F3> Move the cursor to the line of the previous error
      • <F4> Move the cursor to the line of the next error

references

  1. Fun vim game
  2. Vim study guide
  3. vim plugin
  4. Vim Script

If this article has helped you, or if you are interested in technical articles, you can follow the WeChat public account: Technical Tea Party, you can receive related technical articles as soon as possible, thank you!

Technical tea party

This article is automatically published by ArtiPub , a multi- posting platform

Guess you like

Origin blog.csdn.net/haojunyu2012/article/details/112976120