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

Updated plugins and added vim-abolish

This commit is contained in:
amix
2017-05-26 11:30:32 +02:00
parent 85e105159e
commit 48a2c325c3
38 changed files with 1876 additions and 288 deletions

View File

@ -1,9 +1,9 @@
Thanks for improving vim-go! Before you dive in please read the following:
1. Please read our
[FAQ](https://github.com/fatih/vim-go/wiki/FAQ-Troubleshooting), it might
[Documentation](https://github.com/fatih/vim-go/blob/master/doc/vim-go.txt), it might
have answers for your problem
2. If you add a new feature please don't forget to update the documentation:
[doc/vim-go.txt](https://github.com/fatih/vim-go/blob/master/doc/vim-go.txt)
[doc/vim-go.txt](https://github.com/fatih/vim-go/blob/master/doc/vim-go.txt.
3. If it's a breaking change or exceed +100 lines please open an issue first
and describe the changes you want to make.

View File

@ -1,12 +1,27 @@
## unplanned
FEATURES:
* New `:GoKeyify` command that turns unkeyed struct literals into keyed struct literals. [gh-1258]
* New `g:go_addtags_transform` setting to change the transform rule (snakecase, camelcase, etc..) for `:GoAddTags` command [gh-1275]
* New snippet shortcut assigned to `ife` that expands to `if err := foo(); err != nil { ... }` [gh-1268]
IMPROVEMENTS
* :GoMetaLinter can now exclude linters with the new `g:go_metalinter_excludes` option [gh-1253]
* Override `<C-LeftMouse>` mapping so `:GoDef` is used by default (as we do the same for `CTRL-]`, `gd`, etc. [gh-1264]
BUG FIXES:
* job: fix race between channel close and job exit [gh-1247]
* internal: fix system calls when using tcsh [gh-1276]
* path: return the unmodified GOPATH if autodetect is disabled [gh-1280]
* fix jumping to quickfix window when autom gometalinter on save was enabled [gh-1293]
BACKWARDS INCOMPATIBILITIES:
* `:GoLint` works on the whole directory instead of the current file. To use it for the current file give it as an argument, i.e `:GoLint foo.go` [gh-1295]
* `go_snippet_case_type` is removed in favor of the new `go_addtags_transform` setting [gh-1299]
## 1.12 - (March 29, 2017)

View File

@ -0,0 +1,58 @@
function! go#keyify#Keyify()
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
let bin_path = go#path#CheckBinPath("keyify")
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
if empty(bin_path) || !exists('*json_decode')
let $GOPATH = old_gopath
return
endif
" Get result of command as json, that contains `start`, `end` and `replacement`
let command = printf("%s -json %s:#%s", bin_path, fname, go#util#OffsetCursor())
let output = go#util#System(command)
silent! let result = json_decode(output)
" We want to output the error message in case the result isn't a JSON
if type(result) != type({})
call go#util#EchoError(s:chomp(output))
let $GOPATH = old_gopath
return
endif
" Because keyify returns the byte before the region we want, we goto the
" byte after that
execute "goto" result.start + 1
let start = getpos('.')
execute "goto" result.end
let end = getpos('.')
let vis_start = getpos("'<")
let vis_end = getpos("'>")
" Replace contents between start and end with `replacement`
call setpos("'<", start)
call setpos("'>", end)
let select = 'gv'
" Make sure the visual mode is 'v', to avoid some bugs
normal! gv
if mode() !=# 'v'
let select .= 'v'
endif
silent! execute "normal!" select."\"=result.replacement\<cr>p"
" Replacement text isn't aligned, so it needs fix
normal! '<v'>=
call setpos("'<", vis_start)
call setpos("'>", vis_end)
let $GOPATH = old_gopath
endfunction
function! s:chomp(string)
return substitute(a:string, '\n\+$', '', '')
endfunction

View File

@ -123,12 +123,11 @@ function! go#lint#Golint(...) abort
endif
if a:0 == 0
let goargs = shellescape(expand('%'))
let out = go#util#System(bin_path)
else
let goargs = go#util#Shelljoin(a:000)
let out = go#util#System(bin_path . " " . go#util#Shelljoin(a:000))
endif
let out = go#util#System(bin_path . " " . goargs)
if empty(out)
echon "vim-go: " | echohl Function | echon "[lint] PASS" | echohl None
return
@ -255,9 +254,13 @@ function s:lint_job(args)
caddexpr a:msg
let &errorformat = old_errorformat
" TODO(arslan): cursor still jumps to first error even If I don't want
" it. Seems like there is a regression somewhere, but not sure where.
" TODO(jinleileiking): give a configure to jump or not
let l:winnr = winnr()
copen
exe l:winnr . "wincmd w"
endfunction
function! s:exit_cb(job, exitval) closure

View File

@ -33,22 +33,16 @@ function! go#path#GoPath(...) abort
let $GOPATH = a:1
endfunction
" Default returns the default GOPATH. If there is a single GOPATH it returns
" it. For multiple GOPATHS separated with a the OS specific separator, only
" the first one is returned. If GOPATH is not set, it uses the default GOPATH
" set starting with GO 1.8. This GOPATH can be retrieved via 'go env GOPATH'
" Default returns the default GOPATH. If GOPATH is not set, it uses the
" default GOPATH set starting with Go 1.8. This GOPATH can be retrieved via
" 'go env GOPATH'
function! go#path#Default() abort
if $GOPATH == ""
" use default GOPATH via go env
return go#util#gopath()
endif
let go_paths = split($GOPATH, go#util#PathListSep())
if len(go_paths) == 1
return $GOPATH
endif
return go_paths[0]
return $GOPATH
endfunction
" HasPath checks whether the given path exists in GOPATH environment variable
@ -134,8 +128,8 @@ function! go#path#BinPath() abort
elseif $GOBIN != ""
let bin_path = $GOBIN
else
" GOPATH (user set or default GO)
let bin_path = expand(go#path#Default() . "/bin/")
let go_paths = split(go#path#Default(), go#util#PathListSep())
let bin_path = expand(go_paths[0] . "/bin/")
endif
return bin_path

View File

@ -122,11 +122,13 @@ func s:create_cmd(args) abort
let l:offset = a:args.offset
let l:mode = a:args.mode
let l:cmd_args = a:args.cmd_args
let l:modifytags_transform = get(g:, 'go_addtags_transform', "snakecase")
" start constructing the command
let cmd = [bin_path]
call extend(cmd, ["-format", "json"])
call extend(cmd, ["-file", a:args.fname])
call extend(cmd, ["-transform", l:modifytags_transform])
if l:offset != 0
call extend(cmd, ["-offset", l:offset])

View File

@ -94,19 +94,29 @@ function! go#util#osarch() abort
return go#util#goos() . '_' . go#util#goarch()
endfunction
" System runs a shell command. It will reset the shell to /bin/sh for Unix-like
" systems if it is executable.
" System runs a shell command. If possible, it will temporary set
" the shell to /bin/sh for Unix-like systems providing a Bourne
" POSIX like environment.
function! go#util#System(str, ...) abort
" Preserve original shell and shellredir values
let l:shell = &shell
let l:shellredir = &shellredir
" Use a Bourne POSIX like shell. Some parts of vim-go expect
" commands to be executed using bourne semantics #988 and #1276.
" Alter shellredir to match bourne. Especially important if login shell
" is set to any of the csh or zsh family #1276.
if !go#util#IsWin() && executable('/bin/sh')
let &shell = '/bin/sh'
set shell=/bin/sh shellredir=>%s\ 2>&1
endif
try
let l:output = call('system', [a:str] + a:000)
return l:output
finally
" Restore original values
let &shell = l:shell
let &shellredir = l:shellredir
endtry
endfunction
@ -203,7 +213,7 @@ endfunction
" snippetcase converts the given word to given preferred snippet setting type
" case.
function! go#util#snippetcase(word) abort
let l:snippet_case = get(g:, 'go_snippet_case_type', "snakecase")
let l:snippet_case = get(g:, 'go_addtags_transform', "snakecase")
if l:snippet_case == "snakecase"
return go#util#snakecase(a:word)
elseif l:snippet_case == "camelcase"
@ -235,51 +245,6 @@ function! go#util#camelcase(word) abort
endif
endfunction
function! go#util#AddTags(line1, line2, ...) abort
" default is json
let l:keys = ["json"]
if a:0
let l:keys = a:000
endif
let l:line1 = a:line1
let l:line2 = a:line2
" If we're inside a struct and just call this function let us add the tags
" to all fields
" TODO(arslan): I don't like using patterns. Check if we can move it to
" `motion` and do it via AST based position
let ln1 = searchpair('struct {', '', '}', 'bcnW')
if ln1 == 0
echon "vim-go: " | echohl ErrorMsg | echon "cursor is outside the struct" | echohl None
return
endif
" searchpair only returns a single position
let ln2 = search('}', "cnW")
" if no range is given we apply for the whole struct
if l:line1 == l:line2
let l:line1 = ln1 + 1
let l:line2 = ln2 - 1
endif
for line in range(l:line1, l:line2)
" get the field name (word) that are not part of a commented line
let l:matched = matchstr(getline(line), '\(\/\/.*\)\@<!\w\+')
if empty(l:matched)
continue
endif
let word = go#util#snippetcase(l:matched)
let tags = map(copy(l:keys), 'printf("%s:%s", v:val,"\"'. word .'\"")')
let updated_line = printf("%s `%s`", getline(line), join(tags, " "))
" finally, update the line inplace
call setline(line, updated_line)
endfor
endfunction
" TODO(arslan): I couldn't parameterize the highlight types. Check if we can
" simplify the following functions
"

View File

@ -102,7 +102,7 @@ command.
Plugin 'fatih/vim-go'
* Vim |packages|
* Vim |packages|
>
git clone https://github.com/fatih/vim-go.git \
~/.vim/pack/plugins/start/vim-go
@ -167,7 +167,7 @@ COMMANDS *go-commands*
*:GoLint*
:GoLint [packages]
Run golint for the current Go file, or for given packages.
Run golint for the current directory, or for given packages.
*:GoDoc*
:GoDoc [word]
@ -219,14 +219,17 @@ COMMANDS *go-commands*
If [!] is not given the first error is jumped to.
*:GoDef*
:GoDef
:GoDef
gd
CTRL-]
g<C-LeftMouse>
<C-LeftMouse>
Goto declaration/definition for the declaration under the cursor. By default
the CTRL-] key and the mapping `gd` are enabled to invoke :GoDef for the
identifier under the cursor. See |'g:go_def_mapping_enabled'| to disable
them. No explicit arguments are supported.
Goto declaration/definition for the declaration under the cursor. By
default the CTRL-] shortcut, the mapping `gd` and <C-LeftMouse>,
g<LeftMouse> are enabled to invoke :GoDef for the identifier under the
cursor. See |'g:go_def_mapping_enabled'| to disable them. No explicit
arguments are supported.
vim-go also keeps a per-window location stack, roughly analogous to how
Vim's internal |tags| functionality works. This is pushed to every time a
@ -605,7 +608,7 @@ CTRL-t
Changes the build tags for various commands. If you have any file that
uses a custom build tag, such as `//+build integration` , this command can
be used to pass it to all tools that accepts tags, such as guru, gorenate,
etc..
etc..
The build tags is cleared (unset) if `""` is given. If no arguments is
given it prints the current custom build tags.
@ -742,7 +745,22 @@ CTRL-t
Toggles |'g:go_template_autocreate'|.
*:GoKeyify*
:GoKeyify
Uses `keyify` to turn unkeyed struct literals into keyed ones.
For example:
>
Person{"John", "Smith"}
<
Becomes:
>
Person{
Name: "John",
Surname: "Smith",
}
<
==============================================================================
MAPPINGS *go-mappings*
@ -1128,9 +1146,10 @@ Use this option to define the command to be used for |:GoDef|. By default
<
*'g:go_def_mapping_enabled'*
Use this option to enable/disable the default mapping of CTRL-] and (`gd`) for
GoDef and CTRL-t for :GoDefPop. Disabling it allows you to map something else
to these keys or mappings. Default is enabled. >
Use this option to enable/disable the default mapping of CTRL-],
<C-LeftMouse>, g<C-LeftMouse> and (`gd`) for GoDef and CTRL-t for :GoDefPop.
Disabling it allows you to map something else to these keys or mappings.
Default is enabled. >
let g:go_def_mapping_enabled = 1
<
@ -1169,28 +1188,6 @@ Use this option to define the default snippet engine. By default "ultisnips"
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'*
@ -1213,7 +1210,7 @@ set, so the relevant commands defaults are being used.
*'g:go_build_tags'*
These options that will be automatically passed to the `-tags` option of
various tools, such as `guru`, `gorename`, etc... This is a permanatent
various tools, such as `guru`, `gorename`, etc... This is a permanent
setting. A more useful way is to use |:GoBuildTags| to dynamically change or
remove build tags. By default it's not set.
>
@ -1538,6 +1535,31 @@ default it's 60 seconds. Must be in milliseconds.
>
let g:go_statusline_duration = 60000
<
*'g:go_addtags_transform'*
Sets the `transform` option for `gomodifytags` when using |:GoAddTags| or if
it's being used for snippet expansion of single fields. Possible options are:
`snakecase`, `camelcase`. For the following case, if `snakecase` is used the
field will be transformed 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_addtags_transform = 'snakecase'
<
==============================================================================
DEVELOPMENT *go-development*

View File

@ -33,6 +33,8 @@ if get(g:, "go_def_mapping_enabled", 1)
" useful again for Go source code
nnoremap <buffer> <silent> gd :GoDef<cr>
nnoremap <buffer> <silent> <C-]> :GoDef<cr>
nnoremap <buffer> <silent> <C-LeftMouse> <LeftMouse>:GoDef<cr>
nnoremap <buffer> <silent> g<LeftMouse> <LeftMouse>:GoDef<cr>
nnoremap <buffer> <silent> <C-w><C-]> :<C-u>call go#def#Jump("split")<CR>
nnoremap <buffer> <silent> <C-w>] :<C-u>call go#def#Jump("split")<CR>
nnoremap <buffer> <silent> <C-t> :<C-U>call go#def#StackPop(v:count1)<cr>

View File

@ -92,4 +92,7 @@ command! -nargs=* -buffer -complete=customlist,go#impl#Complete GoImpl call go#i
" -- template
command! -nargs=0 GoTemplateAutoCreateToggle call go#template#ToggleAutoCreate()
" -- keyify
command! -nargs=0 GoKeyify call go#keyify#Keyify()
" vim: sw=2 ts=2 et

View File

@ -143,6 +143,13 @@ else {
}
endsnippet
# if inline error
snippet ife "If with inline erro"
if err := ${1:condition}; err != nil {
${0:${VISUAL}}
}
endsnippet
# error snippet
snippet errn "Error return " !b
if err != nil {

View File

@ -118,6 +118,14 @@ snippet else
else {
${0}
}
# if inline error
snippet ife
abbr if err := ...; err != nil { ... }
if err := ${1:condition}; err != nil {
${0}
}
# error snippet
snippet errn
abbr if err != nil { ... }

View File

@ -21,6 +21,7 @@ let s:packages = [
\ "github.com/fatih/gomodifytags",
\ "github.com/zmb3/gogetdoc",
\ "github.com/josharian/impl",
\ "github.com/dominikh/go-tools/cmd/keyify",
\ ]
" These commands are available on any filetypes