mirror of
1
0
Fork 0

Updated vim plugins

This commit is contained in:
amix 2016-03-20 19:01:44 +01:00
parent 20729bff94
commit 6dcca46b4a
20 changed files with 504 additions and 113 deletions

View File

@ -34,7 +34,7 @@ endfunction
function! s:set_color(group, attr, color)
let gui = a:color =~ '^#'
execute printf("hi %s %s%s=%s", a:group, gui ? 'gui' : 'cterm', a:attr, a:color)
execute printf('hi %s %s%s=%s', a:group, gui ? 'gui' : 'cterm', a:attr, a:color)
endfunction
function! s:blank(repel)
@ -207,13 +207,13 @@ function! s:goyo_on(dim)
endif
" vim-airline
let t:goyo_disabled_airline = exists("#airline")
let t:goyo_disabled_airline = exists('#airline')
if t:goyo_disabled_airline
AirlineToggle
endif
" vim-powerline
let t:goyo_disabled_powerline = exists("#PowerlineMain")
let t:goyo_disabled_powerline = exists('#PowerlineMain')
if t:goyo_disabled_powerline
augroup PowerlineMain
autocmd!
@ -222,7 +222,7 @@ function! s:goyo_on(dim)
endif
" lightline.vim
let t:goyo_disabled_lightline = exists('#LightLine')
let t:goyo_disabled_lightline = exists('#lightline')
if t:goyo_disabled_lightline
silent! call lightline#disable()
endif
@ -330,7 +330,7 @@ function! s:goyo_off()
let &winheight = wh
for [k, v] in items(goyo_revert)
execute printf("let &%s = %s", k, string(v))
execute printf('let &%s = %s', k, string(v))
endfor
execute 'colo '. get(g:, 'colors_name', 'default')
@ -344,7 +344,7 @@ function! s:goyo_off()
endif
endif
if goyo_disabled_airline && !exists("#airline")
if goyo_disabled_airline && !exists('#airline')
AirlineToggle
" For some reason, Airline requires two refreshes to avoid display
" artifacts
@ -352,7 +352,7 @@ function! s:goyo_off()
silent! AirlineRefresh
endif
if goyo_disabled_powerline && !exists("#PowerlineMain")
if goyo_disabled_powerline && !exists('#PowerlineMain')
doautocmd PowerlineStartup VimEnter
silent! PowerlineReloadColorscheme
endif

View File

@ -746,53 +746,81 @@ takes precedence over both 'b:syntastic_<filetype>_<checker>_exec' and
------------------------------------------------------------------------------
5.3 Configuring specific checkers *syntastic-config-makeprg*
Most checkers use the 'makeprgBuild()' function and provide many options by
default - in fact you can customise every part of the command that gets called.
Checkers are run by constructing a command line and passing it to a shell.
In most cases this command line is built using an internal function named
'makeprgBuild()', which provides a number of options that allows you to
customise every part of the command that gets called.
*'syntastic_<filetype>_<checker>_<option>'*
Checkers that use 'makeprgBuild()' construct a 'makeprg' like this: >
Checkers that use 'makeprgBuild()' construct a command line like this: >
let makeprg = self.makeprgBuild({
\ "exe": self.getExec(),
\ "args": "-a -b -c",
\ "fname: shellescape(expand('%', 1)),
\ "post_args": "--more --args",
\ "tail": "2>/dev/null" })
<
The result is a 'makeprg' of the form: >
The result is a command line of the form: >
<exe> <args> <fname> <post_args> <tail>
<
All arguments above are optional, and can be overridden by setting global
variables 'g:syntastic_<filetype>_<checker-name>_<option-name>' - even
parameters not specified in the call to makeprgBuild(). These variables also
have local versions 'b:syntastic_<filetype>_<checker-name>_<option-name>',
which take precedence over the global ones in the corresponding buffers.
If one of these variables has a non-empty default and you want it to be empty,
you can set it to an empty string, e.g.: >
let g:syntastic_javascript_jslint_args = ""
parameters not specified in the call to 'makeprgBuild()'. For example to
override the args and the tail: >
let g:syntastic_c_pc_lint_args = "-w5 -Iz:/usr/include/linux"
let g:syntastic_c_pc_lint_tail = "2>/dev/null"
<
These variables also have local versions named
'b:syntastic_<filetype>_<checker-name>_<option-name>', which takes precedence
over the global ones in the corresponding buffers.
If any of the characters in the values of these variables have a special
meaning for the shell in use (see |'shell'| and |'syntastic_shell'|) you need
to escape them so that they can survive shell expansions. Vim function
|shellescape()| can help you with that: >
let g:syntastic_c_cppcheck_args =
\ '-DBUILD_BASENAME=my-module ' . shellescape('-DBUILD_STR(s)=#s')
<
Alternatively, you can tell syntastic to escape special characters by turning
the value into a list: >
let g:syntastic_c_cppcheck_args =
\ ['-DBUILD_BASENAME=my-module', '-DBUILD_STR(s)=#s']
<
Each element of the list will then be escaped as needed and turned into a
separate shell argument.
If one of the above variables has a non-empty default and you want it to be
empty, you can set it to an empty string, e.g.: >
let g:syntastic_javascript_jslint_args = ""
You can see the final outcome of setting these variables in the debug logs
(cf. |syntastic-config-debug|).
*'syntastic_<filetype>_<checker>_exe'*
The 'exe' is normally the same as the 'exec' attribute described above, in
which case it may be omitted. However, you can use it to add environment
variables, or to change the way the checker is run. For example this setup
The 'exe' option is special. Normally it is the same as the 'exec' attribute
described above, but you can use it to add environment variables to the
command line, or to change the way the checker is run. For example this setup
allows you to run PC-Lint under Wine emulation on Linux: >
let g:syntastic_c_pc_lint_exec = "wine"
let g:syntastic_c_pc_lint_exe = "wine c:/path/to/lint-nt.exe"
<
To override the args and the tail: >
let g:syntastic_c_pc_lint_args = "-w5 -Iz:/usr/include/linux"
let g:syntastic_c_pc_lint_tail = "2>/dev/null"
<
The general form of the override options is: >
syntastic_<filetype>_<checker>_<option-name>
*'syntastic_<filetype>_<checker>_fname'*
The 'fname' option is also special. Normally it is automatically set by
syntastic to the name of the current file, but you can change that as needed.
For example you can tell the SML/NJ compiler to use Compilation Manager by
omitting the filename from the command line: >
let g:syntastic_sml_smlnj_fname = ""
<
*syntastic-config-no-makeprgbuild*
For checkers that do not use the 'makeprgBuild()' function you will have to
look at the source code of the checker in question. If there are specific
options that can be set, these are usually documented in the wiki:
options that can be set, they are normally documented in the wiki:
https://github.com/scrooloose/syntastic/wiki/Syntax-Checkers
*'syntastic_<filetype>_<checker>_quiet_messages'*
In the same vein, 'g:syntastic_<filetype>_<checker-name>_quiet_messages' can
Last but not least, 'g:syntastic_<filetype>_<checker-name>_quiet_messages' can
be used to restrict message filters to messages produced by specific checkers.
Example: >
let g:syntastic_python_pylama_quiet_messages = {

View File

@ -19,7 +19,7 @@ if has('reltime')
lockvar! g:_SYNTASTIC_START
endif
let g:_SYNTASTIC_VERSION = '3.7.0-99'
let g:_SYNTASTIC_VERSION = '3.7.0-101'
lockvar g:_SYNTASTIC_VERSION
" Sanity checks {{{1

View File

@ -184,7 +184,7 @@ endfunction " }}}2
" not run).
function! g:SyntasticRegistry.getCheckers(ftalias, hints_list) abort " {{{2
let ft = s:_normalise_filetype(a:ftalias)
call self._loadCheckersFor(ft)
call self._loadCheckersFor(ft, 0)
let checkers_map = self._checkerMap[ft]
if empty(checkers_map)
@ -233,7 +233,7 @@ endfunction " }}}2
function! g:SyntasticRegistry.getNamesOfAvailableCheckers(ftalias) abort " {{{2
let ft = s:_normalise_filetype(a:ftalias)
call self._loadCheckersFor(ft)
call self._loadCheckersFor(ft, 0)
return keys(filter( copy(self._checkerMap[ft]), 'v:val.isAvailable()' ))
endfunction " }}}2
@ -320,9 +320,8 @@ function! g:SyntasticRegistry._filterCheckersByName(checkers_map, list) abort "
return filter( map(copy(a:list), 'get(a:checkers_map, v:val, {})'), '!empty(v:val)' )
endfunction " }}}2
function! g:SyntasticRegistry._loadCheckersFor(filetype, ...) abort " {{{2
" XXX: a:1 == 1 means re-scan checkers for filetype
if has_key(self._checkerMap, a:filetype) && (!a:0 || !a:1)
function! g:SyntasticRegistry._loadCheckersFor(filetype, force) abort " {{{2
if !a:force && has_key(self._checkerMap, a:filetype)
return
endif

View File

@ -95,10 +95,10 @@ that are part of Git repositories).
:Gfetch [args] Like |:Gpush|, but for git-fetch.
*fugitive-:Ggrep*
:Ggrep [args] |:grep| with git-grep as 'grepprg'.
:Ggrep[!] [args] |:grep|[!] with git-grep as 'grepprg'.
*fugitive-:Glgrep*
:Glgrep [args] |:lgrep| with git-grep as 'grepprg'.
:Glgrep[!] [args] |:lgrep|[!] with git-grep as 'grepprg'.
*fugitive-:Glog*
:Glog [args] Load all previous revisions of the current file into

View File

@ -9,6 +9,8 @@ disabled/enabled easily.
![vim-go](https://dl.dropboxusercontent.com/u/174404/vim-go-2.png)
## Features
* Improved Syntax highlighting with items such as Functions, Operators, Methods.
@ -49,6 +51,12 @@ disabled/enabled easily.
in their own new terminal. (beta)
* Alternate between implementation and test code with `:GoAlternate`
## Donation
People have asked for this for a long time, now you can be a fully supporter by [being a patron](https://www.patreon.com/fatih)! This is fully optional and is just a way to support vim-go's ongoing development directly. Thanks!
[https://www.patreon.com/fatih](https://www.patreon.com/fatih)
## Install
Vim-go follows the standard runtime path structure, so I highly recommend to

View File

@ -0,0 +1,158 @@
let s:go_decls_var = {
\ 'init': 'ctrlp#decls#init()',
\ 'exit': 'ctrlp#decls#exit()',
\ 'enter': 'ctrlp#decls#enter()',
\ 'accept': 'ctrlp#decls#accept',
\ 'lname': 'declarations',
\ 'sname': 'decls',
\ 'type': 'tabs',
\}
if exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
let g:ctrlp_ext_vars = add(g:ctrlp_ext_vars, s:go_decls_var)
else
let g:ctrlp_ext_vars = [s:go_decls_var]
endif
function! ctrlp#decls#init()
cal s:enable_syntax()
return s:decls
endfunction
function! ctrlp#decls#exit()
unlet! s:decls s:current_dir s:target
endfunction
" The action to perform on the selected string
" Arguments:
" a:mode the mode that has been chosen by pressing <cr> <c-v> <c-t> or <c-x>
" the values are 'e', 'v', 't' and 'h', respectively
" a:str the selected string
function! ctrlp#decls#accept(mode, str)
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
try
" we jump to the file directory so we can get the fullpath via fnamemodify
" below
execute cd . s:current_dir
let vals = matchlist(a:str, '|\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)|')
" i.e: main.go
let filename = vals[1]
let line = vals[2]
let col = vals[3]
" i.e: /Users/fatih/vim-go/main.go
let filepath = fnamemodify(filename, ":p")
" acceptile is a very versatile method,
call ctrlp#acceptfile(a:mode, filepath)
call cursor(line, col)
silent! norm! zvzz
finally
"jump back to old dir
execute cd . fnameescape(dir)
endtry
endfunction
function! ctrlp#decls#enter()
let s:current_dir = fnameescape(expand('%:p:h'))
let s:decls = []
let bin_path = go#path#CheckBinPath('motion')
if empty(bin_path)
return
endif
let command = printf("%s -format vim -mode decls", bin_path)
let command .= " -include ". get(g:, "go_decls_includes", "func,type")
call go#cmd#autowrite()
if s:mode == 0
" current file mode
let fname = expand("%:p")
if exists('s:target')
let fname = s:target
endif
let command .= printf(" -file %s", fname)
else
" all functions mode
let dir = expand("%:p:h")
if exists('s:target')
let dir = s:target
endif
let command .= printf(" -dir %s", dir)
endif
let out = system(command)
if v:shell_error != 0
call go#util#EchoError(out)
return
endif
if exists("l:tmpname")
call delete(l:tmpname)
endif
let result = eval(out)
if type(result) != 4 || !has_key(result, 'decls')
return
endif
let decls = result.decls
" find the maximum function name
let max_len = 0
for decl in decls
if len(decl.ident)> max_len
let max_len = len(decl.ident)
endif
endfor
for decl in decls
" paddings
let space = " "
for i in range(max_len - len(decl.ident))
let space .= " "
endfor
call add(s:decls, printf("%s\t%s |%s:%s:%s|\t%s",
\ decl.ident . space,
\ decl.keyword,
\ fnamemodify(decl.filename, ":t"),
\ decl.line,
\ decl.col,
\ decl.full,
\))
endfor
endfunc
function! s:enable_syntax()
if !(has('syntax') && exists('g:syntax_on'))
return
endif
syntax match CtrlPIdent '\zs\h\+\ze\s'
syntax match CtrlPKeyword '\zs[^\t|]\+\ze|[^|]\+:\d\+:\d\+|'
syntax match CtrlPFilename '|\zs[^|]\+:\d\+:\d\+\ze|'
syntax match CtrlPSignature '\zs\t.*\ze$' contains=CtrlPKeyWord,CtrlPFilename
highlight link CtrlPIdent Function
highlight link CtrlPKeyword Keyword
highlight link CtrlPFilename SpecialComment
highlight link CtrlPSignature Comment
endfunction
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
function! ctrlp#decls#cmd(mode, ...)
let s:mode = a:mode
if a:0 && !empty(a:1)
let s:target = a:1
endif
return s:id
endfunction

View File

@ -87,32 +87,21 @@ fu! s:gocodeCurrentBufferOpt(filename)
return '-in=' . a:filename
endf
fu! go#complete#gocodeCursor()
if &encoding != 'utf-8'
let sep = &l:fileformat == 'dos' ? "\r\n" : "\n"
let c = col('.')
let buf = line('.') == 1 ? "" : (join(getline(1, line('.')-1), sep) . sep)
let buf .= c == 1 ? "" : getline('.')[:c-2]
return printf('%d', len(iconv(buf, &encoding, "utf-8")))
endif
return printf('%d', line2byte(line('.')) + (col('.')-2))
endf
fu! s:gocodeAutocomplete()
let filename = s:gocodeCurrentBuffer()
let result = s:gocodeCommand('autocomplete',
\ [s:gocodeCurrentBufferOpt(filename), '-f=vim'],
\ [expand('%:p'), go#complete#gocodeCursor()])
\ [expand('%:p'), go#util#OffsetCursor()])
call delete(filename)
return result
endf
function! go#complete#GetInfoFromOffset(offset)
function! go#complete#GetInfo()
let offset = go#util#OffsetCursor()+1
let filename = s:gocodeCurrentBuffer()
let result = s:gocodeCommand('autocomplete',
\ [s:gocodeCurrentBufferOpt(filename), '-f=godit'],
\ [expand('%:p'), a:offset])
\ [expand('%:p'), offset])
call delete(filename)
" first line is: Charcount,,NumberOfCandidates, i.e: 8,,1
@ -148,11 +137,6 @@ function! go#complete#GetInfoFromOffset(offset)
return ""
endfunction
function! go#complete#GetInfo()
let offset = go#complete#gocodeCursor()+1
return go#complete#GetInfoFromOffset(offset)
endfunction
function! go#complete#Info(auto)
" auto is true if we were called by g:go_auto_type_info's autocmd
let result = go#complete#GetInfo()

View File

@ -15,9 +15,7 @@ endf
" modified and improved version of vim-godef
function! go#def#Jump(...)
if !len(a:000)
" gives us the offset of the word, basicall the position of the word under
" he cursor
let arg = s:getOffset()
let arg = "-o=" . go#util#OffsetCursor()
else
let arg = a:1
endif
@ -43,7 +41,7 @@ endfunction
function! go#def#JumpMode(mode)
let arg = s:getOffset()
let arg = "-o=" . go#util#OffsetCursor()
let bin_path = go#path#CheckBinPath(g:go_godef_bin)
if empty(bin_path)
@ -65,18 +63,7 @@ endfunction
function! s:getOffset()
let pos = getpos(".")[1:2]
if &encoding == 'utf-8'
let offs = line2byte(pos[0]) + pos[1] - 2
else
let c = pos[1]
let buf = line('.') == 1 ? "" : (join(getline(1, pos[0] - 1), go#util#LineEnding()) . go#util#LineEnding())
let buf .= c == 1 ? "" : getline(pos[0])[:c-2]
let offs = len(iconv(buf, &encoding, "utf-8"))
endif
let argOff = "-o=" . offs
return argOff
return "-o=" . go#util#OffsetCursor()
endfunction

View File

@ -62,15 +62,6 @@ func! s:loclistSecond(output)
call go#list#Window("locationlist", len(errors))
endfun
func! s:getpos(l, c)
if &encoding != 'utf-8'
let buf = a:l == 1 ? '' : (join(getline(1, a:l-1), "\n") . "\n")
let buf .= a:c == 1 ? '' : getline('.')[:a:c-2]
return len(iconv(buf, &encoding, 'utf-8'))
endif
return line2byte(a:l) + (a:c-2)
endfun
func! s:RunOracle(mode, selected, needs_package) range abort
let fname = expand('%:p')
let dname = expand('%:p:h')
@ -102,13 +93,13 @@ func! s:RunOracle(mode, selected, needs_package) range abort
endif
if a:selected != -1
let pos1 = s:getpos(line("'<"), col("'<"))
let pos2 = s:getpos(line("'>"), col("'>"))
let pos1 = go#util#Offset(line("'<"), col("'<"))
let pos2 = go#util#Offset(line("'>"), col("'>"))
let cmd = printf('%s -format plain -pos=%s:#%d,#%d -tags=%s %s',
\ bin_path,
\ shellescape(fname), pos1, pos2, tags, a:mode)
else
let pos = s:getpos(line('.'), col('.'))
let pos = go#util#OffsetCursor()
let cmd = printf('%s -format plain -pos=%s:#%d -tags=%s %s',
\ bin_path,
\ shellescape(fname), pos, tags, a:mode)

View File

@ -144,7 +144,6 @@ function! go#path#CheckBinPath(binpath)
return binpath
endif
" just get the basename
let basename = fnamemodify(binpath, ":t")

View File

@ -31,7 +31,7 @@ function! go#rename#Rename(bang, ...)
endif
let fname = expand('%:p')
let pos = s:getpos(line('.'), col('.'))
let pos = go#util#OffsetCursor()
let cmd = printf('%s -offset %s -to %s', shellescape(bin_path), shellescape(printf('%s:#%d', fname, pos)), shellescape(to))
let out = go#tool#ExecuteInDir(cmd)
@ -65,14 +65,5 @@ function! go#rename#Rename(bang, ...)
silent execute ":e"
endfunction
func! s:getpos(l, c)
if &encoding != 'utf-8'
let buf = a:l == 1 ? '' : (join(getline(1, a:l-1), "\n") . "\n")
let buf .= a:c == 1 ? '' : getline('.')[:a:c-2]
return len(iconv(buf, &encoding, 'utf-8'))
endif
return line2byte(a:l) + (a:c-2)
endfun
" vim:ts=4:sw=4:et
"

View File

@ -2,14 +2,179 @@ if !exists("g:go_textobj_enabled")
let g:go_textobj_enabled = 1
endif
if !exists("g:go_textobj_include_function_doc")
let g:go_textobj_include_function_doc = 1
endif
" ( ) motions
" { } motions
" s for sentence
" p for parapgrah
" < >
" t for tag
function! go#textobj#Function(mode)
if search('^\s*func .*{$', 'Wce', line('.')) <= 0
\ && search('^\s*func .*{$', 'bWce') <= 0
let offset = go#util#OffsetCursor()
let fname = expand("%:p")
if &modified
" Write current unsaved buffer to a temp file and use the modified content
let l:tmpname = tempname()
call writefile(getline(1, '$'), l:tmpname)
let fname = l:tmpname
endif
let bin_path = go#path#CheckBinPath('motion')
if empty(bin_path)
return
endif
if a:mode == 'a'
normal! Va{V
else " a:mode == 'i'
normal! Vi{V
let command = printf("%s -format vim -file %s -offset %s", bin_path, fname, offset)
let command .= " -mode enclosing"
if g:go_textobj_include_function_doc
let command .= " -parse-comments"
endif
let out = system(command)
if v:shell_error != 0
call go#util#EchoError(out)
return
endif
" if exists, delete it as we don't need it anymore
if exists("l:tmpname")
call delete(l:tmpname)
endif
" convert our string dict representation into native Vim dictionary type
let result = eval(out)
if type(result) != 4 || !has_key(result, 'fn')
return
endif
let info = result.fn
if a:mode == 'a'
" anonymous functions doesn't have associated doc. Also check if the user
" want's to include doc comments for function declarations
if has_key(info, 'doc') && g:go_textobj_include_function_doc
call cursor(info.doc.line, info.doc.col)
else
call cursor(info.func.line, info.func.col)
endif
normal! v
call cursor(info.rbrace.line, info.rbrace.col)
return
endif
" rest is inner mode, a:mode == 'i'
" if the function is a one liner we need to select only that portion
if info.lbrace.line == info.rbrace.line
call cursor(info.lbrace.line, info.lbrace.col+1)
normal! v
call cursor(info.rbrace.line, info.rbrace.col-1)
return
endif
call cursor(info.lbrace.line+1, 1)
normal! V
call cursor(info.rbrace.line-1, 1)
endfunction
function! go#textobj#FunctionJump(mode, direction)
" get count of the motion. This should be done before all the normal
" expressions below as those reset this value(because they have zero
" count!). We abstract -1 because the index starts from 0 in motion.
let l:cnt = v:count1 - 1
" set context mark so we can jump back with '' or ``
normal! m'
" select already previously selected visual content and continue from there.
" If it's the first time starts with the visual mode. This is needed so
" after selecting something in visual mode, every consecutive motion
" continues.
if a:mode == 'v'
normal! gv
endif
let offset = go#util#OffsetCursor()
let fname = expand("%:p")
if &modified
" Write current unsaved buffer to a temp file and use the modified content
let l:tmpname = tempname()
call writefile(getline(1, '$'), l:tmpname)
let fname = l:tmpname
endif
let bin_path = go#path#CheckBinPath('motion')
if empty(bin_path)
return
endif
let command = printf("%s -format vim -file %s -offset %s", bin_path, fname, offset)
let command .= ' -shift ' . l:cnt
if a:direction == 'next'
let command .= ' -mode next'
else " 'prev'
let command .= ' -mode prev'
endif
if g:go_textobj_include_function_doc
let command .= " -parse-comments"
endif
let out = system(command)
if v:shell_error != 0
call go#util#EchoError(out)
return
endif
" if exists, delete it as we don't need it anymore
if exists("l:tmpname")
call delete(l:tmpname)
endif
" convert our string dict representation into native Vim dictionary type
let result = eval(out)
if type(result) != 4 || !has_key(result, 'fn')
return
endif
" we reached the end and there are no functions. The usual [[ or ]] jumps to
" the top or bottom, we'll do the same.
if type(result) == 4 && has_key(result, 'err') && result.err == "no functions found"
if a:direction == 'next'
keepjumps normal! G
else " 'prev'
keepjumps normal! gg
endif
return
endif
let info = result.fn
" if we select something ,select all function
if a:mode == 'v' && a:direction == 'next'
keepjumps call cursor(info.rbrace.line, 1)
return
endif
if a:mode == 'v' && a:direction == 'prev'
if has_key(info, 'doc') && g:go_textobj_include_function_doc
keepjumps call cursor(info.doc.line, 1)
else
keepjumps call cursor(info.func.line, 1)
endif
return
endif
keepjumps call cursor(info.func.line, 1)
endfunction
" vim:ts=2:sw=2:et

View File

@ -85,6 +85,22 @@ function! go#util#Shelllist(arglist, ...)
endtry
endfunction
" Returns the byte offset for line and column
function! go#util#Offset(line, col)
if &encoding != 'utf-8'
let sep = go#util#LineEnding()
let buf = a:line == 1 ? '' : (join(getline(1, a:line-1), sep) . sep)
let buf .= a:col == 1 ? '' : getline('.')[:a:col-2]
return len(iconv(buf, &encoding, 'utf-8'))
endif
return line2byte(a:line) + (a:col-2)
endfunction
"
" Returns the byte offset for the cursor
function! go#util#OffsetCursor()
return go#util#Offset(line('.'), col('.'))
endfunction
" TODO(arslan): I couldn't parameterize the highlight types. Check if we can
" simplify the following functions

View File

@ -503,6 +503,27 @@ COMMANDS *go-commands*
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
augroup END
<
*:GoDecls*
:GoDecls [file]
Only enabled if `ctrlp.vim` is installed. If run shows all function and
type declarations for the current file. If [file] is non empty it parses
the given file.
By default `type` and `func` declarations are being showed. This can be
changed via |g:go_decls_includes|, which accepts a comma delimited list of
definitions. By default set to: `"func,type"`. Possible options are:
`{func,type}`
*:GoDeclsDir*
:GoDeclsDir [dir]
Only enabled if `ctrlp.vim` is installed. If run shows all function and
type declarations for the current directory. If [dir] is given it parses
the given directory.
By default `type` and `func` declarations are being showed. This can be
changed via |g:go_decls_includes|, which accepts a comma delimited list of
definitions. By default set to: `"func,type"`. Possible options are:
`{func,type}`
===============================================================================
MAPPINGS *go-mappings*
@ -691,11 +712,26 @@ upon regions of text. vim-go currently defines the following text objects:
*go-v_af* *go-af*
af "a function", select contents from a function definition to the
closing bracket.
closing bracket. If |g:go_textobj_include_function_doc| is
enabled it also includes the comment doc for a function
declaration. This text-object also supports literal functions.
*go-v_if* *go-if*
if "inside a function", select contents of a function,
excluding the function definition and the closing bracket.
excluding the function definition and the closing bracket. This
text-object also supports literal functions
vim-go also defines the following text motion objects:
*go-v_]]* *go-]]*
]] [count] forward to next function declaration. If
|g:go_textobj_include_function_doc| is enabled and if your
on a comment, it skips the function which the comment
belongs and forwards to the next function declaration.
*go-v_[[* *go-[[*
[[ [count] backward to previous function declaration.

View File

@ -33,10 +33,21 @@ if get(g:, "go_def_mapping_enabled", 1)
endif
if get(g:, "go_textobj_enabled", 1)
onoremap <buffer> af :<c-u>call go#textobj#Function('a')<cr>
xnoremap <buffer> af :<c-u>call go#textobj#Function('a')<cr>
onoremap <buffer> if :<c-u>call go#textobj#Function('i')<cr>
xnoremap <buffer> if :<c-u>call go#textobj#Function('i')<cr>
onoremap <buffer> <silent> af :<c-u>call go#textobj#Function('a')<cr>
onoremap <buffer> <silent> if :<c-u>call go#textobj#Function('i')<cr>
xnoremap <buffer> <silent> af :<c-u>call go#textobj#Function('a')<cr>
xnoremap <buffer> <silent> if :<c-u>call go#textobj#Function('i')<cr>
" Remap ]] and [[ to jump betweeen functions as they are useless in Go
nnoremap <buffer> <silent> ]] :<c-u>call go#textobj#FunctionJump('n', 'next')<cr>
nnoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('n', 'prev')<cr>
onoremap <buffer> <silent> ]] :<c-u>call go#textobj#FunctionJump('o', 'next')<cr>
onoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('o', 'prev')<cr>
xnoremap <buffer> <silent> ]] :<c-u>call go#textobj#FunctionJump('v', 'next')<cr>
xnoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('v', 'prev')<cr>
endif
if get(g:, "go_auto_type_info", 0)

View File

@ -56,4 +56,10 @@ command! -nargs=* -complete=customlist,go#package#Complete GoErrCheck call go#li
" -- alternate
command! -bang GoAlternate call go#alternate#Switch(<bang>0, '')
" -- ctrlp
if globpath(&rtp, 'plugin/ctrlp.vim') != ""
command! -nargs=? -complete=file GoDecls call ctrlp#init(ctrlp#decls#cmd(0, <q-args>))
command! -nargs=? -complete=dir GoDeclsDir call ctrlp#init(ctrlp#decls#cmd(1, <q-args>))
endif
" vim:ts=4:sw=4:et

View File

@ -18,6 +18,7 @@ let s:packages = [
\ "github.com/kisielk/errcheck",
\ "github.com/jstemmer/gotags",
\ "github.com/klauspost/asmfmt/cmd/asmfmt",
\ "github.com/fatih/motion",
\ ]
" These commands are available on any filetypes

View File

@ -81,6 +81,10 @@ if !exists("g:go_highlight_string_spellcheck")
let g:go_highlight_string_spellcheck = 1
endif
if !exists("g:go_highlight_generate_tags")
let g:go_highlight_generate_tags = 0
endif
syn case match
syn keyword goDirective package import
@ -132,11 +136,18 @@ hi def link goBoolean Boolean
syn keyword goTodo contained TODO FIXME XXX BUG
syn cluster goCommentGroup contains=goTodo
syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell
syn region goComment start="//" end="$" contains=@goCommentGroup,@Spell
syn region goComment start="//" end="$" contains=goGenerate,@goCommentGroup,@Spell
hi def link goComment Comment
hi def link goTodo Todo
if g:go_highlight_generate_tags != 0
syn match goGenerateVariables contained /\(\$GOARCH\|\$GOOS\|\$GOFILE\|\$GOLINE\|\$GOPACKAGE\|\$DOLLAR\)\>/
syn region goGenerate start="^\s*//go:generate" end="$" contains=goGenerateVariables
hi def link goGenerate PreProc
hi def link goGenerateVariables Special
endif
" Go escapes
syn match goEscapeOctal display contained "\\[0-7]\{3}"
syn match goEscapeC display contained +\\[abfnrtv\\'"]+

View File

@ -8,7 +8,7 @@ snippet def "#define ..."
#define ${1}
endsnippet
snippet ifndef "#ifndef ... #define ... #endif"
snippet #ifndef "#ifndef ... #define ... #endif"
#ifndef ${1/([A-Za-z0-9_]+).*/$1/}
#define ${1:SYMBOL} ${2:value}
#endif /* ifndef $1 */