-
Notifications
You must be signed in to change notification settings - Fork 10
/
.vimrc
58 lines (55 loc) · 1.86 KB
/
.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
set tabstop=4
set shiftwidth=4
set expandtab
set noautoindent
set ffs=unix,dos,mac
set ignorecase
set smartcase
au BufNewFile,BufRead *.ejs setfiletype ejs syntax=html
set encoding=utf8
set noeol
" the following is to prevent vim from automatically inserting an end of line when a file is written
" stolen from http://vim.wikia.com/wiki/Preserve_missing_end-of-line_at_end_of_text_files
augroup automatic_noeol
au!
au BufWritePre * call <SID>TempSetBinaryForNoeol()
au BufWritePost * call <SID>TempRestoreBinaryForNoeol()
augroup END
function! s:TempSetBinaryForNoeol()
let s:save_binary = &binary
if ! &eol && ! &binary
let s:save_view = winsaveview()
setlocal binary
if &ff == "dos" || &ff == "mac"
if line('$') > 1
undojoin | exec "silent 1,$-1normal! A\<C-V>\<C-M>"
endif
endif
if &ff == "mac"
undojoin | %join!
" mac format does not use a \n anywhere, so we don't add one when writing
" in binary (which uses unix format always). However, inside the outer
" if statement, we already know that 'noeol' is set, so no special logic
" is needed.
endif
endif
endfunction
function! s:TempRestoreBinaryForNoeol()
if ! &eol && ! s:save_binary
if &ff == "dos"
if line('$') > 1
" Sometimes undojoin gives errors here, even when it shouldn't.
" Suppress them for now...if you can figure out and fix them instead,
" please update http://vim.wikia.com/wiki/VimTip1369
silent! undojoin | silent 1,$-1s/\r$//e
endif
elseif &ff == "mac"
" Sometimes undojoin gives errors here, even when it shouldn't.
" Suppress them for now...if you can figure out and fix them instead,
" please update http://vim.wikia.com/wiki/VimTip1369
silent! undojoin | silent %s/\r/\r/ge
endif
setlocal nobinary
call winrestview(s:save_view)
endif
endfunction