Vim 不突出显示 bash 脚本的语法(msysgit 版本)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6449524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:14:28  来源:igfitidea点击:

Vim not highlighting syntax for bash scripts (msysgit version)

bashvimmsysgitvim-syntax-highlighting

提问by Adam Dymitruk

I'm using the bash and vim that come with msysgit. I've added the .vimrcfile to my home folder and most of the commands there are executing. But syntax onis not.

我正在使用 msysgit 附带的 bash 和 vim。我已将该.vimrc文件添加到我的主文件夹中,并且正在执行其中的大部分命令。但syntax on不是。

This is the contents of my ~/.vimrcfile:

这是我的~/.vimrc文件的内容:

set cul
hi CursorLine cterm=none ctermbg=darkgray ctermfg=white
syntax on

The current line and highlighting is now working, but the syntax onis failing. Msysgit installs it's own vim and in the C:\Program Files (x86)\Git\share\vim\vim73\syntaxfolder, it does not contain a bash.vim or sh.vim file. Other files are in there like conf.vim, gitcommit.vim and gitrebase.vim - even c.vim.

当前行和突出显示现在正在工作,但syntax on失败了。Msysgit 安装了它自己的 vim 并且在C:\Program Files (x86)\Git\share\vim\vim73\syntax文件夹中,它不包含 bash.vim 或 sh.vim 文件。其他文件在那里,如 conf.vim、gitcommit.vim 和 gitrebase.vim - 甚至 c.vim。

I'm guessing this is why there is no highlighting. Given that I can't touch that folder (don't ask), how can I change my .vimrc file to load up a bash.vim file - and what's a good place to get one?

我猜这就是为什么没有突出显示的原因。鉴于我无法触摸该文件夹(不要问),我如何更改我的 .vimrc 文件以加载 bash.vim 文件 - 什么是获取一个的好地方?

Any help is appreciated.

任何帮助表示赞赏。

采纳答案by quabug

  1. search and download sh.vimvia google or anything else you prefer to.
  2. move sh.vim to $HOME/vimfiles/syntax/directory, then when you open a shell script it'll take effect for that.
  1. sh.vim通过谷歌或您喜欢的任何其他方式搜索和下载。
  2. 将 sh.vim 移动到$HOME/vimfiles/syntax/目录,然后当你打开一个 shell 脚本时它就会生效。

http://vimdoc.sourceforge.net/htmldoc/usr_44.html#44.11

http://vimdoc.sourceforge.net/htmldoc/usr_44.html#44.11

回答by Celsius1414

Have you tried enabling the filetype plugin?

您是否尝试过启用文件类型插件?

:filetype plugin on

Then, if your script syntax still doesn't colorize properly, try manual override:

然后,如果您的脚本语法仍然无法正确着色,请尝试手动覆盖:

:set ft=sh

回答by JFlo

I'm not familiar with msysgit, but to answer your final question:

我不熟悉 msysgit,但要回答您的最后一个问题:

how can I change my .vimrc file to load up a bash.vim file

如何更改我的 .vimrc 文件以加载 bash.vim 文件

you should be able to add:

你应该能够添加:

if filereadable(expand("$HOME/some/path/bash.vim"))
    execute "source " . "$HOME/some/path/bash.vim"
endif

This might be useful if you have a reachable installed copy and don't wish to maintain your own copy.

如果您有一个可访问的已安装副本并且不想维护自己的副本,这可能会很有用。

回答by Forethinker

In my case deleting everything in ~/.vim/view helped. I had mkviewunder autocmd, so when I did not shut down vim and bash properly, I think some files got corrupted. I found this problem by moving the files that were giving me trouble in another directory and finding out that vim had no problem showing their syntax properly.

在我的情况下,删除 ~/.vim/view 中的所有内容有帮助。我有mkviewautocmd,所以当我没有正确关闭 vim 和 bash 时,我认为有些文件已损坏。我通过将给我带来麻烦的文件移动到另一个目录中发现了这个问题,并发现 vim 没有问题地正确显示它们的语法。