I am using vim 8+ with vim-go and gopls. I have been able to get many of the features that and IDE would offer working such as importing packages on save, etc.

One behaviour I have not been able to replicate however is this the following... enter image description here

The above is a screenshot taken from vscode showing a list of possible options available from the fmt package.

Would love to replicate this functionality, or something similar, in generic vim.

Please let me know how this can be achieved.

1 Answer 1


I don't know if this is the "best" solution but this is something I managed to come up with making use of vim's omnicompletion.

function AutoCompleter()
  let previousChar = getline('.')[col('.') - 2]
  if previousChar == '.'
    return "\<c-x>\<c-o>"
    return "\<tab>"

  return ''

inoremap <tab> <c-r>=AutoCompleter()<cr>

This solution creates a function which returns the keystrokes for omnicompletion if the previous character is a .. Then I remap the tab key in insert mode to call this function.

This means that when I press tab in most cases it returns a tab, however, if I press tab after typing a . then I get the following...

enter image description here

In the above screenshot, this brings up the possible options from the fmt package. I can then use CRTL + N, O or P to navigate through the options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.