Created
December 28, 2011 13:21
-
-
Save thenoseman/1527916 to your computer and use it in GitHub Desktop.
Automatically adds the utf-8 magic comment to ruby files
This file contains 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
" Adds the ruby magic comment to file | |
" Ignores SheBang-ed files | |
fun! AddMagicEncodingComment() | |
let line = getline(1) | |
let pos = getpos(".") | |
exec "normal gg" | |
if(match(line,"#!")) > -1 | |
let line = getline(2) | |
exec "normal j" | |
endif | |
if(match(line,"encoding")) == -1 | |
exec "normal O# -*- encoding : utf-8 -*-" | |
if pos[1] == 1 | |
" new file: | |
call setpos(".", [pos[0], 2, pos[2], pos[3]]) | |
else | |
" existing file | |
call setpos(".", pos) | |
endif | |
endif | |
endfun | |
au FileType ruby call AddMagicEncodingComment() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment