forked from jasoncodes/vimfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.vim
49 lines (44 loc) · 1.73 KB
/
functions.vim
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
function! CommandTWithFlush()
CommandTFlush
CommandT
endfunction
command! -range=% -nargs=0 TabToSpace silent! execute "<line1>,<line2>s/^\\t\\+/\\=substitute(submatch(0), '\\t', repeat(' ', ".&ts."), 'g')"
command! -range=% -nargs=0 SpaceToTab silent! execute "<line1>,<line2>s/^\\( \\{".&ts."\\}\\)\\+/\\=substitute(submatch(0), ' \\{".&ts."\\}', '\\t', 'g')"
command! Marked silent !open -a Marked "%:p"
function! ToggleTabs()
let l:save_cursor = getpos(".")
if &expandtab
SpaceToTab
else
TabToSpace
endif
call setpos('.', l:save_cursor)
DetectIndent
endfunction
:command! -range=% -nargs=0 ToggleTabs call ToggleTabs()
" http://vim.wikia.com/wiki/Execute_commands_without_changing_the_search_register
" Executes a command (across a given range) and restores the search register when done.
function! SafeSearchCommand(line1, line2, theCommand)
let search = @/
execute a:line1 . "," . a:line2 . a:theCommand
let @/ = search
endfunction
command! -range -nargs=+ SS call SafeSearchCommand(<line1>, <line2>, <q-args>)
" A nicer version of :s that doesn't clobber the search register
command! -range -nargs=* S call SafeSearchCommand(<line1>, <line2>, 's' . <q-args>)
function! UpdateTags()
if exists('b:git_dir') && executable('ctags')
call system('(cd "'.b:git_dir.'/.." && [ "$(pwd)" != /usr/local ] && nice ctags --tag-relative -R -f .git/tags.new --exclude=.git --langmap="ruby:+.rake.builder.rjs" . && mv .git/tags.new .git/tags) &')
endif
endfunction
" Closes the quickfix window if it's open, overwise the focused window.
function! CloseWindow()
for i in range(1, winnr('$'))
let bnum = winbufnr(i)
if getbufvar(bnum, '&buftype') == 'quickfix'
cclose
return
endif
endfor
close
endfunction