Vim Complete: Compiling and Running Anything
Table of contents
- 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 executing anything (vim-quickrun)
- Work with Git (vim_git)
- Deploy (vim_deploy)
- Testing with xUnit (vim_unittest)
- The library on which everything rests (vim_lib)
- Other useful plugins
How can an editor be called convenient if it does not know how to run what we program? A feature of the plugin that I describe in this article is the ability to run anything, be it program code, plantUML, LaTeX, Less, and anything else you can write and run. The vim-quickrun plugin may seem rather confusing and complicated, despite the excellent documentation, so I decided to briefly cover it in this article so that you can start using it faster.
Compilation and launch by the editor
Of course, using the Vim editor alone, you cannot compile and / or run the code that we write in it. To do this, we need third-party utilities, compilers, and means for viewing the result (for example, a browser, a PDF reader, etc.). The vim-quickrun plugin allows you to define a set of tools that will be applied to the current editor file in order to compile and visualize the result. The plugin is quite flexible, which allows you to work with any language if the system has the appropriate utilities installed, of course.
Type definition
The plugin uses the filetype property of the Vim editor to determine the type of file being launched (processed). In practice, this allows, for example, working with a Web project to run in the editor both a PHP script and compile a Less file and see the resulting CSS. Convenient, isn't it?
Configuration
The plugin includes many ready-made solutions for various languages. So, most modern language packs are compiled and launched by the plugin “out of the box” (if there are appropriate compilers and interpreters). This allows us to install the plugin and immediately start using it, but we come across rarer code, we have to “conjure” a bit. For "witchcraft", the editor variable g: quickrun_config is used , which should be initialized by configuration. It is important that our configuration will just complement the standard one and we don’t have to configure the plugin for all languages.
To configure the plugin you need:
- Define the compiler / interpreter of the plugin using the command property
- Define commands that fulfill preconditions and postconditions using the exec property
- Define the command responsible for rendering the result using the outputter property
Here are some examples:
Markdown
let g:quickrun_config = {
\ 'markdown': {
\ 'outputter': 'browser',
\ },
\}
LaTeX
let g:quickrun_config = {
\ 'tex': {
\ 'command': 'pdflatex',
\ 'exec': ['%c -synctex=1 -interaction=nonstopmode "%S:t:r.tex"', 'evince "%S:r.pdf"', 'rm "%S:t:r.pdf" "%S:t:r.aux" "%S:t:r.log" "%S:t:r.synctex.gz"'],
\ },
\}
PlantUML
let g:quickrun_config = {
\ 'plantuml': {
\ 'exec': ['java -jar ~/bin/plantuml.jar %S:p:h', 'display %S:p:r.png', 'rm %S:p:r.png'],
\ 'outputter': 'null',
\ },
\}
As you can see, the outputter property serves more as a stdout, and exec can act as a command , it all depends on the task.
Bye everyone
To compile and run the current file, use the command : QuickRun . Constantly typing it is not very convenient, therefore I advise you to define an alias in your .vimrc file.
Example
nmap :w:QuickRun
Статья оказалась не очень большой, но не стоит расстраиваться, впереди еще много интересного!