📜 ⬆️ ⬇️

Unite extension overview and setup

I was surprised that at Habré there is no description of the Unite extension, which allows you to replace just a huge number of plug-ins for Vim. Unite combines the functionality of such extensions as: CtrlP, FuzzyFinder, ack, yankring, LustyJuggler, buffer explorer, etc.



Unite installation


Before you start setting up an extension, you must install dependencies. I use Vundle, so we will install through it. To access some Unite features, a vimproc plugin is required. To do this, add the following lines to our .vimrc file:

Bundle 'Shougo/vimproc.vim' Bundle 'Shougo/unite.vim' 

Restart the editor and enter the command: BundleInstall. Compile vimproc:
')
 cd ~ cd .vim/bundle/vimproc.vim make -f make_mac.mak #    ,  Linux: make_unix.mak 

Installation of all dependences is complete, proceed to the Unite configuration. Let's add the following lines to vimrc:

 "  insert mode let g:unite_enable_start_insert = 1 "  Unite     let g:unite_split_rule = "botright" "     let g:unite_force_overwrite_statusline = 0 "   Unite let g:unite_winheight = 10 "   let g:unite_candidate_icon="" 

Let's look at some Unite commands:
TeamDescription
Unite fileopen the list of files and directories in the current project
Unite buffershow open buffers
Unite file buffershow files and open buffers

The Unite command also supports options, for example, by running Unite with the -auto-preview option, we will launch Unite with the file preview function (as in Sublime).

If you need to go through files recursively, that is, search for the current project simply by entering the initial letters of the file as in CtrlP and Command-T, you just need to run Unite with the flag file_rec / async, I want to warn you that this option will not work without vimproc assembly :

 Unite file_rec/async 

To search by the first letters entered, you need to add the -start-insert option:

 Unite file_rec/async -start-insert 

And finally, the end result of the team I tied to the combination leader + f

 nnoremap <leader>f :<Cu>Unite -buffer-name=files -start-insert buffer file_rec/async:!<cr> 

Screenshot editor running Unite



Unite also has a command mode that is triggered by pressing the Ctrl + i key in the open Unite buffer. Command mode allows you to create and compare files, directories, create bookmarks, perform grep, etc. By the way, you can view the list of bookmarks with the command: Unite bookmark, and you can add a file to the bookmarks from command mode.

Create your own menu in Unite


In Unite, you can create your own menu (thanks to the hm- user gmist ). Usage example:

 let g:unite_source_menu_menus = {} let g:unite_source_menu_menus.mymenu = { \ 'description' : 'My Unite menu', \ } let g:unite_source_menu_menus.mymenu.candidates = { \ 'mru&buffer' : 'Unite buffer file_mru', \ 'tag' : 'Unite tag', \ 'file' : 'Unite file', \ 'file_rec' : 'Unite file_rec', \ 'file_rec/async' : 'Unite file_rec/async', \ 'find' : 'Unite find', \ 'grep' : 'Unite grep', \ 'register' : 'Unite register', \ 'bookmark' : 'Unite bookmark', \ 'output' : 'Unite output', \ } function g:unite_source_menu_menus.mymenu.map(key, value) return { \ 'word' : a:key, 'kind' : 'command', \ 'action__command' : a:value, \ } endfunction 


You can start the menu with the command

 :Unite menu:mymenu 


Some more examples of Unite work


Search a file as in CtrlP
 :Unite file_rec/async 

Work example


Search as in ack.vim
 :Unite grep:. 

Work example


Search by history in yankring / yankstack
 let g:unite_source_history_yank_enable = 1 :Unite history/yank 

Work example


Switching buffers as in LustyJuggler
 :Unite -quick-match buffer 

Work example


Project page

Source: https://habr.com/ru/post/201564/


All Articles