Skip to content

Instantly share code, notes, and snippets.

@zhangk1551
Last active September 19, 2020 04:57
Show Gist options
  • Save zhangk1551/528c6e3eecc9ac54bb8fd2fef0783408 to your computer and use it in GitHub Desktop.
Save zhangk1551/528c6e3eecc9ac54bb8fd2fef0783408 to your computer and use it in GitHub Desktop.
vim8 Plugins Recommendation

Vim8 Plugins Recommendation

Preface

Before starting the discussion, go through the following three questions:

With vim,

  1. How do you search a string / file in a project? Could you quickly switch between the search results?
  2. How do you compile a project? Could you do it with one shortcut and jump to the exact position where error occurs?
  3. How do you rename a variable? What if there is another variable with the same name in the project?

LeaderF, AsyncTask and coc.nvim solve the above three problems correspondingly.

Plug-ins

LeaderF for searching

LeaderF does almost all the things related to search.
Here're its subcommands:

    file                search files  
    tag                 navigate tags using the tags file  
    function            navigate functions or methods in the buffer  
    mru                 search most recently used files  
    searchHistory       execute the search command in the history  
    cmdHistory          execute the command in the history  
    help                navigate the help tags  
    line                search a line in the buffer  
    colorscheme         switch between colorschemes  
    gtags               navigate tags using the gtags  
    self                execute the commands of itself  
    bufTag              navigate tags in the buffer  
    buffer              search buffers  
    rg                  grep using rg  
    filetype            navigate the filetype  
    command             execute built-in/user-defined Ex commands.  
    window              search windows.  
    quickfix            navigate the quickfix.  
    loclist             navigate the location list.  

Plus, it also auto-update gtags in the background, which means you don't need another plug-in like vim-gutentags. LeaderF supports fuzzy search with high speed. The navigating subcommands will trigger a display list of corresponding items. Jump through the search results is convenient.

AsyncTask for Compilation

If you prefer to run the compiling / running commands within vim, AsyncTask is a good resolution. AsyncTask simplifies the configuration for you, so that you don't need to write vim script to map the shortcuts depending on the filetype from scratch. It also supports project-specific compiling / running configuration.

coc.nvim as LSP Client

One thing that vim was often criticized before was that compared to IDE, it did not really understand the code. Instead, many of functions of vim(or its plug-ins) just based on text matching, so operations such as renaming the variables would be painful in vim, since vim couldn't distinguish variables in different scopes.

However, with the help of Language Support Protocol(LSP), vim can understand the real meaning of code, and operations such as renaming variables, jumping to definitions and searching references work much better.

coc.nvim could be used as a handy client of LSP. There're also plug-ins like coc-python, which help you set configuration with corresponding LSP server. The "coc" plug-in family also introduce some fancy features from vs-code to vim, for example, completion of snippets(coc-snippets) and so on.

Check LSP server to see the supporting features. e.g. For python with jedi server & coc-python ,

  • IDE-like features
    • Automatic indenting
    • Code navigation ("Go to", "Find all" references)
    • Code definition (Peek and hover definition, View signatures)
    • Rename refactoring
    • Sorting import statements (use the Python: Sort Imports command)
  • Intellisense and autocomplete (including PEP 484 and PEP 526 support)
    • Ability to include custom module paths (e.g. include paths for libraries like Google App Engine, etc.; use the setting python.autoComplete.extraPaths = [])
  • Code formatting
    • Auto formatting of code upon saving changes (default to 'Off')
    • Use either yapf, autopep8, or Black for code formatting (defaults to autopep8)
  • Linting
  • Snippets
  • Miscellaneous
    • Running a file or selected text in python terminal
    • Automatic activation of environments in the terminal
  • Refactoring
    • Rename refactorings
    • Extract variable refactorings
    • Extract method refactorings
    • Sort imports

Plug-in Manager

For vim8, git submodule is good enough. No extra plug-in manager is needed. With git submodule, you can enjoy the benefits of normal git, such as roll back the plug-in repo to a specific commit. It would also be nice if you backup your .vim folder in the github. Everything works in a natural way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment