Ⅰ. 插件描述
GorillaScript vim pluginⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'unc0/vim-gorilla-script'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'unc0/vim-gorilla-script'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'unc0/vim-gorilla-script'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/unc0/vim-gorilla-script
Ⅳ. 文档说明
This project adds [GorillaScript] support to the vim editor. It handles syntax,
indenting, compiling, and more. Also included is support for GorillaScript in
HTML.
Install with Unbundle
Since this plugin has rolling versions based on git commits, using unbundle and
git is the preferred way to install. The plugin ends up contained in its own
directory and updates are just a git pull away.
- Git clone sunaku's [unbundle] into
~/.vim/bundle/and add this line to your
vimrc:
syntax enable
runtime bundle/vim-unbundle/unbundle.vimCreate and change into
~/.vim/ftbundle/gorilla:$ mkdir -p ~/.vim/ftbundle/gorilla $ cd ~/.vim/ftbundle/gorillaMake a clone of the
vim-gorilla-scriptrepository:$ git clone https://github.com/unc0/vim-gorilla-script.git
Updating
Change into
~/.vim/ftbundle/gorilla/vim-gorilla-script/:$ cd ~/.vim/ftbundle/gorilla/vim-gorilla-scriptPull in the latest changes:
$ git pull
Compile to JavaScript
A gorilla wrapper for use with :make is enabled automatically for gorilla
files if no other compiler is loaded. To enable it manually, run
:compiler gorilla
The :make command is then configured to use the gorilla compiler and
recognize its errors. I've included a quick reference here but be sure to check
out :help :make for a full reference of the command.
Consider the full signature of a :make call as
:[silent] make[!] [GORILLA-OPTIONS]...
By default :make shows all compiler output and jumps to the first line
reported as an error. Compiler output can be hidden with a leading :silent:
:silent make
Line-jumping can be turned off by adding a bang:
:make!
GORILLA-OPTIONS given to :make are passed along to gorilla (see alsogorilla_make_options):
:make --bare --output /some/dir
Configuration: gorilla_compiler,gorilla_make_options
The quickfix window
Compiler errors are added to the [quickfix] list by :make, but the quickfix
window isn't automatically shown. The :cwindow command will pop up
the quickfix window if there are any errors:
:make
:cwindow
This is usually the desired behavior, so you may want to add an autocmd to your
vimrc to do this automatically:
autocmd QuickFixCmdPost * nested cwindow | redraw!The redraw! command is needed to fix a redrawing quirk in terminal vim, but
can removed for gVim.
Recompile on write
To recompile a file when it's written, add an BufWritePost autocmd to your
vimrc:
autocmd BufWritePost *.gs silent make!GorillaCompile: Compile GorillaScript Snippets
GorillaCompile shows how the current file or a snippet of GorillaScript is
compiled to JavaScript.
:[RANGE] GorillaCompile [vert[ical]] [WINDOW-SIZE]
Calling :GorillaCompile without a range compiles the whole file.
Calling :GorillaCompile with a range, like in visual mode, compiles the selected
snippet of GorillaScript.
Each file gets its own GorillaCompile buffer, and the same buffer is used for all
future calls of :GorillaCompile on that file. It can be quickly closed by
hitting q in normal mode.
Using vert opens the GorillaCompile buffer vertically instead of horizontally
(see also gorilla_compile_vert):
:GorillaCompile vert
Set the gorilla_compile_vert variable to split the buffer vertically by
default:
let gorilla_compile_vert = 1By default the GorillaCompile buffer splits the source buffer in half, but this
can be overridden by passing in a WINDOW-SIZE:
:GorillaCompile 4
Configuration: gorilla_compiler,gorilla_compile_vert
Quick syntax checking
If compiling a snippet results in a compiler error, GorillaCompile adds that
error to the [quickfix] list.
GorillaWatch: Live Preview Compiling
GorillaWatch emulates using the Try GorillaScript preview box on the [GorillaScript
homepage][GorillaScript].
GorillaWatch takes the same options as GorillaCompile:
:GorillaWatch [vert[ical]] [WINDOW-SIZE]
After a source buffer is watched, leaving insert mode or saving the file fires
off a recompile of the GorillaScript.
You can force recompilation by calling :GorillaWatch.
To get synchronized scrolling of the source buffer and GorillaWatch buffer, set'scrollbind'
on each:
:setl scrollbind
Configuration: gorilla_compiler,gorilla_watch_vert
GorillaRun: Run GorillaScript Snippets
GorillaRun compiles the current file or selected snippet and runs the resulting
JavaScript.
The command has two forms:
:GorillaRun [PROGRAM-OPTIONS]...
This form applies when no RANGE is given or when the given range is 1,$
(first line to last line). It allows passing PROGRAM-OPTIONS to your compiled
- The filename is passed directly to
gorillaso you must save the file - your changes to take effect.
:RANGE GorillaRun [COFFEE-OPTIONS]...
This form applies with all other ranges. It compiles and runs the lines within
the given RANGE and any extra COFFEE-OPTIONS are passed to gorilla.
Configuration: gorilla_compiler,gorilla_run_vert
GorillaScript in HTML
GorillaScript is highlighted and indented within
<script type="text/gorillascript">
</script>blocks in html files.
Custom Autocmds
You can define commands to be ran automatically on these
custom events.
In all cases, the name of the command running the event (GorillaCompile,GorillaWatch, or GorillaRun) is matched by the {pat} argument.
You can match all commands with a * or only specific commands by separating
them with a comma: GorillaCompile,GorillaWatch.
GorillaBufNew
GorillaBufNew is ran when a new scratch buffer is created. It's called from the
new buffer, so it can be used to do additional set up.
augroup GorillaBufNew
autocmd User * set wrap
augroup ENDUsed By: GorillaCompile, GorillaWatch, GorillaRun
GorillaBufUpdate
GorillaBufUpdate is ran when a scratch buffer is updated with output fromgorilla. It's called from the scratch buffer, so it can be used to alter the
compiled output.
" Switch back to the source buffer after updating.
augroup GorillaBufUpdate
autocmd User GorillaCompile,GorillaRun exec bufwinnr(b:gorilla_src_buf) 'wincmd w'
augroup ENDUsed By: GorillaCompile, GorillaWatch, GorillaRun
Configuration Variables
This is the full list of configuration variables available, with example
settings and default values. Use these in your vimrc to control the default
behavior.
gorilla_indent_keep_current
By default, the indent function matches the indent of the previous line if it
doesn't find a reason to indent or outdent. To change this behavior so it
instead keeps the current indent of the cursor, use
let gorilla_indent_keep_current = 1Default: unlet gorilla_indent_keep_current
Note that if you change this after a gorilla file has been loaded, you'll have to
reload the indent script for the change to take effect:
unlet b:did_indent | runtime indent/gorilla.vimgorilla_compiler
Path to the gorilla executable used by the Gorilla commands:
let gorilla_compiler = '/usr/bin/gorilla'Default: 'gorilla' (search $PATH for executable)
gorilla_make_options
Options to pass to gorilla with :make:
let gorilla_make_options = '--bare'Default: '' (nothing)
Note that gorilla_make_options is embedded into 'makeprg', so `:compiler
gorilla must be ran after changing gorilla_make_options` for the changes to take
effect.
gorilla_compile_vert
Open the GorillaCompile buffer with a vertical split instead of a horizontal
one:
let gorilla_compile_vert = 1Default: unlet gorilla_compile_vert
gorilla_watch_vert
Open the GorillaWatch buffer with a vertical split instead of a horizontal
one:
let gorilla_watch_vert = 1Default: unlet gorilla_watch_vert
gorilla_run_vert
Open the GorillaRun buffer with a vertical split instead of a horizontal
one:
let gorilla_run_vert = 1Default: unlet gorilla_run_vert
Configure Syntax Highlighting
Add these lines to your vimrc to disable the relevant syntax group.
Disable trailing whitespace error
Trailing whitespace is highlighted as an error by default. This can be disabled
with:
hi link GorillaSpaceError NONEDisable reserved words error
Reserved words like function and var are highlighted as an error where
they're not allowed in GorillaScript. This can be disabled with:
hi link gorillaReservedError NONETune Vim for GorillaScript
Changing these core settings can make vim more GorillaScript friendly.
Fold by indentation
Folding by indentation works well for GorillaScript functions and classes.
To fold by indentation in GorillaScript files, add this line to your vimrc:
autocmd BufNewFile,BufReadPost *.gs setl foldmethod=indent nofoldenableWith this, folding is disabled by default but can be quickly toggled per-file
by hitting zi. To enable folding by default, remove nofoldenable:
autocmd BufNewFile,BufReadPost *.gs setl foldmethod=indentTwo-space indentation
To get standard two-space indentation in GorillaScript files, add this line to
your vimrc:
autocmd BufNewFile,BufReadPost *.gs setl shiftwidth=2 expandtabCooperate with other plugins
[NERDCommenter]
let g:NERDCustomDelimiters.gorilla = {
\ 'left': '//',
\ 'leftAlt': '/*',
\ 'rightAlt': '*/',
\}[Phrase]
let g:phrase_ft_tbl.gorilla = {
\ "ext": "gs",
\ "cmt": ["/*", "*/"]
\}[Syntastic]
You should comment this autocmd out in your vimrc:
" autocmd BufWritePost *.gs silent make!Install Syntastic:
$ cd ~/.vim/bundle $ git clone https://github.com/scrooloose/syntastic.gitCopy/link the checker to syntastic:
$ mkdir -p syntastic/syntax_checkers/gorilla $ cd syntastic/syntax_checkers/gorilla $ ln -s ~/.vim/ftbundle/gorilla/vim-gorilla-script/syntastic_checker/gorilla.vim
[Tagbar]
Install Tagbar:
$ cd ~/.vim/bundle $ git clone https://github.com/majutsushi/tagbar.gitAdd this to your .ctags:
--langdef=gorilla --langmap=gorilla:.gs --regex-gorilla=/^let[ \t]+([A-Za-z0-9_$\-]+)[ \t]*=[ \t]*require/\1/e,module/ --regex-gorilla=/^let[ \t]+([A-Za-z0-9_$\-]+)[ \t]*=[ \t]*\{?$/\1/o,object/ --regex-gorilla=/^const[ \t]+([A-Z][A-Z0-9_\-]+)[ \t]*=/\1/C,constant/ --regex-gorilla=/^let[ \t]+([A-Za-z0-9_$\-]+)[ \t]*=[ \t]*#(\(.*\))?/\1/f,function/ --regex-gorilla=/^let[ \t]+([A-Za-z0-9_$\-]+)[ \t]*\(.*\)/\1/f,function/ --regex-gorilla=/^[^\/*]*class[ \t]+([A-Za-z0-9_$\-]+)/\1/c,class/ --regex-gorilla=/^[^\/*]*def[ \t]+([A-Za-z0-9_$\-]+)/\1/m,method/ --regex-gorilla=/^let[ \t]+([A-Za-z0-9_$\-]+)[ \t]*=[ \t]*\[/\1/a,array/ --regex-gorilla=/^let[ \t]+([^= ]+)[ \t]*=[ \t]*r'[^']*/\1/r,regex/ --regex-gorilla=/^let[ \t]+([^= ]+)[ \t]*=[ \t]*r"[^"]*/\1/r,regex/ --regex-gorilla=/^let[ \t]+([^= ]+)[ \t]*=[ \t]*[^"r]'[^']*/\1/s,string/ --regex-gorilla=/^let[ \t]+([^= ]+)[ \t]*=[ \t]*[^'r]"[^"]*/\1/s,string/Add this to your .vimrc:
let g:tagbar_type_gorilla = { \ 'ctagstype' : 'gorilla', \ 'kinds' : [ \ 'C:constant', \ 'e:module', \ 'f:function', \ 'c:class', \ 'a:array', \ 'o:object', \ 'r:regex', \ 's:string' \ ], \ 'sro' : ".", \}