mirror of
https://github.com/golang/go
synced 2024-11-12 06:30:21 -07:00
misc/vim: Adding flag-guarding for Vim commands
Default behavior is the same as before, but now a user may selectively disable some commands. Also: deleted the mappings for import.vim. Tested: by trying the commands for fmt, import and godoc in succession to make sure they still work. Also, ran test.sh in ftplugin/go. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/10124043
This commit is contained in:
parent
e59a09fb1a
commit
b76ddefee5
@ -12,11 +12,25 @@
|
||||
" It tries to preserve cursor position and avoids
|
||||
" replacing the buffer with stderr output.
|
||||
"
|
||||
" Options:
|
||||
"
|
||||
" g:go_fmt_commands [default=1]
|
||||
"
|
||||
" Flag to indicate whether to enable the commands listed above.
|
||||
"
|
||||
if exists("b:did_ftplugin_go_fmt")
|
||||
finish
|
||||
endif
|
||||
|
||||
command! -buffer Fmt call s:GoFormat()
|
||||
|
||||
if !exists("g:go_fmt_commands")
|
||||
let g:go_fmt_commands = 1
|
||||
endif
|
||||
|
||||
|
||||
if g:go_fmt_commands
|
||||
command! -buffer Fmt call s:GoFormat()
|
||||
endif
|
||||
|
||||
function! s:GoFormat()
|
||||
let view = winsaveview()
|
||||
|
@ -24,23 +24,40 @@
|
||||
" imported, an error will be displayed and the buffer will be
|
||||
" untouched.
|
||||
"
|
||||
" In addition to these commands, there are also two shortcuts mapped:
|
||||
" If you would like to add shortcuts, you can do so by doing the following:
|
||||
"
|
||||
" \f - Runs :Import fmt
|
||||
" \F - Runs :Drop fmt
|
||||
" Import fmt
|
||||
" au Filetype go nnoremap <buffer> <LocalLeader>f :Import fmt<CR>
|
||||
"
|
||||
" The backslash is the default maplocalleader, so it is possible that
|
||||
" Drop fmt
|
||||
" au Filetype go nnoremap <buffer> <LocalLeader>F :Drop fmt<CR>
|
||||
"
|
||||
" Import the word under your cursor
|
||||
" au Filetype go nnoremap <buffer> <LocalLeader>k
|
||||
" \ :exe 'Import ' . expand('<cword>')<CR>
|
||||
"
|
||||
" The backslash '\' is the default maplocalleader, so it is possible that
|
||||
" your vim is set to use a different character (:help maplocalleader).
|
||||
"
|
||||
" Options:
|
||||
"
|
||||
" g:go_import_commands [default=1]
|
||||
"
|
||||
" Flag to indicate whether to enable the commands listed above.
|
||||
"
|
||||
if exists("b:did_ftplugin_go_import")
|
||||
finish
|
||||
endif
|
||||
|
||||
command! -buffer -nargs=? -complete=customlist,go#complete#Package Drop call s:SwitchImport(0, '', <f-args>)
|
||||
command! -buffer -nargs=1 -complete=customlist,go#complete#Package Import call s:SwitchImport(1, '', <f-args>)
|
||||
command! -buffer -nargs=* -complete=customlist,go#complete#Package ImportAs call s:SwitchImport(1, <f-args>)
|
||||
map <buffer> <LocalLeader>f :Import fmt<CR>
|
||||
map <buffer> <LocalLeader>F :Drop fmt<CR>
|
||||
if !exists("g:go_import_commands")
|
||||
let g:go_import_commands = 1
|
||||
endif
|
||||
|
||||
if g:go_import_commands
|
||||
command! -buffer -nargs=? -complete=customlist,go#complete#Package Drop call s:SwitchImport(0, '', <f-args>)
|
||||
command! -buffer -nargs=1 -complete=customlist,go#complete#Package Import call s:SwitchImport(1, '', <f-args>)
|
||||
command! -buffer -nargs=* -complete=customlist,go#complete#Package ImportAs call s:SwitchImport(1, <f-args>)
|
||||
endif
|
||||
|
||||
function! s:SwitchImport(enabled, localname, path)
|
||||
let view = winsaveview()
|
||||
|
@ -3,6 +3,20 @@
|
||||
" license that can be found in the LICENSE file.
|
||||
"
|
||||
" godoc.vim: Vim command to see godoc.
|
||||
"
|
||||
"
|
||||
" Commands:
|
||||
"
|
||||
" :Godoc
|
||||
"
|
||||
" Open the relevant Godoc for either the word[s] passed to the command or
|
||||
" the, by default, the word under the cursor.
|
||||
"
|
||||
" Options:
|
||||
"
|
||||
" g:go_godoc_commands [default=1]
|
||||
"
|
||||
" Flag to indicate whether to enable the commands listed above.
|
||||
|
||||
if exists("g:loaded_godoc")
|
||||
finish
|
||||
@ -12,6 +26,16 @@ let g:loaded_godoc = 1
|
||||
let s:buf_nr = -1
|
||||
let s:last_word = ''
|
||||
|
||||
if !exists('g:go_godoc_commands')
|
||||
let g:go_godoc_commands = 1
|
||||
endif
|
||||
|
||||
if g:go_godoc_commands
|
||||
command! -nargs=* -range -complete=customlist,go#complete#Package Godoc :call s:Godoc(<q-args>)
|
||||
endif
|
||||
|
||||
nnoremap <silent> <Plug>(godoc-keyword) :<C-u>call <SID>Godoc('')<CR>
|
||||
|
||||
function! s:GodocView()
|
||||
if !bufexists(s:buf_nr)
|
||||
leftabove new
|
||||
@ -92,7 +116,4 @@ function! s:Godoc(...)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
command! -nargs=* -range -complete=customlist,go#complete#Package Godoc :call s:Godoc(<q-args>)
|
||||
nnoremap <silent> <Plug>(godoc-keyword) :<C-u>call <SID>Godoc('')<CR>
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
Loading…
Reference in New Issue
Block a user