Next: , Previous: , Up: Go-Mode Features   [Index]


A.4.2 Managing Imports

The new go-mode has three functions for working with imports:

go-import-add (‘C-c C-a)

will prompt you for an import path (again supporting tab completion) and insert it in the import block, creating it if necessary. If an import already existed but was commented, it will be uncommented. If prefixed with ‘C-u’, it will ask you for an alias, too. An annoying procedure of moving around and mental context switching has just been reduced to a keystroke.

go-remove-unused-imports

Instead of offering a function for removing a single import, go-mode will detect all unused imports and delete them (or comment them) once you run go-remove-unused-imports. It is not bound to a key by default, but you can bind it yourself if you want to. Personally I have bound it to ‘C-c C-r’:

(add-hook 'go-mode-hook (lambda ()
   (local-set-key (kbd "C-c C-r") 'go-remove-unused-imports)))
go-goto-imports

If you decide you want to look at your imports or edit them manually, go-goto-imports will take you to them automatically, placing your cursor after the last import. It isn’t bound to a key.