I use macvim with YouCompleteMe (YCM), which I recently updated and recompiled. I followed the YCM instructions for OSX. I'm also using iterm2, tmux and zsh, all of which are installed with brew and updated.

YCM autocompletion of variable names and shell functions that are defined in the shell script itself work as intended.

However, with my current setup, YCM will not autocomplete variable names and shell functions from files sourced with source in this shell script.

I have verified that files were sourced correctly, because the script functions properly.

All files sourced are in the same directory as the sourcing script, and are sourced with relative pathnames with slashes. One file, init.sh, has no #! and contains only variables. The second, functions.sh has a #! (which isn't really necessary for my use case) and function definitions. No variables are used in specifying the sourced files. So:

source "./init.sh"
source "./functions.sh"

I've made sure to source ~/.vimrc and restart the YCM server after any changes, and verify that YCM logs in my vim session contain no errors, after any change to my files.

How can I get YCM to autocomplete these items?

  • Welcome to Vi and Vim!
    – filbranden
    Commented Aug 26, 2020 at 17:42
  • 1
    Thanks @filbranden! Update: I got some very helpful suggestions from the YCM folks: using the YCM bash language server github.com/ycm-core/lsp-examples (which didn't work), and using ctags and this: github.com/ycm-core/… . I'm currently working on the second idea, but I don't fully understand tags yet.
    – Life5ign
    Commented Aug 26, 2020 at 21:59
  • I'm not a user of YCM myself so I can't give you many pointers about that... Regarding tags, you install a ctags program and use ctags -R . at the top level of your project, it will find all source files in it and create a pretty large file named tags that serves as index to where things are defined. Note that Vim has native support for tag files, for example you can use <C-]> (Ctrl + ] -- the close bracket) to jump to definition of the term under the cursor.
    – filbranden
    Commented Aug 26, 2020 at 22:08
  • One downside of using tags is that you need to keep the tags file up to date, but there are plug-ins that can help with that. I have used vim-gutentags in the past for this purpose and I've been happy with the way it works. There are others too, make your research...
    – filbranden
    Commented Aug 26, 2020 at 22:08
  • 1
    Great, thanks @filbranden, that's really helpful info about how tags work. I will edit the question to be YCM-centric, since that's kind of how I originally phrased it (although I didn't even know about the existence of tags when I wrote it). That being said, it seems that tags will likely need to be involved, whether used with YCM, or on their own with a ctags program and vim plugin like you mentioned. I look forward to asking more questions, I'm pretty set on making vim into my IDE. thanks again!
    – Life5ign
    Commented Aug 27, 2020 at 0:23


Your Answer

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