-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunctions.vim
87 lines (67 loc) · 2.24 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
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
79
80
81
82
83
84
85
86
87
" Format whole file according to the filetype and vims syntax settings
function! FormatFile()
execute "normal! mf"
execute "normal! gg"
execute "normal! =G"
execute "normal! 'f"
endfunction
" Check for vim config update
function! CheckForUpgrade()
let g:VimConfigUpdateCheck = 1
let g:VimConfigUpdateCheckLockFile = $HOME . '/.vim/updatecheck.lock' " Not working in windows - who cares...
let g:VimConfigUpdateCheckDelay = 432000 " 5 days in seconds...
if !g:VimConfigUpdateCheck
return
endif
let current = localtime()
if !filereadable(g:VimConfigUpdateCheckLockFile)
call writefile([current], g:VimConfigUpdateCheckLockFile)
else
let content = readfile(g:VimConfigUpdateCheckLockFile)
let lastcheck = content[0]+0 " Force conversion to number
let nextcheck = lastcheck+g:VimConfigUpdateCheckDelay
if current < nextcheck
return
else
call writefile([current], g:VimConfigUpdateCheckLockFile)
endif
endif
let output = "Vim configuration update checker\n--------------------------------\n\n"
let cwd = getcwd()
execute 'lcd '.$HOME.'/.vim'
let remote = system("git ls-remote origin -h refs/heads/master | awk '{print $1}'")
let local = system("git rev-parse HEAD")
if remote == local
let output .= '**Nothing to update**'
else
let output .= '**You need an update!**'
let output .= "\n\n\nGit output\n----------\n\n"
let output .= system("git pull origin master")
let output .= system("git submodule update --init")
let output .= "\n==========================================\n"
let output .= "You're up to date now (Please restart Vim)"
let output .= "\n=========================================="
endif
execute 'lcd '.cwd
execute ':tabnew'
silent put=output
set filetype=rst
set nomodified
execute ':tabp'
redraw
endfunction
" Switch between light and dark background
function! SwitchBackground()
let &background = (&background == "dark"? "light" : "dark")
endfunction
" Returns branch in square brackets or empty string based on fugitive#head output
function! GitBranch()
if !exists('*fugitive#head')
return ''
endif
let branch = fugitive#head(7)
if branch == ''
return ''
endif
return '[' . branch . ']'
endfunction