vim-syntax-expand


Ⅰ. 插件描述

Expand characters to code if not in a comment or string

Ⅱ. 基本信息

创建日期:  2015-06-12
使用用户:  3
Github星:  13
插件作者:  Oliver Caldwell

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'olical/vim-syntax-expand-own-character'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

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

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'olical/vim-syntax-expand-own-character'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'olical/vim-syntax-expand-own-character'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

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

Ⅳ. 文档说明

# vim-syntax-expand

This contains functions to expand a character to a string as long as your cursor isn't currently inside a string or comment syntax element. This essentially allows you to have single character abbreviations that only apply to actual syntax. Please check the doc directory for more information.

Here's how I use it with conceal in JavaScript to create a cute language on top of JavaScript that doesn't affect anyone else.

asciicast

Installation

Use your favourite plugin manager, you know the drill. I like [vim-plug][], so here's how you'd install it with that.

Plug 'Wolfy87/vim-syntax-expand'

Usage

Here's my example configuration for JavaScript. The conceal functionality is provided by [vim-javascript][] (which is fantastic).

" Map the conceal characters to their expanded forms (only for javascript files)
autocmd FileType javascript inoremap <silent> <buffer> @ <C-r>=syntax_expand#expand("@", "this")<CR>
autocmd FileType javascript inoremap <silent> <buffer> # <C-r>=syntax_expand#expand("#", ".prototype.")<CR>
autocmd FileType javascript inoremap <silent> <buffer> < <C-r>=syntax_expand#expand_head("<", "return")<CR>

" Keeps everything concealed at all times. Even when my cursor is on the word.
set conceallevel=1
set concealcursor=nvic

" JavaScript thanks to pangloss/vim-javascript
let g:javascript_conceal_function = "λ"
let g:javascript_conceal_this = "@"
let g:javascript_conceal_return = "<"
let g:javascript_conceal_prototype = "#"

So now when I type @ it is actually expanded to this but I still see it as @. Cool, right? This will work for other languages too, you just need to set up your conceal rules (there's usually a plugin) and some expansion bindings.

Author

[Oliver Caldwell][] / [@OliverCaldwell][]

Unlicenced

Find the full [unlicense][] in the UNLICENSE file, but here's a snippet.

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

Do what you want. Learn as much as you can. Unlicense more software.

添加新评论