1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 01:25:00 +08:00

Updated vimrc

This commit is contained in:
amix
2015-07-13 11:22:46 +01:00
parent 9a2843c2a5
commit d7752b59ae
301 changed files with 4699 additions and 7969 deletions

View File

@ -4,6 +4,7 @@ if exists("g:go_loaded_install")
endif
let g:go_loaded_install = 1
" these packages are used by vim-go and can be automatically installed if
" needed by the user with GoInstallBinaries
let s:packages = [
@ -17,74 +18,11 @@ let s:packages = [
\ "github.com/jstemmer/gotags",
\ ]
" Commands
command! GoErrCheck call go#errcheck#Run()
" These commands are available on any filetypes
command! GoInstallBinaries call s:GoInstallBinaries(-1)
command! GoUpdateBinaries call s:GoInstallBinaries(1)
command! -nargs=? -complete=dir GoPath call go#path#GoPath(<f-args>)
" LineEnding returns the correct line ending, based on the current fileformat
function! LineEnding()
if &fileformat == 'dos'
return "\r\n"
elseif &fileformat == 'mac'
return "\r"
endif
return "\n"
endfunction
" IsWin returns 1 if current OS is Windows or 0 otherwise
function! IsWin()
let win = ['win16', 'win32', 'win32unix', 'win64', 'win95']
for w in win
if (has(w))
return 1
endif
endfor
return 0
endfunction
" PathSep returns the appropriate path separator based on OS.
function! PathSep()
if IsWin()
return ";"
endif
return ":"
endfunction
" DefaultGoPath returns the default GOPATH.
" If there is only one GOPATH it returns that, otherwise it returns the first one.
function! DefaultGoPath()
let go_paths = split($GOPATH, PathSep())
if len(go_paths) == 1
return $GOPATH
endif
return go_paths[0]
endfunction
" GetBinPath returns the binary path of installed go tools
function! GetBinPath()
let bin_path = ""
" check if our global custom path is set, if not check if $GOBIN is set so
" we can use it, otherwise use $GOPATH + '/bin'
if exists("g:go_bin_path")
let bin_path = g:go_bin_path
elseif $GOBIN != ""
let bin_path = $GOBIN
elseif $GOPATH != ""
let bin_path = expand(DefaultGoPath() . "/bin/")
else
" could not find anything
endif
return bin_path
endfunction
" GoInstallBinaries downloads and install all necessary binaries stated in the
" packages variable. It uses by default $GOBIN or $GOPATH/bin as the binary
@ -103,7 +41,7 @@ function! s:GoInstallBinaries(updateBinaries)
return
endif
let go_bin_path = GetBinPath()
let go_bin_path = go#path#BinPath()
" change $GOBIN so go get can automatically install to it
let $GOBIN = go_bin_path
@ -112,7 +50,7 @@ function! s:GoInstallBinaries(updateBinaries)
let old_path = $PATH
" vim's executable path is looking in PATH so add our go_bin path to it
let $PATH = $PATH . PathSep() .go_bin_path
let $PATH = $PATH . go#util#PathListSep() .go_bin_path
" when shellslash is set on MS-* systems, shellescape puts single quotes
" around the output string. cmd on Windows does not handle single quotes
@ -124,6 +62,15 @@ function! s:GoInstallBinaries(updateBinaries)
set noshellslash
endif
let cmd = "go get -u -v "
let s:go_version = matchstr(system("go version"), '\d.\d.\d')
" https://github.com/golang/go/issues/10791
if s:go_version > "1.4.0" && s:go_version < "1.5.0"
let cmd .= "-f "
endif
for pkg in s:packages
let basename = fnamemodify(pkg, ":t")
let binname = "go_" . basename . "_bin"
@ -140,7 +87,8 @@ function! s:GoInstallBinaries(updateBinaries)
echo "vim-go: ". basename ." not found. Installing ". pkg . " to folder " . go_bin_path
endif
let out = system("go get -u -v ".shellescape(pkg))
let out = system(cmd . shellescape(pkg))
if v:shell_error
echo "Error installing ". pkg . ": " . out
endif