Created
September 19, 2012 23:09
-
-
Save pinzolo/3752938 to your computer and use it in GitHub Desktop.
保存時にマジックコメントがなければ挿入する.vimrc設定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" マジックコメント自動追加関数 | |
function! AddMagicComment() | |
let pos = getpos('.') | |
let line_index = 1 | |
let magic_comment = '# coding: utf-8' | |
if &filetype == 'ruby' | |
let line = getline(line_index) | |
if line[0:1] == '#!' | |
let line_index = 2 | |
endif | |
elseif &filetype == 'haml' | |
let magic_comment = '-'.magic_comment | |
elseif &filetype == 'eruby' | |
let magic_comment = '<%'.magic_comment.' %>' | |
endif | |
let line = getline(line_index) | |
if line =~ 'coding:' | |
return | |
endif | |
call cursor(line_index, 0) | |
execute ':normal O'.magic_comment | |
call setpos('.', pos) | |
endfunction | |
autocmd BufWritePre *.rb,*.erb,*.haml call AddMagicComment()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment