vim-alias


Ⅰ. 插件描述

versatile Vim command-line aliases

Ⅱ. 基本信息

创建日期:  2003-08-25
使用用户:  12
Github星:  38
插件作者:  Enno Nagel

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'konfekt/vim-alias'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'konfekt/vim-alias'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'konfekt/vim-alias'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/konfekt/vim-alias

Ⅳ. 文档说明

# vim-alias

This plugin lets you define command-line abbreviations that only expand at the beginning of the command-line prompt by a command :Alias.
These command-line abbreviations work like the bash aliases, except that the alias is substituted in-place.

Check out why an alias is most often preferable to a <leader> mapping!

Usage

    :Alias[!] [-range] [-buffer] <lhs> <rhs>
    :UnAlias [-buffer] <lhs> ...
    :Aliases [-buffer] [lhs] ...
  • To create an Alias, use :Alias.

    Pass the optional parameters `-buffer` or `-range` to to create a buffer-local alias or one that accepts a range preceding the alias.
    To override an existing alias, append `!` to `:Alias`.
  • To remove an alias, use :UnAlias.
  • To list all aliases, use :Aliases.

    Restrict the output to all aliases whose name contains `...` by appending `...`.
    

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 -range     il   ilist\ /\v/<left><c-r>=EatChar("\ ")<cr>
    :Alias -range     dl   dlist\ //<left><c-r>=EatChar("\ ")<cr>
    :Alias            g    Silent\ git
    :Alias            gbl  Silent\ tig\ blame\ +<c-r>=line('.')<cr>\ --\ %<c-left><c-left><left>
    :Alias -range     tl   !translate\ -no-warn\ -no-ansi\ -brief\ -to
    :Alias            g!   g!
    :UnAlias          g
    :Aliases

See :help abbreviations for Eatchar(c).
The command :Silent is defined as

    if has('unix')
        command! -complete=shellcmd -nargs=1 -bang Silent execute ':silent<bang> !' . <q-args> | execute ':redraw!'
    elseif has('win32')
        command! -complete=shellcmd -nargs=1 -bang Silent execute ':silent<bang> !start /b ' . <q-args> | execute ':redraw!'
    endif

The executable tig is a text-mode interface for git and translate-shell a command-line translator.

Configuration

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

  let g:cmdalias_cmdprefixes = [
    \ '\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!! ...),
  • moving functions to autoload for faster startup of Vim,
  • 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.

添加新评论