Ⅰ. 插件描述
Vim constext filetypeⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'osyo-manga/vim-precious'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'osyo-manga/vim-precious'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'osyo-manga/vim-precious'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/osyo-manga/vim-precious
Ⅳ. 文档说明
# precious.vim
現在のカーソル位置のコンテキストによって filetype を切り換える為のプラグインです。
Set the buffer filetype based on the code block the cursor currently resides in.
The code block filetype is determined by the context_filetype.vim plugin.
Requirement
- context_filetype.vim
<Plug>(textobj-precious-i)を使用したい時のみ必要。
<Plug>(precious-quickrun-op)を使用したい時のみ必要。
Screencapture

Supported
c
- masm
- gas
cpp
- masm
- gas
d
- masm
eruby
- ruby
help
- vim
html
- javascript
- coffee
- css
int-nyaos
- lua
lua
- vim
nyaos
- lua
perl16
- pir
python
- vim
vim
- python
- ruby
- lua
vimshell
- vim
xhtml
- javascript
- coffee
- css
- markdown
Example
" test.vim
" set filetype=vim --------------------------------------------------
echo "hello, world"
" set filetype=ruby -----------------------------
ruby << EOF
result = (1..10).map(&:to_s).join("-")
puts result
EOF
"---------------------------------------------------------
" set filetype=python ----------------------------
python << EOF
print map(str, range(1, 10))
print "-".join(map(str, range(1, 10)))
EOF
"---------------------------------------------------------
echo join(range(10), "-")
" autocmd
" コンテキストに入った時の処理をフック
augroup test
autocmd!
autocmd User PreciousFileType :echo precious#context_filetype()
" ruby のコンテキストに入った時に tabstop を設定する
autocmd User PreciousFiletype_ruby :PreciousSetContextLocal tabstop=8
augroup END
" insert mode に入った時に 'filetype' を切り換える。
" カーソル移動時の自動切り替えを無効化
" let g:precious_enable_switch_CursorMoved = {
" \ "*" : 0
" \}
" let g:precious_enable_switch_CursorMoved_i = {
" \ "*" : 0
" \}
"
" " insert に入った時にスイッチし、抜けた時に元に戻す
" augroup test
" autocmd!
" autocmd InsertEnter * :PreciousSwitch
" autocmd InsertLeave * :PreciousReset
" augroup END
" quickrun.vim との連携
" <Space>qic で quickrun.vim する
" filetype が切り替わってない状態でも
" コンテキストから quickrun.vim で使用する type を決定
" nmap <Space>q <Plug>(precious-quickrun-op)
" omap ic <Plug>(textobj-precious-i)
" vmap ic <Plug>(textobj-precious-i)
"------------------------------------------------------------------------------Implementations
- コンテキストに入った時に自動的に filetype を切り換える
- コンテキストが切り替わった時に autocmd User で処理がフック出来る
- コンテキストの範囲の textobj に対応
quickrun.vim との連携
- コンテキストの範囲を quickrun する
- filetype が切り替わってない状態でも type を設定
TODO
- matcher、switcher を使用した機能の拡張
- matcher、switcher の優先順位付け
- コンテキストの範囲を取得