Skip to content

Basic go to definition usage

Grzegorz Adam Hankiewicz edited this page Apr 29, 2019 · 1 revision

Once you have configured this plug-in following the steps above, create a file test.nim with the following contents:

import strutils

proc testMe() =
  echo "test".toLower

proc main() =
  testMe()
  test_me()

when isMainModule:
  main()

Put your cursor on the first testMe() call inside the main() proc, and while still in normal mode, type the default binding to jump to the definition of the testMe() proc, which is gd. If the plugin is correctly installed and nimsuggest is working, your cursor should jump to the sixth column of the third line, where the proc is defined. Type Ctrl+o to jump back, and repeat the same on the line below: since Nim syntax is style insensitive, the go to definition command will work the same on the test_me() call.

Now position your cursor on the toLower call at the end of the fourth line and repeat the go to definition command. Nimsuggest works across source files and into Nim's own standard library, so you should end up looking at the toLower*(s: string) proc, which at the moment of writing this is located on line 1546 of the lib/pure/unicode.nim file. You can even move your cursor a few lines below to the convertRune(s, toLower) and nimsuggest will keep working. Type Ctrl+o (several times, if needed) to jump back to your source file.

If you are working on a file, chances are it will be dirty and not saved to disk. In these situations, the go to definition command only works for your own source. If you start any modification of the test file and try to go to the definition of toLower, you will be greeted with the error:

E37: No write since last change (add ! to override)

This is because Neovim does not want to lose your changes switching the current buffer. This can be avoided in two ways:

  • Save the file beforehand.
  • Use the alternative gD mapping which will split the current window and go to the definition in the new window. Typing Ctrl+o now would bring you back to your buffer and keep the split window, so you might as well close the window directly typing :q.
Clone this wiki locally