vimでautocmdの影響範囲を局所化する プレゼンツールの自動コマンド実行

@fukataさん作のプレゼンテーションツール Presentation https://github.com/fukata/Presentation

http://fukata.org/2011/11/03/management-of-lightning-talks-slides-at-programmer/

即時反映の方法を、.vimrcに書くと全体の設定に影響するので、局所的に抑えてみた。

~/.vim/ftplugin/presen.vim

" Vim filetype plugin
" Language:             Presentation
" Maintainer:           smeghead <smeghead7@gmail.com>
" Last Change:          2011-11-11
 
if exists("b:did_ftplugin")
  finish
endif
 
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
unlet! b:did_ftplugin
 
setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=>\ %s
setlocal formatoptions+=tcqln
setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+
 
let b:undo_ftplugin .= "|setl cms< com< fo<"
 
"auto update
autocmd BufWritePost <buffer> silent exec "!presen blue"
 
"open browser
noremap <buffer> <F5> :!gnome-open %:p:h/index.html > /dev/null 2>&1<CR>
 
" vim:set sw=2:

markdownのftpluginファイルをコピーして、ファイルの最後に保存時にpresenコマンドを実行するコマンドを実行させる設定を追加しただけです。

~/.vim/syntax/presen.vim の生成

cp /usr/share/vim/vim73/syntax/markdown.vim ~/.vim/syntax/presen.vim

プレゼン設定 main.txtへのmodeline追加

そして、プレゼンテーションのドキュメント記述ファイルであるmain.txtの最終行に、modelineを追加します。

<!-- vim: set filetype=presen : -->

これで、このファイルを開いた時だけ、自動保存のautocmdが有効になります。autocmdの影響範囲も、上のmodelineを書いたファイルのみに限定されます。

  • 追記 filetype on である必要があります filetype plugin:OFFだった場合は、以下を.vimrcに追加すればonにできます。
  filetype plugin indent on

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です


The reCAPTCHA verification period has expired. Please reload the page.

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください