gofiletype.vim 876 B

1234567891011121314151617181920212223
  1. " We take care to preserve the user's fileencodings and fileformats,
  2. " because those settings are global (not buffer local), yet we want
  3. " to override them for loading Go files, which are defined to be UTF-8.
  4. let s:current_fileformats = ''
  5. let s:current_fileencodings = ''
  6. " define fileencodings to open as utf-8 encoding even if it's ascii.
  7. function! s:gofiletype_pre()
  8. let s:current_fileformats = &g:fileformats
  9. let s:current_fileencodings = &g:fileencodings
  10. set fileencodings=utf-8 fileformats=unix
  11. setlocal filetype=go
  12. endfunction
  13. " restore fileencodings as others
  14. function! s:gofiletype_post()
  15. let &g:fileformats = s:current_fileformats
  16. let &g:fileencodings = s:current_fileencodings
  17. endfunction
  18. au BufNewFile *.go setlocal filetype=go fileencoding=utf-8 fileformat=unix
  19. au BufRead *.go call s:gofiletype_pre()
  20. au BufReadPost *.go call s:gofiletype_post()