Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The only thing I've really struggled with when trying to get into using vim full-time is navigating my project. In VSCode I basically hit CTRL+SHIT+F -> "portion_of_a_function_name_or_something" constantly. I abuse the heck out of global search. Is there a way of navigating your project in vim that's similar/easier?

How do vim people quickly navigate their code without going "what was the name of that file with that function"?



Historically, people used :grep and the quicklist to jump between project files based on abitrary strings and Ctags to generate a language specific index of functions, variables which you can jump to.

These days people generally use some kind of fuzzy finder plugin thats basically the same as the vscode experience. Exactly which one you use depends on various factors, but Telescope and Fzf are two big names and both allow searching through a bunch of other stuff, setting names, edit history etc. (You can also save the fuzzy search results to the quicklist so you've basically got a reusable index).

And neovim is heavily embracing the LSP paradigm, where you'd use something like gd to jump to definition when on top of a function and a language specific LSP server will tell Neovim where to jump to.


> And neovim is heavily embracing the LSP paradigm, where you'd use something like gd to jump to definition when on top of a function and a language specific LSP server will tell Neovim where to jump to.

This x100. I switched to neovim+pylsp a few months ago, and it's been an absolute delight. I use lspconfig [1] and pyslp [2] since most of my time is spent developing Python code. Not only can I navigate more quickly and easily, I also find myself catching more silly errors before run-time due to better linting from the lsp.

It used to be that I wouldn't use vim beyond quick edits on single files. Although I still prefer to use vim style bindings in IDEs, I can go much further before I feel the need to fire up an IDE in the first place.

[1]: https://github.com/neovim/nvim-lspconfig

[2]: https://github.com/python-lsp/python-lsp-server


Vim supports ctags[0] lookup out of the box which fits your need somewhat.

I tend to use FZF[1] which has functions for leveraging ripgrep and silver surfer for searches. It can also use find. FZF also has dialogues for paring down results in real time (i.e., as you type)

There are also plugins that are much more nuanced and more involved for searching symbols and providing autocomplete. Duoplete, vimcomplete, youcompleteme spring to mind.

[0]: https://ctags.io/

[1]: https://github.com/junegunn/fzf.vim


+1 As a fellow global search fan, FZF + the silver searcher is the way to go. You just type `:Ag <your string>` and you're done.


Yup. FZF is where it's at. :Files to jump to a file, :Rg to search around for some content.

I also keep vinegar around for when I want to poke around at the contents of a directory.


Yep that’s what I do too. ctags are fast and low overhead to generate.

The other alternative is to set up a Language Server (LSP) for navigation and you can use the same ones as VSCode uses.


I use neovim now and have switched my search over to using Telescope.nvim which is a fuzzy search basically.

It lets you do pretty much what you say allowing me to type <leader>-f and partially type things to remember where I am with a preview pane. Seems moderately fast most of the time for the monolith I work on.


The only catch with this is that it's neo vim only. It works incredibly well and can fuzzy find lots of things not just files.


Vim has the concept of <cword> and <cWord> (you can :h <cword> these for more info), which are basically the things that vim will jump across when you press 'w' or 'W'.

You can combine this with grep and the location list to find symbol usage across multiple files.

    nnoremap <leader>g :grep <cword><CR>
You can then use :cnext and :cprev (or focusing the window and selecting an entry) to navigate between them.

As others have stated, you can also use ctags (plugins like https://github.com/ludovicchabant/vim-gutentags are useful for refreshing tags in a project), but for some languages you may need to add a tag definition (e.g. for something like rust or zig). For older languages like C you should be fine.


Worth noting that :grep can be configued to use ag, rg, ack or git grep which can add some modern conviences like respecting prohect specific ignore lists and there are plugins that build more on top for each specific tool.


‘:!ctags -R’ and ‘:ta function’ (or ‘^]’ for the identifier under the cursor). Works well enough for me, even in Real Vi (TM).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: