1
0
Fork 0
mirror of synced 2024-11-22 08:45:34 -05:00

Updated vim plugins

This commit is contained in:
amix 2016-07-16 20:30:35 +02:00
parent c4e6a11dad
commit 64a81818ee
21 changed files with 429 additions and 122 deletions

View file

@ -122,6 +122,19 @@ nice code clean-up (which ack.vim is now hopefully getting), and ack.vim picked
up a few features that haven't made their way to ag.vim, like `:AckWindow`,
optional background search execution with [vim-dispatch], and auto-previewing.
#### I don't want to jump to the first result automatically. ####
Use `:Ack!`, with bang. If you want this behavior most of the time, you might
like an abbreviation or mapping in your personal config, something like these:
```vim
cnoreabbrev Ack Ack!
nnoremap <Leader>a :Ack!<Space>
```
Most of the `:[L]Ack*` commands support this. Note that this behavior follows
the convention of Vim's built-in `:grep` and `:make` commands.
[The Silver Searcher]: https://github.com/ggreer/the_silver_searcher
[sadface]: https://github.com/mileszs/ack.vim/commit/d97090fb502d40229e6976dfec0e06636ba227d5#commitcomment-5771145

View file

@ -275,7 +275,19 @@ If you're using this plugin with ag, The Silver Searcher, bear in mind that:
==============================================================================
ISSUES AND FAQ *ack-issues-and-faq*
I use NERDTree and opening ack.vim results in a vertical split displaces it.~
I don't want to jump to the first result automatically.~
Use `:Ack!`, with bang. If you want this behavior most of the time, you
might like an abbreviation or mapping in your personal config, something
like these:
>
cnoreabbrev Ack Ack!
nnoremap <Leader>a :Ack!<Space>
<
Most of the `:[L]Ack*` commands support this. Note that this behavior
follows the convention of Vim's built-in |:grep| and |:make| commands.
I use NERDTree and opening ack.vim results in a vertical split displacing it.~
You are probably using NERDTree with its default alignment at the left
side of the window. Set these custom mappings in your vimrc to work around

View file

@ -149,6 +149,7 @@ let [s:lcmap, s:prtmaps] = ['nn <buffer> <silent>', {
\ 'CreateNewFile()': ['<c-y>'],
\ 'MarkToOpen()': ['<c-z>'],
\ 'OpenMulti()': ['<c-o>'],
\ 'YankLine()': [],
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ }]
@ -1325,6 +1326,18 @@ fu! s:OpenMulti(...)
unl! s:tabct
endf
fu! s:YankLine(...)
let @" = s:getinput()
let has_marked = exists('s:marked')
if !has_marked
let line = ctrlp#getcline()
if line == '' | retu | en
let marked = { 1 : fnamemodify(line, ':p') }
en
let @" = join(values(has_marked ? s:marked : marked), "\n")
cal s:PrtExit()
endf
fu! s:OpenNoMarks(md, line)
if a:md == 'a'
let [s:marked, key] = [{}, 1]

View file

@ -25,19 +25,21 @@
3. [Recommended settings](#settings)
4. [FAQ](#faq)
4.1. [I installed syntastic but it isn't reporting any errors...](#faqinfo)
4.2. [The `python` checker complains about syntactically valid Python 3 constructs...](#faqpython3)
4.3. [Are there any local checkers for HTML5 that I can use with syntastic?](#faqhtml5)
4.4. [The `perl` checker has stopped working...](#faqperl)
4.5. [What happened to the `rustc` checker?](#faqrust)
4.6. [What happened to the `xcrun` checker?](#faqxcrun)
4.7. [I run a checker and the location list is not updated...](#faqloclist)
4.7. [I run`:lopen` or `:lwindow` and the error window is empty...](#faqloclist)
4.8. [How can I pass additional arguments to a checker?](#faqargs)
4.9. [Syntastic supports several checkers for my filetype - how do I tell which one(s) to use?](#faqcheckers)
4.10. [What is the difference between syntax checkers and style checkers?](#faqstyle)
4.11. [I have enabled multiple checkers for the current filetype. How can I display all errors from all checkers together?](#faqaggregate)
4.12. [How can I jump between the different errors without using the location list at the bottom of the window?](#faqlnext)
4.13. [The error window is closed automatically when I :quit the current buffer but not when I :bdelete it?](#faqbdelete)
4.2. [How can I check scripts written for different versions of Python?](#faqpython)
4.3. [How can I check scripts written for different versions of Ruby?](#faqruby)
4.4. [Are there any local checkers for HTML5 that I can use with syntastic?](#faqhtml5)
4.5. [The `perl` checker has stopped working...](#faqperl)
4.6. [What happened to the `rustc` checker?](#faqrust)
4.7. [What happened to the `xcrun` checker?](#faqxcrun)
4.8. [I run a checker and the location list is not updated...](#faqloclist)
4.8. [I run`:lopen` or `:lwindow` and the error window is empty...](#faqloclist)
4.9. [How can I pass additional arguments to a checker?](#faqargs)
4.10. [Syntastic supports several checkers for my filetype - how do I tell which one(s) to use?](#faqcheckers)
4.11. [What is the difference between syntax checkers and style checkers?](#faqstyle)
4.12. [I have enabled multiple checkers for the current filetype. How can I display all errors from all checkers together?](#faqaggregate)
4.13. [How can I jump between the different errors without using the location list at the bottom of the window?](#faqlnext)
4.14. [My favourite checker needs to load a configuration file from the project's root rather than the current directory...](#faqconfig)
4.15. [The error window is closed automatically when I :quit the current buffer but not when I :bdelete it?](#faqbdelete)
5. [Resources](#otherresources)
- - -
@ -150,7 +152,7 @@ You now have pathogen installed and can put syntastic into `~/.vim/bundle` like
this:
```sh
cd ~/.vim/bundle && \
git clone https://github.com/scrooloose/syntastic.git
git clone --depth=1 https://github.com/scrooloose/syntastic.git
```
Quit vim and start it back up to reload it, then type:
```vim
@ -227,19 +229,40 @@ or the error output for a syntax checker may have changed. In this case, make
sure you have the latest version of the syntax checker installed. If it still
fails then post an [issue][bug_tracker] - or better yet, create a pull request.
<a name="faqpython3"></a>
<a name="faqpython"></a>
__4.2. Q. The `python` checker complains about syntactically valid Python 3 constructs...__
__4.2. Q. How can I check scripts written for different versions of Python?__
A. Configure the `python` checker to call a Python 3 interpreter rather than
Python 2, e.g:
```vim
let g:syntastic_python_python_exec = '/path/to/python3'
```
A. Install a Python version manager such as [virtualenv][virtualenv]
or [pyenv][pyenv], activate the environment for the relevant version
of Python, and install in it the checkers you want to use. Set
`g:syntastic_python_checkers` accordingly in your `vimrc`, and run [Vim][vim]
from the virtual environment.
If you're starting Vim from a desktop manager rather than from a terminal you
might need to write wrapper scripts around your checkers, to activate the
virtual environment before running the actual checks. Then you'll need to
point the relevant `g:syntastic_python_<checker>_exec` variables to the wrapper
scripts.
<a name="faqruby"></a>
__4.3. Q. How can I check scripts written for different versions of Ruby?__
A. Install a Ruby version manager such as [rvm][rvm] or [rbenv][rbenv],
activate the environment for the relevant version of Ruby, and install in it
the checkers you want to use. Set `g:syntastic_ruby_checkers` accordingly in
your `vimrc`, and run [Vim][vim] from the virtual environment.
If you're starting Vim from a desktop manager rather than from a terminal you
might need to write wrapper scripts around your checkers, to activate the
virtual environment before running the actual checks. Then you'll need to
point the relevant `g:syntastic_ruby_<checker>_exec` variables to the wrapper
scripts.
<a name="faqhtml5"></a>
__4.3. Q. Are there any local checkers for HTML5 that I can use with syntastic?__
__4.4. Q. Are there any local checkers for HTML5 that I can use with syntastic?__
[HTML Tidy][tidy_old] has a fork named [HTML Tidy for HTML5][tidy]. It's a drop
in replacement, and syntastic can use it without changes. Just install it
@ -259,7 +282,7 @@ let g:syntastic_html_validator_api = 'http://localhost:8888/'
<a name="faqperl"></a>
__4.4. Q. The `perl` checker has stopped working...__
__4.5. Q. The `perl` checker has stopped working...__
A. The `perl` checker runs `perl -c` against your file, which in turn
__executes__ any `BEGIN`, `UNITCHECK`, and `CHECK` blocks, and any `use`
@ -275,14 +298,14 @@ let g:syntastic_enable_perl_checker = 1
<a name="faqrust"></a>
__4.5. Q. What happened to the `rustc` checker?__
__4.6. Q. What happened to the `rustc` checker?__
A. It is now part of the [rust.vim][rust] plugin. If you install this plugin the
checker should be picked up automatically by syntastic.
<a name="faqxcrun"></a>
__4.6. Q. What happened to the `xcrun` checker?__
__4.7. Q. What happened to the `xcrun` checker?__
A. The `xcrun` checker used to have a security problem and it has been removed.
A better checker for __Swift__ is part of the [vim-swift][swift] plugin. If you
@ -290,8 +313,8 @@ install this plugin the checker should be picked up automatically by syntastic.
<a name="faqloclist"></a>
__4.7. Q. I run a checker and the location list is not updated...__
__4.7. Q. I run`:lopen` or `:lwindow` and the error window is empty...__
__4.8. Q. I run a checker and the location list is not updated...__
__4.8. Q. I run`:lopen` or `:lwindow` and the error window is empty...__
A. By default the location list is changed only when you run the `:Errors`
command, in order to minimise conflicts with other plugins. If you want the
@ -303,7 +326,7 @@ let g:syntastic_always_populate_loc_list = 1
<a name="faqargs"></a>
__4.8. Q. How can I pass additional arguments to a checker?__
__4.9. Q. How can I pass additional arguments to a checker?__
A. Almost all syntax checkers use the `makeprgBuild()` function. Those checkers
that do can be configured using global variables. The general form of the
@ -319,7 +342,7 @@ See `:help syntastic-checker-options` for more information.
<a name="faqcheckers"></a>
__4.9. Q. Syntastic supports several checkers for my filetype - how do I tell it
__4.10. Q. Syntastic supports several checkers for my filetype - how do I tell it
which one(s) to use?__
A. Stick a line like this in your `vimrc`:
@ -360,7 +383,7 @@ filetype of the current file is `php`).
<a name="faqstyle"></a>
__4.10. Q. What is the difference between syntax checkers and style checkers?__
__4.11. Q. What is the difference between syntax checkers and style checkers?__
A. The errors and warnings they produce are highlighted differently and can
be filtered by different rules, but otherwise the distinction is pretty much
@ -390,7 +413,7 @@ See `:help syntastic_quiet_messages` for details.
<a name="faqaggregate"></a>
__4.11. Q. I have enabled multiple checkers for the current filetype. How can I
__4.12. Q. I have enabled multiple checkers for the current filetype. How can I
display all errors from all checkers together?__
A. Set `g:syntastic_aggregate_errors` to 1 in your `vimrc`:
@ -402,7 +425,7 @@ See `:help syntastic-aggregating-errors` for more details.
<a name="faqlnext"></a>
__4.12. Q. How can I jump between the different errors without using the location
__4.13. Q. How can I jump between the different errors without using the location
list at the bottom of the window?__
A. Vim provides several built-in commands for this. See `:help :lnext` and
@ -412,9 +435,28 @@ If you use these commands a lot then you may want to add shortcut mappings to
your `vimrc`, or install something like [unimpaired][unimpaired], which provides such
mappings (among other things).
<a name="faqconfig"></a>
__4.14. My favourite checker needs to load a configuration file from the
project's root rather than the current directory...__
A. You can set up an `autocmd` to search for the configuration file in the
current directory and upwards, and add it to the checker's options when found.
For example for `jscs`:
```vim
function! FindConfig(prefix, what, where)
let cfg = findfile(a:what, escape(a:where, ' ') . ';')
return cfg !=# '' ? ' ' . a:prefix . ' ' . cfg : ''
endfunction
autocmd FileType javascript let b:syntastic_javascript_jscs_args =
\ get(g:, 'syntastic_javascript_jscs_args', '') .
\ FindConfig('-c', '.jscsrc', expand('<amatch>:p:h', 1))
```
<a name="faqbdelete"></a>
__4.13. Q. The error window is closed automatically when I :quit the current buffer
__4.15. Q. The error window is closed automatically when I :quit the current buffer
but not when I :bdelete it?__
A. There is no safe way to handle that situation automatically, but you can
@ -458,9 +500,12 @@ a look at [ghcmod-vim][ghcmod], [jedi-vim][jedi], [python-mode][python_mode], [v
[pathogen]: https://github.com/tpope/vim-pathogen
[perlrun]: http://perldoc.perl.org/perlrun.html#*-c*
[plug]: https://github.com/junegunn/vim-plug/
[pyenv]: https://github.com/yyuu/pyenv
[python_mode]: https://github.com/klen/python-mode
[rbenv]: https://github.com/rbenv/rbenv
[roktas]: https://github.com/roktas/syntastic-more
[rust]: https://github.com/rust-lang/rust.vim
[rvm]: https://rvm.io/
[stack_overflow]: http://stackoverflow.com/questions/tagged/syntastic
[swift]: https://github.com/kballard/vim-swift
[tidy]: http://www.htacg.org/tidy-html5/
@ -469,6 +514,7 @@ a look at [ghcmod-vim][ghcmod], [jedi-vim][jedi], [python-mode][python_mode], [v
[vam]: https://github.com/MarcWeber/vim-addon-manager
[vim]: http://www.vim.org/
[vimgo]: https://github.com/fatih/vim-go
[virtualenv]: https://virtualenv.pypa.io/en/stable/
[vnu]: http://about.validator.nu/
[vnu_jar]: https://github.com/validator/validator/releases/latest
[vnu_server]: http://validator.github.io/validator/#standalone

View file

@ -44,6 +44,7 @@ CONTENTS *syntastic-contents*
6.2.Editing files over network.............|syntastic-netrw|
6.3.The 'shellslash' option................|syntastic-shellslash|
6.4.Saving Vim sessions....................|syntastic-sessions|
6.5.The location list callback.............|syntastic-loclist-callback|
7.Compatibility with other software............|syntastic-compatibility|
7.1.The csh and tcsh shells................|syntastic-csh|
7.2.Eclim..................................|syntastic-eclim|
@ -882,6 +883,7 @@ The syntax is of course identical to that of |syntastic_quiet_messages|.
------------------------------------------------------------------------------
5.6 Debugging *syntastic-config-debug*
*syntastic-debug*
Syntastic can log a trace of its working to Vim's |message-history|. To verify
the command line constructed by syntastic to run a checker, set the variable
@ -958,6 +960,29 @@ remove option "blank" from 'sessionoptions': >
This will prevent `:mksession` from saving |syntastic-error-window| as empty
quickfix windows.
------------------------------------------------------------------------------
6.5 The location list callback *syntastic-loclist-callback*
*SyntasticCheckHook()*
Syntastic also gives you direct access to the list of errors. A function
named |SyntasticCheckHook()| is called by syntastic (if it exists) right
before populating the |location-list| and enabling the notifiers. The function
takes exactly one argument, the list of errors in |location-list| format (see
|getqflist()| for details). format. You can do essentially anything with this
list, as long as you don't change its format, and you don't add or remove
elements.
For example the following function will make the error window smaller if fewer
than 10 errors are found: >
function! SyntasticCheckHook(errors)
if !empty(a:errors)
let g:syntastic_loc_list_height = min([len(a:errors), 10])
endif
endfunction
<
(Please keep in mind however that Vim options |winheight| and |winminheight|
also affect window sizes.)
==============================================================================
7. Compatibility with other software *syntastic-compatibility*

View file

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

View file

@ -19,7 +19,7 @@ let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_matlab_mlint_GetLocList() dict
let makeprg = self.makeprgBuild({ 'args_after': '-id $*' })
let makeprg = self.makeprgBuild({ 'args_after': '-id' })
let errorformat =
\ 'L %l (C %c): %*[a-zA-Z0-9]: %m,'.

View file

@ -2840,7 +2840,7 @@ function! s:cfile() abort
elseif getline('.') =~# '^#\trenamed:.* -> '
let file = '/'.matchstr(getline('.'),' -> \zs.*')
return [file]
elseif getline('.') =~# '^#\t\(\k\| \)\+: *.'
elseif getline('.') =~# '^#\t\(\k\| \)\+\p\?: *.'
let file = '/'.matchstr(getline('.'),': *\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$')
return [file]
elseif getline('.') =~# '^#\t.'

View file

@ -3,9 +3,11 @@
FEATURES:
* If you open a new buffer with a Go filename it get automatically populated based on the directory. If there are no Go files a simple main package is created, otherwise the file will include the package declaration line based on the package in the current directory. Checkout the demo to see it in action: https://twitter.com/fatih/status/748333086643994624. This is enabled by default. Can be disabled with `let g:go_template_autocreate = 0`. You can use your own template with `let g:go_template_file = "foo.go"` and putting the file under the `templates/` folder. [gh-918]
* The snippet expansion `json` is now much more smarter. It pre populates the placeholder according to the first word and it also applies `snake_case` or `camelCase` conversion. Checkout the demo to see it in action: https://github.com/fatih/vim-go/pull/927 [gh-927]
* **`:GoSameIds`** support. When called highlights all same identifiers in the current file. Can be also enabled to highlight identifiers automatically. Checkout the demo to see it in action: https://twitter.com/fatih/status/753673709278339072. [gh-936]
* Add new `errp` snippet to expand an `if err != nil { panic() }` clause [gh-926]
IMPROVEMENTS:
* `:GoDoc` accepts arguments now which are passed directly to `godoc`. So usages like `:GoDoc flag` works again (it was changed in previous versions [gh-894]
* `:GoDef` works now for modified files as well [gh-910]
* Internal: fix indentations on all files to **2-spaces/no tabs**. This is now the default vim-go style across all VimL files [gh-915]

View file

@ -7,7 +7,18 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
return {'err': "bin path not found"}
endif
let filename = expand('%:p')
let filename = fnamemodify(expand("%"), ':p:gs?\\?/?')
if !filereadable(filename)
" this might happen for new buffers which are not written yet
return {'err': "file does not exist"}
endif
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 filename = l:tmpname
endif
let dirname = expand('%:p:h')
let pkg = go#package#ImportPath(dirname)
@ -80,12 +91,18 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
" the query might take time, let us give some feedback
call go#util#EchoProgress("analysing ...")
if a:mode !=# 'what'
" the query might take time, let us give some feedback
call go#util#EchoProgress("analysing ...")
endif
" run, forrest run!!!
let out = go#util#System(command)
if exists("l:tmpname")
call delete(l:tmpname)
endif
let $GOPATH = old_gopath
if go#util#ShellError() != 0
" the output contains the error message
@ -268,37 +285,65 @@ function! go#guru#What(selected)
let out = s:RunGuru('what', 'json', a:selected, 0)
if has_key(out, 'err')
return out.err
return {'err': out.err}
endif
call s:loclistSecond(out.out)
let result = json_decode(out.out)
if type(result) != type({})
return {'err': "malformed output from guru"}
endif
if !has_key(result, 'what')
return {'err': "no what query found for the given identifier"}
endif
return {'out': result.what}
return result
endfunction
function! go#guru#SameIds(selected)
call go#guru#ClearSameIds()
let result = go#guru#What(a:selected)
if has_key(out, 'err')
call go#util#EchoError(out.err)
if has_key(result, 'err') && !get(g:, 'go_auto_sameids', 0)
" only echo if it's called via `:GoSameIds, but not if it's in automode
call go#util#EchoError(result.err)
return
endif
if !has_key(result.out, 'sameids')
call go#util#EchoError("no same_ids founds for the given identifier")
return -1
if !has_key(result, 'sameids')
if !get(g:, 'go_auto_sameids', 0)
call go#util#EchoError("no same_ids founds for the given identifier")
endif
return
endif
let same_ids = result.what.sameids
echo same_ids
let poslen = 0
for enclosing in result['enclosing']
if enclosing['desc'] == 'identifier'
let poslen = enclosing['end'] - enclosing['start']
break
endif
endfor
" return when there's no identifier to highlight.
if poslen == 0
return
endif
hi goSameId term=bold cterm=bold ctermbg=white ctermfg=black
let same_ids = result['sameids']
" highlight the lines
for item in same_ids
let pos = split(item, ':')
call matchaddpos('goSameId', [[str2nr(pos[-2]), str2nr(pos[-1]), str2nr(poslen)]])
endfor
endfunction
function! go#guru#ClearSameIds()
let m = getmatches()
for item in m
if item['group'] == 'goSameId'
call matchdelete(item['id'])
endif
endfor
endfunction
" vim: sw=2 ts=2 et

View file

@ -131,85 +131,121 @@ function! go#util#Shelljoin(arglist, ...)
return join(map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')'), ' ')
endif
return join(map(copy(a:arglist), 'shellescape(v:val)'), ' ')
finally
let &shellslash = ssl_save
endtry
return join(map(copy(a:arglist), 'shellescape(v:val)'), ' ')
finally
let &shellslash = ssl_save
endtry
endfunction
fu! go#util#Shellescape(arg)
if s:has_vimproc()
return vimproc#shellescape(a:arg)
endif
try
let ssl_save = &shellslash
set noshellslash
return shellescape(a:arg)
finally
let &shellslash = ssl_save
endtry
if s:has_vimproc()
return vimproc#shellescape(a:arg)
endif
try
let ssl_save = &shellslash
set noshellslash
return shellescape(a:arg)
finally
let &shellslash = ssl_save
endtry
endf
" Shelllist returns a shell-safe representation of the items in the given
" arglist. The {special} argument of shellescape() may optionally be passed.
function! go#util#Shelllist(arglist, ...)
try
let ssl_save = &shellslash
set noshellslash
if a:0
return map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')')
endif
return map(copy(a:arglist), 'shellescape(v:val)')
finally
let &shellslash = ssl_save
endtry
try
let ssl_save = &shellslash
set noshellslash
if a:0
return map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')')
endif
return map(copy(a:arglist), 'shellescape(v:val)')
finally
let &shellslash = ssl_save
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)
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('.'))
return go#util#Offset(line('.'), col('.'))
endfunction
" Windo is like the built-in :windo, only it returns to the window the command
" was issued from
function! go#util#Windo(command)
let s:currentWindow = winnr()
try
execute "windo " . a:command
finally
execute s:currentWindow. "wincmd w"
unlet s:currentWindow
endtry
let s:currentWindow = winnr()
try
execute "windo " . a:command
finally
execute s:currentWindow. "wincmd w"
unlet s:currentWindow
endtry
endfunction
" snippetcase converts the given word to given preferred snippet setting type
" case.
function! go#util#snippetcase(word)
let l:snippet_case = get(g:, 'go_snippet_case_type', "snakecase")
if l:snippet_case == "snakecase"
return go#util#snakecase(a:word)
elseif l:snippet_case == "camelcase"
return go#util#camelcase(a:word)
else
return a:word " do nothing
endif
endfunction
" snakecase converts a string to snake case. i.e: FooBar -> foo_bar
" Copied from tpope/vim-abolish
function! go#util#snakecase(word)
let word = substitute(a:word,'::','/','g')
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
let word = substitute(word,'\(\l\|\d\)\(\u\)','\1_\2','g')
let word = substitute(word,'[.-]','_','g')
let word = tolower(word)
return word
endfunction
" camelcase converts a string to camel case. i.e: FooBar -> fooBar
" Copied from tpope/vim-abolish
function! go#util#camelcase(word)
let word = substitute(a:word, '-', '_', 'g')
if word !~# '_' && word =~# '\l'
return substitute(word,'^.','\l&','')
else
return substitute(word,'\C\(_\)\=\(.\)','\=submatch(1)==""?tolower(submatch(2)) : toupper(submatch(2))','g')
endif
endfunction
" TODO(arslan): I couldn't parameterize the highlight types. Check if we can
" simplify the following functions
function! go#util#EchoSuccess(msg)
redraws! | echon "vim-go: " | echohl Function | echon a:msg | echohl None
redraws! | echon "vim-go: " | echohl Function | echon a:msg | echohl None
endfunction
function! go#util#EchoError(msg)
redraws! | echon "vim-go: " | echohl ErrorMsg | echon a:msg | echohl None
redraws! | echon "vim-go: " | echohl ErrorMsg | echon a:msg | echohl None
endfunction
function! go#util#EchoWarning(msg)
redraws! | echon "vim-go: " | echohl WarningMsg | echon a:msg | echohl None
redraws! | echon "vim-go: " | echohl WarningMsg | echon a:msg | echohl None
endfunction
function! go#util#EchoProgress(msg)
redraws! | echon "vim-go: " | echohl Identifier | echon a:msg | echohl None
redraws! | echon "vim-go: " | echohl Identifier | echon a:msg | echohl None
endfunction
" vim: sw=2 ts=2 et

View file

@ -552,6 +552,17 @@ CTRL-t
object as does the selected identifier, within any package in the analysis
scope.
*:GoSameIds*
:GoSameIds
Highlights all identifiers that are equivalent to the identifier under the
cursor.
*:GoSameIdsClear*
:GoSameIdsClear
Clears all SameIds highlights from a |:GoSameIds| call.
*:GoMetaLinter*
:GoMetaLinter [path]
@ -778,7 +789,7 @@ Shows the godef tag stack
*(go-def-stack-clear)*
Resets and clers the tasg stack
Resets and clears the tag stack
*(go-def-pop)*
@ -920,11 +931,17 @@ with |:GoPlay|. By default it's enabled. >
Use this option to show the type info (|:GoInfo|) for the word under the cursor
automatically. Whenever the cursor changes the type info will be updated.
By default it's disabled >
By default it's disabled.
>
let g:go_auto_type_info = 0
<
*'g:go_auto_sameids'*
Use this option to highlight all uses of the identifier under the cursor
(:GoSameIds) automatically. By default it's disabled.
>
let g:go_auto_sameids = 0
<
*'g:go_jump_to_error'*
Use this option to enable/disable passing the bang attribute to the mappings
@ -1044,6 +1061,28 @@ is used. Use "neosnippet" for neosnippet.vim: >
let g:go_snippet_engine = "ultisnips"
<
*'g:go_snippet_case_type'*
Use this option to define the default conversion type of snippet expansion for
field tags. For the following case, if `snakecase` is used the `json` snippet
will expand to:
>
type T struct {
FooBarQuz string `json:"foo_bar_quz"
}
<
If "camelcase" is used:
>
type T struct {
FooBarQuz string `json:"fooBarQuz"
}
<
By default "snakecase" is used. Current values are: ["snakecase", "camelcase"].
>
let g:go_snippet_case_type = "snakecase"
<
*'g:go_get_update'*
Use this option to disable updating dependencies with |GoInstallBinaries|. By

View file

@ -12,9 +12,8 @@ command! -range=% GoFreevars call go#guru#Freevars(<count>)
command! -range=% GoChannelPeers call go#guru#ChannelPeers(<count>)
command! -range=% GoReferrers call go#guru#Referrers(<count>)
command! -nargs=? GoGuruTags call go#guru#Tags(<f-args>)
" TODO(arslan): enable this once the function is implemented
" command! -range=% GoSameIds call go#guru#SameIds(<count>)
command! -range=% GoSameIds call go#guru#SameIds(<count>)
command! -range=0 GoSameIdsClear call go#guru#ClearSameIds()
" -- tool
command! -nargs=0 GoFiles echo go#tool#Files()

View file

@ -43,9 +43,7 @@ nnoremap <silent> <Plug>(go-callstack) :<C-u>call go#guru#Callstack(-1)<CR>
xnoremap <silent> <Plug>(go-freevars) :<C-u>call go#guru#Freevars(0)<CR>
nnoremap <silent> <Plug>(go-channelpeers) :<C-u>call go#guru#ChannelPeers(-1)<CR>
nnoremap <silent> <Plug>(go-referrers) :<C-u>call go#guru#Referrers(-1)<CR>
" TODO(arslan): enable this once the function is implemented
" nnoremap <silent> <Plug>(go-sameids) :<C-u>call go#guru#SameIds(-1)<CR>
nnoremap <silent> <Plug>(go-sameids) :<C-u>call go#guru#SameIds(-1)<CR>
nnoremap <silent> <Plug>(go-rename) :<C-u>call go#rename#Rename(!g:go_jump_to_error)<CR>

View file

@ -151,14 +151,7 @@ if err != nil {
${0}
endsnippet
# error snippet
snippet errt "Error test fatal " !b
if err != nil {
t.Fatal(err)
}
${0}
endsnippet
# error multiple return
snippet errn, "Error return with two return values" !b
if err != nil {
return ${1:nil}, err
@ -166,6 +159,23 @@ if err != nil {
${0}
endsnippet
# error panic
snippet errp "Error panic" !b
if err != nil {
panic(${1})
}
${0}
endsnippet
# error test
snippet errt "Error test fatal " !b
if err != nil {
t.Fatal(err)
}
${0}
endsnippet
# error handle
snippet errh "Error handle and return" !b
if err != nil {
${1}
@ -174,8 +184,9 @@ if err != nil {
${0}
endsnippet
# json field tag
snippet json "\`json:key\`"
\`json:"${1:keyName}"\`
\`json:"${1:`!v go#util#snippetcase(matchstr(getline("."), '\w\+'))`}"\`
endsnippet
# fallthrough

View file

@ -149,6 +149,14 @@ abbr if err != nil { return }
}
${0}
# error snippet with panic
snippet errp
abbr if err != nil { ... }
if err != nil {
panic(${1})
}
${0}
# json snippet
snippet json
abbr \`json:key\`

View file

@ -151,6 +151,11 @@ augroup vim-go
autocmd CursorHold *.go nested call go#complete#Info(1)
endif
" GoSameId automatic update
if get(g:, "go_auto_sameids", 0)
autocmd CursorMoved *.go nested call go#guru#SameIds(-1)
endif
" Echo the identifier information when completion is done. Useful to see
" the signature of a function, etc...
if exists('##CompleteDone')

View file

@ -286,19 +286,22 @@ if g:go_highlight_operators != 0
syn match goOperator /:=\|||\|<-\|++\|--/
" match ...
syn match goOperator /\.\.\./
hi def link goPointerOperator Operator
endif
hi def link goOperator Operator
" Functions;
if g:go_highlight_functions != 0
syn match goDeclaration /\<func\>/ nextgroup=goReceiver,goFunction skipwhite skipnl
syn match goReceiver /([^),]\+)/ contained nextgroup=goFunction contains=goReceiverType skipwhite skipnl
syn match goReceiverType /\(\s\|*\)\w\+)/hs=s+1,he=e-1 contained
syn match goFunction /\w\+/ contained
syn match goReceiver /(\(\w\|[ *]\)\+)/ contained nextgroup=goFunction contains=goReceiverVar skipwhite skipnl
syn match goReceiverVar /\w\+/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl
syn match goReceiverType /\w\+/ contained
syn match goFunction /\w\+/ contained
else
syn keyword goDeclaration func
endif
hi def link goReceiverType Type
hi def link goFunction Function
" Methods;
@ -320,6 +323,7 @@ if g:go_highlight_types != 0
syn match goTypeDecl /\<type\>/ nextgroup=goTypeName skipwhite skipnl
syn match goTypeName /\w\+/ contained nextgroup=goDeclType skipwhite skipnl
syn match goDeclType /\<interface\|struct\>/ contained skipwhite skipnl
hi def link goReceiverType Type
else
syn keyword goDeclType struct interface
syn keyword goDeclaration type
@ -362,6 +366,7 @@ if g:go_highlight_build_constraints != 0
hi def link goPackageComment Comment
endif
hi def link goSameId IncSearch
" Search backwards for a global declaration to start processing the syntax.
"syn sync match goSync grouphere NONE /^\(const\|var\|type\|func\)\>/

View file

@ -1,5 +1,27 @@
priority -50
global !p
def create_table(snip):
# retrieving single line from current string and treat it like tabstops count
placeholders_string = snip.buffer[snip.line].strip().split("x",1)
rows_amount = int(placeholders_string[0])
columns_amount = int(placeholders_string[1])
# erase current line
snip.buffer[snip.line] = ''
# create anonymous snippet with expected content and number of tabstops
anon_snippet_title = ' | '.join(['$' + str(col) for col in range(1,columns_amount+1)]) + "\n"
anon_snippet_delimiter = ':-|' * (columns_amount-1) + ":-\n"
anon_snippet_body = ""
for row in range(1,rows_amount+1):
anon_snippet_body += ' | '.join(['$' + str(row*columns_amount+col) for col in range(1,columns_amount+1)]) + "\n"
anon_snippet_table = anon_snippet_title + anon_snippet_delimiter + anon_snippet_body
# expand anonymous snippet
snip.expand_anon(anon_snippet_table)
endglobal
###########################
# Sections and Paragraphs #
###########################
@ -50,4 +72,21 @@ $1
$0
endsnippet
snippet refl "Reference Link"
[${1:${VISUAL:Text}}][${2:id}]$0
[$2]:${4:http://${3:www.url.com}} "${5:$4}"
endsnippet
snippet fnt "Footnote"
[^${1:${VISUAL:Footnote}}]$0
[^$1]:${2:Text}
endsnippet
post_jump "create_table(snip)"
snippet "tb(\d+x\d+)" "Customizable table" br
`!p snip.rv = match.group(1)`
endsnippet
# vim:ft=snippets:

View file

@ -1,5 +1,14 @@
priority -50
global !p
import vim
# Set g:ultisnips_php_scalar_types to 1 if you'd like to enable PHP 7's scalar types for return values
def isPHPScalarTypesEnabled():
isEnabled = vim.eval("get(g:, 'ultisnips_php_scalar_types', 0)") == "1"
return isEnabled or re.match('<\?php\s+declare\(strict_types=[01]\);', '\n'.join(vim.current.window.buffer))
endglobal
## Snippets from SnipMate, taken from
## https://github.com/scrooloose/snipmate-snippets.git
@ -9,7 +18,7 @@ snippet gm "PHP Class Getter" b
*
* @return ${2:string}
*/
public function get${1/\w+\s*/\u$0/}()
public function get${1/\w+\s*/\u$0/}()`!p snip.rv = ': '+t[2] if isPHPScalarTypesEnabled() else ''`
{
return $this->$1;
}
@ -36,7 +45,7 @@ snippet gs "PHP Class Getter Setter" b
*
* @return ${2:string}
*/
public function get${1/\w+\s*/\u$0/}()
public function get${1/\w+\s*/\u$0/}()`!p snip.rv = ': '+t[2] if isPHPScalarTypesEnabled() else ''`
{
return $this->$1;
}

View file

@ -2,6 +2,8 @@ snippet <?
<?php
${0}
snippet dst "declare(strict_types=1)"
declare(strict_types=${1:1});
snippet ec
echo ${0};
snippet <?e