vim-symbol


Ⅰ. 插件描述

A buffer-local symbol-list plugin

Ⅱ. 基本信息

创建日期:  2012-10-30
使用用户:  2
Github星:  27
插件作者:  Matt Sacks

Ⅲ. 安装方法

使用Vundle管理器安装

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

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

使用NeoBundle管理器安装

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

使用VimPlug管理器安装

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

使用Pathogen管理器安装

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

Ⅳ. 文档说明

# symbol.vim

Jump to a matched string via regular expressions with customizable expressions per filetype. Includes a CtrlP extension for fast filtering.

Use

Use :Symbol {fuzzy string} to find any matched symbols in the current buffer and navigate to them.

Built-in filetypes:

  • HTML, ERB, Mustache, Handlebars
  • SCSS (with support for nested contexts)
  • JavaScript, CoffeeScript
  • Vim

See the Adding Definitions section for information on adding additional definitions and filetypes.

CtrlP

An extension for CtrlP is included for quick filtering to the list of gathered symbols in the current buffer.

In your .vimrc, add the following:

let g:ctrlp_extensions = ['symbol']

The :CtrlPSymbol command will be available in any filetype included in g:symbol_patterns.

Adding Definitions

Given a filetype and a regular expression, the :Symbol command can jump to any line that matches that regular expression. To add a single expression for one filetype, here's an example of a line from your .vimrc:

let g:symbol_patterns['javascript'] = '\.prototype.\zs\w\+\ze\ = function'

This will match any text in a javascript filetype that comes after .prototype. but must also followed by a space, an =, another space, and function. For instance, this will match: Thing.prototype.test = function with test.

To add multiple definitions (and multiple definitions for a single filetype):

let g:symbol_patterns = {
  \ 'javascript': [
    \ 'var \zs\w\+\>\ze ='
  \ ],
  \ 'html': [
    \ 'id="\zs.\+\ze"',
    \ 'class="\zs.\+\ze"'
  \ ]
\ }

Function Definitions

Function defintions are also available, where the first argument will be the line and the second argument will be the line number.

Return a string to set a symbol for the line, or return 0 to ignore matching a symbol on that line.

function! CountIndent(linestr, line)
  let indent = indent(a:line)
  if indent <= 2
    return matchstr(a:linestr, '\w\+\ze\s')
  else 
    return 0
  endif
endfunction

let g:symbol_patterns['scss'] = function('CountIndent')

Feedback

Let me know what you think, I'm @mattsacks on Twitter and GitHub.

添加新评论