1

I use this simple approach to jump to definitions in C++, which works fine for me.

In my vimrc:

autocmd BufRead,BufNewFile *.c,*.cpp,*.cc set path+=/Library/Developer/CommandLineTools/usr/include/c++/v1

Is there a similar solution for Python? or for any language I could be using in the future?

Is this approach sensible? I'm trying to configure a minimal IDE... without loads of pluggins

2
  • 1
    Not really; Vim has somewhat decent-ish IDE-like functionality built-in for C because that's what everyone was using in the 90s, but even there it's a bit so-so and it really breaks down with other languages. For a general "works for most languages"-type solution LSP is more or less the only way to go. I use vim-lsc, which is a fairly simple to setup LSP plugin (without loads of dependencies and whatnot), although you do also need to setup the LSP (clangd, pylsp, gopls, etc.) Commented Jun 24, 2023 at 13:43
  • Another solution is to use ctags; there are generators for many different languages. But I never really had much success with that myself. Commented Jun 24, 2023 at 13:44

1 Answer 1

1

The general idea definitely works with other languages but, simply by using C/C++, you benefit from lots of defaults being set for C: :help 'include', :help 'define', etc. even :help 'path' itself. For other languages, you may need to set those yourself, which may or may not be an acceptable waste of your time. Moreover the differences in language design can make things way too complicated. PHP, for example, is insanely difficult to do right.

define and include are already set for Python by the built-in ftplugin, so all you need is to make sure that path covers your (implied) needs.

Note that doing this with the :help FileType event would make more sense:

autocmd FileType c,cpp setlocal path+=whatever

and doing it in a ftplugin would be even better:

" in after/ftplugin/c.vim
setlocal path+=/whatever

" in after/ftplugin/cpp.vim
setlocal path+=/whatever

" in after/ftplugin/python.vim
setlocal path+=/whatever

That said… if you need an IDE, get an IDE.

2
  • thx @romainl you gave me some ideas to try out... I use IDEs but I want to go full vim, because I can't help it: i love vim haha. I take this opportunity to thank you for all your answers to my previous questions!
    – ranemirusG
    Commented Jun 24, 2023 at 18:39
  • I love lasagna but I don't eat lasagna every day.
    – romainl
    Commented Jun 25, 2023 at 5:32

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.