0

If I initiate vim from command line prompt, everything works as expected, but when it is initiated from a script, then syntax color highlighting is lost. The script can be as simple as the following,

 #!/bin/bash
 vi NR_NK.f

Please help me find out why this is the case, and how to possibly fix it.

  • 2
    that's vi not vim right? – Mass Dec 20 '17 at 21:27
  • 2
    Is vi an alias for vim? Aliases are not normally exported and will not be seen by scripts. Therefore, your script may be running the program vi in your PATH, which is often a minimal version of Vim without support for syntax highlighting. – garyjohn Dec 20 '17 at 22:00
  • 1
    Thank you guys, you solved my problem. Please reply my question so that I can choose your answer. – bsmile Dec 21 '17 at 5:49
0

As Mass pointed out, your script is running vi, not vim. That may be because you have vi as an alias for vim and are used to typing vi rather than vim on the command line. Aliases are not expanded by bash when the shell is not interactive, as when it is processing your script. Therefore, your script may be running the program vi in your PATH, which is often a minimal version of Vim without support for syntax highlighting.

  • Also if vim is invoked as vi it will set compatible and a bunch of other other options that disable "modern" features like syntax highlighting. – Martin Tournoij Dec 21 '17 at 18:11
  • I just tried that, creating a symlink from vim to vi and running that vi. Syntax coloring still worked. I think reverting to vi behavior depends on more that just the program name, but I can't find that in the help at the moment. – garyjohn Dec 21 '17 at 18:53

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.