Hi, Habrayuzer!
For the second year now I have been an active user and a fan of Vim. During this time I have gone from two commands to
.vimrc , to a file of several kilobytes and back. I tried a lot of plugins, as well as actively writing my own, and now this is my main text editor for work and leisure.
In this series of articles, I decided to share my own work and, perhaps, show what this editor can be capable of in the hands of a programmer. The series will consist of the following parts:
- Introduction (vim_lib)
- Plugin Manager without fatal flaws (vim_lib, vim_plugmanager)
- Project level and file system (vim_prj, nerdtree)
- Snippets and File Templates (UltiSnips, vim_template)
- Compiling and doing anything (vim-quickrun)
- Work with Git (vim_git)
- Deploy (vim_deploy)
- Testing with xUnit (vim_unittest)
- The library on which everything is kept (vim_lib)
- Other useful plugins
I would like to immediately note that I do not pursue the goal of “putting as many people as possible on the Vim needle”, since the article is intended more for experienced users than for beginners.
')
What's wrong with Vim plugins
The main problem of the editor (except for VimLanguage) is a huge variety of plug-ins for all occasions. It would seem that in this bad? The fact is that plug-ins are written by a huge community, from which they are extremely poorly connected to each other. Often, you may encounter the fact that one of your plug-ins is partially able to do the same as the other two, simply because the author of this plugin decided to add more "buns" to it. If you look into the code of most plugins, you can find a lot of duplicate solutions and algorithms from the plug-in to the plug-in, which should be rendered either in the VimLanguage or in some single library. Unfortunately, some plugin authors try to implement these libraries, but after a few simple plug-ins created on the basis of these libraries, they stop supporting and in addition to a dozen not-so-different plug-ins, you need to install a couple of libraries.
When I started developing under Vim, my main goal was to write a single library (yes, another standard) for all my, and most importantly, foreign plug-ins. A distinctive feature of my idea from others was that I was going to implement all the main plug-ins based on this library, and if there are ready-made solutions, then bring them to the library standards. In other words, I want to implement the whole "gentleman's set" of plug-ins that will dock with each other "out of the box" and use a single library.
Two years of work
I began my movement towards “pure and beautiful” by writing a library. I rewrote it as much as three times, because I needed to thoroughly understand all the subtleties of the VimLanguage, its capabilities and limitations, and I can tell you there are a lot of them! The result was the
vim_lib library, which completely satisfies me.
A feature of the library is that it defines the structure of the editor as a whole (as a framework), adding a new level of action of scripts - project. In fact, this allows you to customize your editor for a specific project and even install plugins that will only work in this project. This is especially useful when working with multiple PLs.
Here is a small example. Suppose we work with a web project using PHP and JavaScript, and in our free time we write a book using LaTeX. What can I offer you and Vim:
- All general settings are placed in the ~ / .vim / directory , after which they will be available in all projects.
- Settings for a web project we put in the webProject / .vim / directory , and to work with a book in bookProject / .vim /
- Every time we open the Vim editor window, we’ll seeand going to the project, it will open in the place of its last editing with the restoration of all windows
- In order not to create blank files each time (for example, Unit tests, Mapper classes for business logic or a chapter of a book), we will create
ready-made file templates in each project (for example for webProject / .vim / templates / test / ___ Test.php Unit-tests) - Who wants to constantly recruit
foreach(...)
Let Vim do it for us. Create some snippets for all occasions. - LaTeX-specific plugins will be installed directly into the bookProject project to work with LaTeX.
- But we are not alone, so we will share our experiences with our colleagues with the help of Git, and for this we have
convenient interface right in Vim - Finished the next chapter and want to look at it in the pdf reader? No problem! Press F9 and the book will be compiled and shown to you immediately. Does it make sense to mention other scripts that can be executed just as easily?
- Decided to start testing a specific class? No question, and for this there is a plugin
- Is it time to merge the changes into production? We press one button and they are already there
Experienced Vim users will say: “Pff ... For all this, there are a bunch of ready-made plug-ins. Bike! ”- but you just don’t know what my proposed solutions are capable of. Not only do they easily fit together, they are also more functional than their counterparts among Vim! In this you can be sure of the following articles of the cycle, just have patience.
What if you can't wait
I accompany almost all my plugins with detailed documentation, so you can try them now. Here is a list of solutions implemented to date:
- vim_lib is a basic library, without which nothing will work for you. It also determines the order in which the editor is loaded.
- vim_plugmanager is my implementation of a package manager for Vim without “fatal flaws”. A feature of this solution is the ability to install the plug-in both in the user directory and in the project directory without the need to change the plug-in configuration, as well as automatically resolve dependencies of installed plug-ins.
- vim_prj - a very useful plugin that allows you to save and restore the state of the project when it is opened and closed
- vim_start - plugin that implements the start menu with the ability to quickly switch to recent projects
- vim_git is a very powerful Git plugin right from Vim
- vim_grep - search in the project
- vim_deploy - plugin to work with any deployment systems (at the expense of adapters to them). At present, only two adapters are implemented: shipit and gradle
- vim_unittest - plugin to work with any xUnit systems (at the expense of adapters to them). Only phpunit adapter is implemented for today.
- vim_template - a very useful plugin that allows you to flexibly customize templates for new files
- vim_write - auto save project
- vim_winmanager - work with windows Vim
To install, create a directory
~ / .vim / bundle (you can use any name) and copy vim_lib there.
git clone https://github.com/Bashka/vim_lib.git ~/.vim/bundle/vim_lib
Then add the following entry to your
.vimrc :
filetype off set rtp=~/.vim/bundle/vim_lib call vim_lib
In general, everything is as usual.
Bye all
I support this project on days off from work, correcting the bugs found during the week and adding the functionality that I needed in the process. If you have any suggestions, what would you personally lack in Vim, go through the survey, and sooner or later it will be implemented as another plugin for Vim.