2

All,

I am pretty new to NeoVim or Vim and i have setup vim for scala development. Everything else seems to be working fine. The only hiccup i have is i am not able to navigate to a file or function.

Is there a plugin for vim or neovim that i can use to make the navigation simpler.

ps: I have tried ctags and dont see that as a very user friendly and convenient option to go with.

2

Language support in modern Vim/NeoVim typically involves using an LSP server that is able to parse/interpret/compile your code base and provide your editor with access to semantic elements such as functions, classes, variables, types, etc.

For Scala, you might want to look into Metals, which is an LSP implementation for Scala. (There are other implementations of LSPs for Scala, you might consider researching and comparing them to choose the one that suits you best.)

Metals has comprehensive documentation, including a guide to set up Vim/NeoVim support for it.

Here you'll find again you have implementation choices between LSP clients for Vim/NeoVim. The Metals docs suggests two options, one is based on the native LSP client shipped with NeoVim (this is a NeoVim only option) or using coc.nvim (Conqueror of Completion), which works on both Vim and NeoVim (even though the plug-in uses ".nvim" in its name.) Adopting coc.nvim is not a bad idea, even if you're in NeoVim, it will give you many features typically found in modern IDEs such as VSCode, and should provide you with a very featureful experience out of the box.

Setting up all these components and their dependencies might be a bit tricky! Metals depends on a Java runtime (which you probably already have around and properly set up if you're doing Scala.) coc.nvim requires a working Node.js installation.

You also need to hook up all these components to each other, which typically works well during setup (many of these have been designed to work together), but it might be a headache to debug if you actually run into trouble with some part of it not working as expected... The documentation for both projects I mentioned is pretty comprehensive and complete, follow the guides and they'll hopefully lead you to a working setup. Your main interface will be through coc.nvim, so check out its documentation for actions related to navigation, such as "go to definition" which should take you to a function by its name.

1
2

i [sic] am not able to navigate to a file or function

Vim comes with many ways to do this. So many, I nearly closed this as too broad. (Plugin requests are also off-topic…)

A quick smattering of things to read about, none of which is going to give you the IDE-like experience of an LSP. They are however all built-in and often sufficient, if you adapt your workflow.

  • :help path and the related topics (gf, :find, etc.)
  • :help include and related commands ([i, :isearch)
  • :help define and related commands (esp. :help include-search)
  • :help gd and related commands
  • :help Explore and related commands
  • :help usr_22 has a good introduction

You mentioned tags. Universal Ctags, the most modern implementation, is very user-friendly, especially when paired with a scala tag definition, such as mine, automatic updates based on tpope's original scripts (you'll want to also look at the specific hook files in that directory), and the :help tags-and-searches interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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