vim-alias

versatile Vim command-line aliases

3 years after

vim-alias

This plugin lets you define command-line abbreviations by :Alias which only expand at the beginning of the command prompt.

You can pass the optional parameters

-buffer or -range

to create a buffer local alias or one that accepts a range preceding the alias.

These command line abbreviations work like the bash aliases, except that the alias is substituted in-place.

Usage

    :Alias [-range] [-buffer] <lhs> <rhs>
    :UnAlias <lhs> ...
    :Aliases [<lhs> ...]

To define the Aliases after Vim has started up, define them in ~/.vim/after/plugin/alias.vim, or add to ~/.vimrc

if exists('s:loaded_vimafter')
  silent doautocmd VimAfter VimEnter *
else
  let s:loaded_vimafter = 1
  augroup VimAfter
    autocmd!
    autocmd VimEnter * source ~/.vim/after/vimrc.vim
  augroup END
endif

and define them in ~/.vim/after/vimrc.vim.

Examples:

    :Alias   -range   dg   <c-r>=&l:diff?"diffget":"dg"<cr>
    :Alias   -buffer  spl  setlocal\ spell<bar>setlocal\ spelllang=en
    :Alias            w!!  write\ !sudo\ tee\ >\ /dev/null\ %
    :Alias            F    find\ *<c-r>=Eatchar("\ ")<cr>
    :Alias            th   tab\ help
    :Alias            sft  setfiletype
    :Alias            g    !git
    :UnAlias          g
    :Aliases

See :help abbreviations for Eatchar(c).

Configuration

The variable g:cmdaliasCmdPrefixes lists the patterns of all commands by which an alias command may be preceded and yet expand. It defaults to

  let g:cmdaliasCmdPrefixes = [
    \ '\d*verb\%[ose]', 'debug', 'sil\%[ent]!\?', 'uns\%[ilent]', 'redir\?!\?',
    \ '.*[^|]|',
    \ 'ld!\?', '[cl]fd!\?', '[cl]f\?do!\?',
    \ '\%(\%([.$]\|\d\+\)\%([,;]\%([.$]\|\d\+\)\)*\)\?\s*' .
    \ '\%(argdo\?!\?\|bufdo\?!\?\|windo\?\|tabdo\?\)' ]

Installation

If you use vim-plug, then add the following line to your vimrc file:

Plug 'Konfekt/vim-alias'

Credits

This plugin builds and improves on cmdalias.vim 3.0 by Hari Krishna Dara by

  • allowing for aliases of commands preceded by a range (like :Alias -range dg diffget),
  • allowing for alias names ending in non-word chars (like :Alias w!! ...),
  • having a Vim documentation, and
  • more checks for proper usage, more consistent parameter parsing and a finer check for blanks or commands (such as : silent! ) preceding the alias.

Related Repositories

chromium-vim

chromium-vim

Vim bindings for Google Chrome. ...

targets.vim

targets.vim

Vim plugin that provides additional text objects ...

vim-session

vim-session

Extended session management for Vim (:mksession on steroids) ...

simplenote.vim

simplenote.vim

vim plugin to interact with the simplenote service ...

vim-geeknote

vim-geeknote

Vim plugin for Geeknote ...


Top Contributors

Konfekt AndrewRadev blueyed

Releases

-   3.0 zip tar
-   2.0 zip tar
-   1.3 zip tar
-   1.2 zip tar
-   1.1 zip tar
-   1.0 zip tar