Vim plugins: Difference between revisions

From miki
Jump to navigation Jump to search
Line 573: Line 573:
tnoremap <expr> <esc> &filetype == 'fzf' ? "\<esc>" : "\<c-\>\<c-n>"
tnoremap <expr> <esc> &filetype == 'fzf' ? "\<esc>" : "\<c-\>\<c-n>"
</source>
</source>

=== airline ===
{| class=wikitable width=100%
|-
|width=72pt|
|width=72pt|[https://github.com/vim-airline/vim-airline GitHub]
!width=15%|vim-airline
|lean & mean status/tabline for vim that's light as air
|-
|width=72pt|
|width=72pt|[https://github.com/vim-airline/vim-airline-themes GitHub]
!width=15%|vim-airline-themes
|A collection of themes for vim-airline
|-
|colspan=4|
|}
Note that ''gruvbox'' comes with a theme for ''airline''.


== Plugins to try ==
== Plugins to try ==

Revision as of 17:32, 17 November 2016

This page is about Vim plugins.

Overview

Find a plugin

Most plugins are found on vim.org or GitHub:

A mirror of all plugins originally found on http://www.vim.org/scripts/ ;
  • GitHub.

Install a plugin

The best is to use a plugin manager (see below). Otherwise,

  • Unzip the plugin in ~/.vim directory (or plugin, autoload...)
  • Generate the help tags with:
helptags ~/.vim/tags

Getting help

Most plugins come with local help files. Do :help local-additions to get a list of help files for locally installed plugins.

Plugin Managers

Here I list various plugin managers. My current favorite is vim-plug.

apt-vim

Fully-automated, Cross-platform Plugin Manager for Vim.

Pathogen

Plugin manager from Tim Pope.

VIM (vim-addon-manager)

VAM manage and install vim plugins (including their dependencies) in a sane way.

vim-plug

Plugin manager from junegunn, author of fzf, vim-easy-align.

Interaction with $HOME version control

If we store our HOME files (dot-files) in git, we can't store the plugins anymore because they are fetched and stored locally as squashed git submodules. We can circumvent this by managing these plugins as git submodules.

First create .gitmodules:

[submodule "ack.vim"]
    path = .vim/plugged/ack.vim
    url = ./.vim/plugged/ack.vim
[submodule "auto-pairs"]
    path = .vim/plugged/auto-pairs
    url = ./.vim/plugged/auto-pairs
[submodule "a.vim"]
    path = .vim/plugged/a.vim
    url = ./.vim/plugged/a.vim

Then create the bare repositories:

git clone --bare /home/peetersm home.git
cd home.git/
mkdir -p .vim/plugged
cd .vim/plugged
for g in ~/.vim/plugged/*; do git clone --bare $g; done

Then, to clone the HOME repository:

git clone --recursive .../home.git

Finally we must update the tags file in vim. Start vim and run PlugInstall!. Ignore the error messages.


Troubleshooting
  • Using short path may fail if plugin name has an extension. For instance:
" The following FAILS because of trailing .vim
Plug 'ctrlpvim/ctrlp.vim'
" Use the following instead.
Plug 'https://github.com/ctrlpvim/ctrlp.vim.git'
  • Conditional plugin activation.
See the FAQ.

Installed plugins

Plugins I'm currently using.

SnipMate

snipMate : TextMate-style snippets for Vim

Some snippets:

#### C ####
main  main()
inc   #include <...>
Inc   #include "..."
Def   #ifndef ... #define ... #endif
def   #define
ifdef #ifdef ... #endif
#if   #if ... #endif
once  #ifndef HEADER_H .... # define HEADER_H ... #endif (Header Include-Guard)
if    If (...) { ... } 
el    else { ... } 
t     ... ? ... : ... (tertiary conditional)
do    do ... while ( ... )
wh    while (...) { ... }
for   for (... = 0; ...; ...) { ... }
forr  for (... = ...; ...; ...) { ... }
fun   ... function(...) { ... }
fund  ... function(...;)
td    typedef
st    struct
tds   typedef struct
tde   typedef enum
pr    printf
fpr   fprintf
.     [ ... ]
un    unsigned
#### C++ ####
readfile  snippet for reading file
map       std::map<... , ...> map...
vector    std::vector<...> v...
ns        namespace ... { ... }
cl        class { public: ... private: };

A

a.vim : Alternate Files quickly (.c --> .h etc) (forked version, the original version)

AutoTag

AutoTag : Updates entries in a tags file automatically when saving

Surround

surround.vim : Delete/change/add parentheses/quotes/XML-tags/much more with ease (github)

Repeat

Install repeat.vim : Use the repeat command (.) with supported plugins

tComment

tComment : An extensible & universal comment plugin that also handles embedded filetypes

Smart Tabs

Smart Tabs : Use tabs for indent, spaces for alignment

Cpp.vim

cpp.vim: General C++ Settings (no indentation for namespace...)

(disabled highlight of leading tabs, line length overruns, unit test header test + nice AlterColour function that computes new colour...)

CScope

CScope (also mirrored on GitHub)

Auto-Pairs

vim.org GitHub auto-pairs Vim plugin, insert or delete brackets, parens, quotes in pair
M-e )wrapme)
M-n Jump to next closed pair

Tested on NeoVim: undoable and dot-repeatable (.) (and should be the same on vim 7.4.849+).

Works better than ClosePairs and similar.

More auto-close plugins or similar:

Tested on NeoVim: undo broken but dot-repeatable (.).
Tested on NeoVim: undoable and dot-repeatable (.) (and should be the same on vim 7.4.849+).
breaks undo / dot-repeat (tested on neovim). Nice support of triple apostrophe.
Requires Python.
Tested on NeoVim: undo broken but dot-repeatable (.).

More on auto-close plugins:

More on the issue of dot-repeat (with list of plugins):

Vim BufStat

Vim BufStat

" GRB: use fancy buffer closing that doesn't close the split
cnoremap <expr> bd (getcmdtype() == ':' ? 'Bclose' : 'bd')

LustyExplorer

vim.org GitHub LustyExplorer Dynamic filesystem and buffer explore
More recent GitHub (merged with LustyJuggler)

FuzzyFinder

FuzzyFinder : buffer/file/command/tag/etc explorer with fuzzy matching

  • Alternative, Command-T (inspired from TextMate)
  • See also Super-Finder in Vim (using FuzzyFinder)
  • After :set path=/path/to/project/**, one can do :find filename.ext (See [6], more details at [7])
  • To find a file in a sub-directory, use the fuzzy query **/filename

Vim-LaTeX

vim-latex (documentation See page vim-latex.

SparkUp

Sparkup — A parser for a condensed HTML format Use ^e in edit mode to extend sparkup text, and ^n to go to next empty item. Some examples (more at Zen Coding:

div#page.section.main
div[title] 
a[title="Hello world" rel] 
td[colspan=2]
ul > li*5
li.item$$$*3
div#page>(div#header>ul#nav>li*4>a)+(div#page>(h1>span)+p*2)+div#footer
#content>.section
div#content>div.section
p>{Click }+a{here}+{ to continue}

MatchIt

matchit.zip : extended % matching for HTML, LaTeX, and many other languages

VimWiki

vim.org GitHub vimwiki Personal Wiki for Vim
S-CR Continue list
gq Quote text block with {{{ ... }}}

To quote a text block with {{{ ... }}} in visual mode, add to ~/.vim/ftplugin/vimwiki_custom.vim:

" Quote a block of text with {{{ }}} in visual mode
:vmap gq DO {{{<CR><ESC>P

ack.vim

GitHub ack.vim Vim plugin for the Perl module / CLI script 'ack'

I fell back to this plugin because ag.vim is stalled. But we can still use ag as search engine.

My settings [8]:

if executable('ag')
  " Use ag over grep - See ag man page for option '--vimgrep'
  set grepprg=ag\ --vimgrep\ $*
  set grepformat=%f:%l:%c:%m

  " bind K to grep word under cursor
  nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
  let g:ackprg = 'ag --vimgrep'
  " Allow lowercase command 'ag' - see http://vim.wikia.com/wiki/Replace_a_builtin_command_using_cabbrev
  cnoreabbrev ag <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Ack' : 'ag')<CR>
endif

ctrlp.vim

vim.org GitHub ctrlp.vim Active fork of kien/ctrlp.vim—Fuzzy file, buffer, mru, tag, etc finder. home
^p Invoke CtrlP ^j ^k Navigate list ^z ^o Mark/unmark, open
F5 Refresh cache ^t Open new tab :diffthis Compare marked files
^f ^b Cycle between modes ^v ^x Open new split
^d Switch filename/full ^n ^p Next/prev hist
^r Switch regexp mode ^y Create new file

Currently works best using ag (this and [9]) as file scanner and cpsm as match engine.

My settings:

" Set root directory
let g:ctrlp_working_path_mode = 'rwa'

" Enable filename search (instead of full path) - Ctrl-D to switch
let g:ctrlp_by_filename = 1
"
"  Use AG for look-up. See https://robots.thoughtbot.com/faster-grepping-in-vim
if executable('ag')
  " Use ag in CtrlP for listing files. Lightning fast and DOESN'T respect .gitignore
  let g:ctrlp_user_command = 'ag %s -U -l --nocolor -g ""'

  " ag is fast enough that CtrlP doesn't need to cache - BUT we are on a slow filesystem
  " let g:ctrlp_use_caching = 0
endif

Conque

conque.vim: Run interactive commands inside a Vim buffer.

Mcf-make-target

mcf-make-target: Persistent make target in Vim This plugin lets Vim to store the last arguments passed to make, and use that argument when make is invoked without arguments. For ease, define the following macro:

:nmap <F5> :wa<CR>:Make<CR>:cw<CR>             # Note the capital M to Make

To build a custom target:

:Make <targetname>           # first invocation. Store targetname for future use
<F5>                         # next

Vim-gitgutter

GitHub vim-gitgutter A Vim plugin which shows a git diff in the gutter (sign column) and stages/undoes hunks

Fugitive

vim.org GitHub fugitive.vim A Git wrapper so awesome, it should be illegal

Add to .vimrc:

set diffopt+=vertical                       " Favor vertical split for vimdiff

Some commands:

" Gdiff
:Gdiff                                      " View differences with index
:Gdiff HEAD                                 " View differences with HEAD
:Gdiff -                                    " View differences with HEAD
:Gdiff ^                                    " View differences with previous commit
:Gdiff ~3                                   " View differences with 3 commits ago

" Glog
:Glog                                       " Open log of commits impacting current file

" Gedit
:Gedit                                      " Edit back current file

Vim-easymotion

vim.org GitHub vim-easymotion Vim motions on speed!
\\w \\f Horizontal move
\\j \\k Vertical move
Example configuration
" <Leader>f{char} to move to {char}
map  <Leader>f <Plug>(easymotion-bd-f)
nmap <Leader>f <Plug>(easymotion-overwin-f)

" s{char}{char} to move to {char}{char}
nmap s <Plug>(easymotion-overwin-f2)

" Move to line
map <Leader>L <Plug>(easymotion-bd-jk)
nmap <Leader>L <Plug>(easymotion-overwin-line)

" Move to word
map  <Leader>w <Plug>(easymotion-bd-w)
nmap <Leader>w <Plug>(easymotion-overwin-w)

Vim-incsearch

vim.org GitHub incsearch.vim Improved incremental searching for Vim
GitHub incsearch-easymotion.vim Integration between incsearch and easymotion
Tab Move cursor to next match
S-Tab Move cursor to previous match

See website for more features (including fuzzy search, etc.).

Integration with easy-motion
" You can use other keymappings like <C-l> instead of <CR> if you want to
" use these mappings as default search and somtimes want to move cursor with
" EasyMotion.
function! s:incsearch_config(...) abort
  return incsearch#util#deepextend(deepcopy({
  \   'modules': [incsearch#config#easymotion#module({'overwin': 1})],
  \   'keymap': {
  \     "\<CR>": '<Over>(easymotion)'
  \   },
  \   'is_expr': 0
  \ }), get(a:, 1, {}))
endfunction

noremap <silent><expr> /  incsearch#go(<SID>incsearch_config())
noremap <silent><expr> ?  incsearch#go(<SID>incsearch_config({'command': '?'}))
noremap <silent><expr> g/ incsearch#go(<SID>incsearch_config({'is_stay': 1}))

Vim-easy-align

GitHub vim-easy-align A Vim alignment plugin
gaip*= Auto-align around all occurences of =

Supertab

vim.org GitHub Supertab Perform all your vim insert mode completions with Tab
Tab Complete, insert

cpsm

GitHub cpsm A CtrlP matcher, specialized for paths.
C-p Ctrl-P file mode
C-o Ctrl-P MRU mode

fzf.vim

GitHub fzf.vim fzf :heart: vim
C-p Ctrl-P file mode
C-o Ctrl-P MRU mode
Neovim

fzf.vim uses neovim terminal emulator. Use this mapping to have esc key leave fzf, but go to normal mode in other terminals [10]:

tnoremap <expr> <esc> &filetype == 'fzf' ? "\<esc>" : "\<c-\>\<c-n>"

airline

GitHub vim-airline lean & mean status/tabline for vim that's light as air
GitHub vim-airline-themes A collection of themes for vim-airline

Note that gruvbox comes with a theme for airline.

Plugins to try

Plugins I need to try or install some day.

Some videos that illustrates those plugins:

vim.org GitHub unimpaired.vim Pairs of handy bracket mappings
For interaction with plugin fugitive, and quickfix mappings [q, ]q, [Q, and ]Q.
vim.org GitHub ifdef-highlighting #ifdef highlighting in c/c++/idl
GitHub vim-bufferline Super simple vim plugin to show the list of buffers in the command bar
GitHub VimFold4C Vim folding ftplugin for C & C++ (and similar langages)

Interesting plugin, but does not handle well nested #ifdef it seems.

GitHub GoldenView.Vim Always have a nice view for vim split windows! http://zhaocai.github.io/GoldenView.Vim/

Uninstalled plugins

Plugins I'm no longer using.

EasyTags

easytags.vim : Automated tag file generation and syntax highlighting of tags in Vim

  • Replaced by AutoTag — syntax highlighting of tags is limited to c files; moreover AutoTag has a clever way to look for the tags file in project hierarchy.

AutoClose

vim.org GitHub AutoClose Inserts matching bracket, paren, brace or quote

Don't like it much because inserting the closing pair will jump out of nested pair, which is annoying when one try to simply insert a closing brace (but a solution is to use the Surround plugin to surround some selected text with braces).

ClosePairs

vim.org GitHub ClosePairs Auto closes pairs of characters

simpler than AutoClose, and can also delete pair of braces at once with <BS>. However breaks undo and not dot-repeatable.

Below is a patch to push down the closing brace when typing { twice (inspired from AutoClose plugin).

Trinity.vim

trinity.vim : Build the trinity of srcexpl, taglist, NERD_tree to be a good IDE

MiniBufExpl

minibufexpl.vim : Elegant buffer explorer - takes very little screen space

  • 1st attempt: No real tab support. Seems to interfere with trinity plugin. Interesting key bindings inside though. To reassess...
  • 2nd attempt: Don't care about tabs, the idea is to fully replace tabs with buffers since most plugins interface better with buffers. Disabled

trinity plugin.

  • Closing a buffer: Use d in minibufexpl window to close a buffer, or :bd[elete] seems to work most of the time.
  • Uninstalled because found better alternative (bufstat)

LustyJuggler

vim.org GitHub LustyJuggler Switch very quickly among your active buffers
More recent GitHub (merged with LustyExplorer

Removed because I don't use it. LustyExplorer, NERDTree and FuzzyFinder are much better alternatives.

LaTeX Text Formatter

Latex Text Formatter : This scripts makes it easier to format latex text

  • Does not work well (line too short, line merge too aggressive)

Calendar

calendar.vim - A calendar application for Vim

  • :Calendar to launch. < and > to cycle through views, E and T to view Event list or Task list.
  • :Calendar 2001 1 1 to focus a specific date.

My settings in .vimrc:

" ----- Vim-Calendar ---------------------------------------------------------
let g:calendar_week_number=1
let g:calendar_first_day='monday'

DiffChanges

diffchanges.vim : Show changes made to current buffer since the last save

  • Never used. Functionality quite limited (only compared with last save). And if file is stored in Git, plugin fugitive is a much better alternative.

MRU

mru.vim : Plugin to manage Most Recently Used (MRU) files

  • Never used. And same functionality is available in Ctrl-P plugin anyway.

Git-file

git:file.vim : open any version of a file in git For instance, to open file filename.c at commit HEAD~4:

vim HEAD~4:./filename.c
  • Never used. Similar functionality available in plugin fugitive.

Align

vim.org GitHub Align Help folks to align text, eqns, declarations, tables, etc
see examples.

Let's give vim-easy-align a try instead.

Hexman

vim.org GitHub Hexman Simpler Hex viewing and editing

Uninstalled because it contains the sign of the devil... Well, no, in fact because I don't use it much and standard mappings interfere with vim-gitgutter.