1

I'm trying to do something relatively simple: Editing a file in src and pointing Vim to the header file located in include. My .vimrc file has set modeline on, and the first line in my file is: // vim: set path += ../include (I've also tried include, include;, and several other variations). When I look at the path variable:

echo &path gives me .,/usr/include,,; the path doesn't change regardless of what I put in the modeline.

echo path gives me nothing.

What am I doing incorrectly here?

4
  • 1
    That doesnt look like proper modeline or set syntax. Have you checked :help modeline?
    – D. Ben Knoble
    Mar 31, 2020 at 2:17
  • @D.BenKnoble I have, yes. There were also a couple of tutorials that used this syntax. I've tried different modeline syntaxes, altered spacing, etc. to no avail. What about is improper set syntax? Mar 31, 2020 at 3:39
  • 2
    You need to get rid of the whitespace in the modeline option value. Also the modeline needs a trailing :. This should work from my limited testing: // vim: set path+=../include: You can always check the result (after loading the file) using :verbose set path? Mar 31, 2020 at 6:34
  • @ChristianBrabandt Ah, I missed the trailing colon. Thank you. :) If you include your comment in an answer, I'll accept it. Mar 31, 2020 at 16:07

1 Answer 1

1

There are basically, two forms of modelines. Let me copy in the most important parts here together with an example:

 There are two forms of modelines.  The first form:
   [text{white}]{vi:vim:ex:}[white]{options}
 [...]
 Examples:
   vi:noai:sw=3 ts=6
 [...]
 The second form (this is compatible with some versions of Vi):
   [text{white}]{vi:vim:|Vim:ex:}[white]se[t] {options}:[text]
 [...]
 Examples:
   /* vim: set ai tw=75: */

Since you have been using the :set command, this means you are trying to create the latter form. There are two things to note here: First, you cannot use whitespace in the option value, otherwise Vim will parse those as separate options. The second is, you need to add a trailing : to indicate where the modeline ends.

This means, in your case, the complete line with the modeline should look like this:

// vim: set path+=../include:

Here is a simple tip, I use when creating a modeline. After reloading the file (:e), you can check the value of the options from the modeline by using :verbose set path?. Vim will output something like:

  path=.,,,../include
  Last set from modeline line 8

Your Answer

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

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