Created
April 29, 2013 18:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " 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