forked from sontek/homies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_vimrc
50 lines (48 loc) · 1.69 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
execute pathogen#infect('bundle/{}', '~/.local.vim/{}')
" If buffer modified, update any 'Last modified: ' in the first 20 lines.
" 'Last modified: ' can have up to 15 characters before (they are retained).
" Restores cursor and window position using save_cursor variable.
function! LastModified()
if &modified
let save_cursor = getpos(".")
let n = min([20, line("$")])
keepjumps exe '1,' . n . 's#^\(.\{,15}"Last modified: \).*"#\1' .
\ strftime('%F') . '"#e'
call histdel('search', -1)
call setpos('.', save_cursor)
endif
endfun
autocmd BufWritePre *.man call LastModified()
function! DoPrettyXML()
" save the filetype so we can restore it later
let l:origft = &ft
set ft=
" Mark empty lines to preserve them.
%s/^\_s*$/<!-- FORMATTER: EMPTY LINE -->/g
" delete the xml header if it exists. This will
" permit us to surround the document with fake tags
" without creating invalid xml.
1s/<?xml .*?>//e
" insert fake tags around the entire document.
" This will permit us to pretty-format excerpts of
" XML that may contain multiple top-level elements.
0put ='<PrettyXML>'
$put ='</PrettyXML>'
silent %!xmllint --format -
" xmllint will insert an <?xml?> header. it's easy enough to delete
" if you don't want it.
1s/<?xml .*?>/<?xml version="1.0" encoding="UTF-8"?>/e
" delete the fake tags
2d
$d
" restore the 'normal' indentation, which is one extra level
" too deep due to the extra tags we wrapped around the document.
silent %<
" restore empty lines
%s/^\_s*<!--\_s*FORMATTER:\_s*EMPTY\_s*LINE\_s*-->\_s*$//g
" back to home
1
" restore the filetype
exe "set ft=" . l:origft
endfunction
command! PrettyXML call DoPrettyXML()