Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

go in vim

  • Loading branch information...
commit 7ba4ebacb3564a56f69bd4a5891207c47db3e7de 1 parent 18d4ad5
Andrea Lattuada authored December 01, 2012
1  gvimrc
@@ -5,3 +5,4 @@ set guioptions-=LlRrb
5 5
 
6 6
 colorscheme wombat-my
7 7
 set cursorline
  8
+
6  update.sh
... ...
@@ -1,3 +1,9 @@
1 1
 #!/bin/bash
2 2
 
3 3
 git submodule foreach git pull origin master
  4
+
  5
+# gocode
  6
+curl https://raw.github.com/nsf/gocode/master/vim/autoload/gocomplete.vim \
  7
+  > vim/custom_bundles/gocode/autoload/gocomplete.vim
  8
+curl https://raw.github.com/nsf/gocode/master/vim/ftplugin/go.vim \
  9
+  > vim/custom_bundles/gocode/ftplugin/go.vim
73  vim/bundle/gocode/autoload/gocomplete.vim
... ...
@@ -0,0 +1,73 @@
  1
+if exists('g:loaded_gocode')
  2
+	finish
  3
+endif
  4
+let g:loaded_gocode = 1
  5
+
  6
+fu! s:gocodeCurrentBuffer()
  7
+	let buf = getline(1, '$')
  8
+	if &l:fileformat == 'dos'
  9
+		" XXX: line2byte() depend on 'fileformat' option.
  10
+		" so if fileformat is 'dos', 'buf' must include '\r'.
  11
+		let buf = map(buf, 'v:val."\r"')
  12
+	endif
  13
+	let file = tempname()
  14
+	call writefile(buf, file)
  15
+	return file
  16
+endf
  17
+
  18
+fu! s:system(str, ...)
  19
+	return (a:0 == 0 ? system(a:str) : system(a:str, join(a:000)))
  20
+endf
  21
+
  22
+fu! s:gocodeShellescape(arg)
  23
+	try
  24
+		let ssl_save = &shellslash
  25
+		set noshellslash
  26
+		return shellescape(a:arg)
  27
+	finally
  28
+		let &shellslash = ssl_save
  29
+	endtry
  30
+endf
  31
+
  32
+fu! s:gocodeCommand(cmd, preargs, args)
  33
+	for i in range(0, len(a:args) - 1)
  34
+		let a:args[i] = s:gocodeShellescape(a:args[i])
  35
+	endfor
  36
+	for i in range(0, len(a:preargs) - 1)
  37
+		let a:preargs[i] = s:gocodeShellescape(a:preargs[i])
  38
+	endfor
  39
+	let result = s:system(printf('gocode %s %s %s', join(a:preargs), a:cmd, join(a:args)))
  40
+	if v:shell_error != 0
  41
+		return "[\"0\", []]"
  42
+	else
  43
+		return result
  44
+	endif
  45
+endf
  46
+
  47
+fu! s:gocodeCurrentBufferOpt(filename)
  48
+	return '-in=' . a:filename
  49
+endf
  50
+
  51
+fu! s:gocodeCursor()
  52
+	return printf('%d', line2byte(line('.')) + (col('.')-2))
  53
+endf
  54
+
  55
+fu! s:gocodeAutocomplete()
  56
+	let filename = s:gocodeCurrentBuffer()
  57
+	let result = s:gocodeCommand('autocomplete',
  58
+				   \ [s:gocodeCurrentBufferOpt(filename), '-f=vim'],
  59
+				   \ [expand('%:p'), s:gocodeCursor()])
  60
+	call delete(filename)
  61
+	return result
  62
+endf
  63
+
  64
+fu! gocomplete#Complete(findstart, base)
  65
+	"findstart = 1 when we need to get the text length
  66
+	if a:findstart == 1
  67
+		execute "silent let g:gocomplete_completions = " . s:gocodeAutocomplete()
  68
+		return col('.') - g:gocomplete_completions[0] - 1
  69
+	"findstart = 0 when we need to return the list of completions
  70
+	else
  71
+		return g:gocomplete_completions[1]
  72
+	endif
  73
+endf
1  vim/bundle/gocode/ftplugin/go.vim
... ...
@@ -0,0 +1 @@
  1
+setlocal omnifunc=gocomplete#Complete
5  vimrc
@@ -72,6 +72,11 @@ inoremap <expr><CR>  neocomplcache#smart_close_popup() . "\<CR>"
72 72
 " <TAB>: completion.
73 73
 inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"
74 74
 inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"
  75
+" omnicomplete
  76
+if !exists('g:neocomplcache_omni_patterns')
  77
+  let g:neocomplcache_omni_patterns = {}
  78
+endif
  79
+let g:neocomplcache_omni_patterns.go = '[^. *\t]\.\w*'
75 80
 
76 81
 " tagbar
77 82
 nmap <F8> :TagbarToggle<CR>

0 notes on commit 7ba4eba

Please sign in to comment.
Something went wrong with that request. Please try again.