-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.vim
More file actions
78 lines (63 loc) · 2.07 KB
/
Copy pathfunctions.vim
File metadata and controls
78 lines (63 loc) · 2.07 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
" Align command (format text in columns) {{{
command! -nargs=1 -range=% Align :execute "<line1>,<line2>!sed 's/" . <f-args> . "/@". <f-args> . "/g' | column -s@ -t"
"}}}
" StripTrailingWhitespaces command {{{
command! StripTrailingWhitespaces :call <SID>ExecPreservingCursorPos('%s/\s\+$//e')
" }}}
fun! s:CloseHiddenBuffers() "{{{
let open_buffers = []
for i in range(tabpagenr('$'))
call extend(open_buffers, tabpagebuflist(i+1))
endfor
for num in range(1, bufnr('$')+1)
if buflisted(num) && index(open_buffers, num) == -1
exec 'bdelete '.num
endif
endfor
endf
command! CloseHiddenBuffers call s:CloseHiddenBuffers()
" }}}
fun! s:ExecPreservingCursorPos(command) "{{{
" Taken from http://goo.gl/DJ7xA
" Save last search and cursor position
let _s=@/
let l = line('.')
let c = col('.')
" Do the business
execute a:command
" Restore previous search history and cursor position
let @/=_s
call cursor(l, c)
endf
" }}}
fun! s:GitAnnotate() "{{{
" save cursor position
let l:current_line = line('.')
" create annotate buffer
execute 'vnew | 0read !git annotate '.expand('%')." | awk '{print $1,$2,$3}' | sed -E 's/\\( ?//g'"
" adjust buffer width to longest line
execute 'vertical resize '.max(map(getline(1,'$'), 'len(v:val)'))
" delete last line
execute 'normal Gddgg'
" configure annotate buffer
setlocal bufhidden=hide buftype=nofile nobuflisted nonumber noswapfile nomodifiable statusline=git-annotate
silent! file git-annotate
" lock cursor and scroll
windo setlocal cursorbind scrollbind
windo execute 'normal '.l:current_line.'Gzz'
wincmd h
" unlock when annotate buffer closes
autocmd BufHidden git-annotate windo set nocursorbind noscrollbind
endf
autocmd BufEnter git-annotate DimInactiveOff
command! GitAnnotate :call s:GitAnnotate()
"}}}
fun! s:SyntaxGroupsForWordUnderCursor() "{{{
if !exists('*synstack')
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endf
nmap <leader>sg :call <SID>SyntaxGroupsForWordUnderCursor()<CR>
" }}}
" vim: set foldmethod=marker foldenable :