Skip to content

Instantly share code, notes, and snippets.

@paulsmith
Created April 29, 2013 18:00
Show Gist options
  • Select an option

  • Save paulsmith/5483440 to your computer and use it in GitHub Desktop.

Select an option

Save paulsmith/5483440 to your computer and use it in GitHub Desktop.
A simple Vim command to quickly append a package to the list of imports in a Go source code file.
" AppendGoPackage() prompts you for the name of a Go package, searches for
" the import statement at the top of the file, appends the package to the
" list of names, and restores the cursor's location.
function! AppendGoPackage()
call inputsave()
let s:pkg = input("Go package: ")
call inputrestore()
let s:cmd = "normal! ma?^import (\<CR>%O\t\"" . s:pkg . "\"\<ESC>`a"
execute s:cmd
endfunction
nnoremap <leader>ai :call AppendGoPackage()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment