我的.vimrc中有以下内容
syntax on
filetype plugin indent on # Thanks to Jeremy
Run Code Online (Sandbox Code Playgroud)
我跑
vim ~/.vimrc
Run Code Online (Sandbox Code Playgroud)
我得到了正确的语法突出显示.
我在.vimrc中获取了很多文件.我的.vimrc就像是一个路线图,我在那里导航
CTRL-W f
Run Code Online (Sandbox Code Playgroud)
当我导航到我已找到的文件时出现问题:没有颜色.
我的所有源文件在其PATH中都包含单词Vim.有可能在解决问题时使用这一事实.
如何为源文件自动提供语法高亮显示?
Lau*_*ves 11
有问题的文件是否以".vim"结尾?如果没有,那么vim的文件类型检测可能无法确定这些文件包含vim-script.您可以重命名文件以使它们以.vim结尾,也可以添加自动命令以适当地设置文件类型.
要执行后者,您可以将以下内容添加到.vimrc中:
au! BufNewFile,BufRead PATTERN set filetype=vim
Run Code Online (Sandbox Code Playgroud)
将"PATTERN"替换为与所讨论文件匹配的文件模式.
编辑:
了解:help autocmd-patterns模式的工作原理:
The file pattern {pat} is tested for a match against the file name in one of
two ways:
1. When there is no '/' in the pattern, Vim checks for a match against only
the tail part of the file name (without its leading directory path).
2. When there is a '/' in the pattern, Vim checks for a match against the
both short file name (as you typed it) and the full file name (after
expanding it to a full path and resolving symbolic links).
Run Code Online (Sandbox Code Playgroud)
特别要注意这个例子:
Note: To match part of a path, but not from the root directory, use a '*' as
the first character. Example: >
:autocmd BufRead */doc/*.txt set tw=78
This autocommand will for example be executed for "/tmp/doc/xx.txt" and
"/usr/home/piet/doc/yy.txt". The number of directories does not matter here.
Run Code Online (Sandbox Code Playgroud)
在你的情况下,你可能想要这样的东西:
au! BufNewFile,BufRead */Vim/* set filetype=vim
Run Code Online (Sandbox Code Playgroud)