2009-06-26 82 views
4

自动突出显示我已经在我的.vimrc以下无法设置语法Vim的

syntax on 
filetype plugin indent on  # Thanks to Jeremy 

我跑

vim ~/.vimrc 

我得到正确的语法高亮。

我源的.vimrc我的许多文件。我的vimrc是像一个路线图,我在哪里,我的

CTRL-W f 

导航时出现问题,当我浏览到我已经源文件:没有颜色

我所有的源文件都包含在其路径字的Vim。 在解决问题时可能会使用这个事实。

你怎么能提供一个语法的源文件自动突出?

回答

11

不要在“vim的”问题结尾的文件?否则,vim的文件类型检测可能无法确定这些文件是否包含vim-script。您可以重命名文件,以便以.vim结尾,或者添加自动命令以适当地设置文件类型。

要做到后者,你可以添加这样的事情给你的.vimrc:

au! BufNewFile,BufRead PATTERN set filetype=vim 

与将有问题的文件匹配文件模式取代“模式”。

编辑:

的模式是如何工作的,请参阅: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). 

特别要注意这个例子:

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. 

你的情况,你可能想是这样的:

au! BufNewFile,BufRead */Vim/* set filetype=vim 
+0

上的文件类型插件缩进我将PATTERN设置为* Vim *失败。看起来该命令只考虑文件名。 - 这表明最简单的方法就是将扩展vim添加到每个文件。 – 2009-06-26 22:30:17

0

一个明显的问题是没有线你采购的文件说:“语法关”?

+0

没有行说“语法关闭”。 – 2009-06-26 22:19:22

1

什么是你源文件的扩展名?扩展名是Vim常用的方法,用于检测它使用哪种语法高亮显示,对于源文件(vimscript),它应该是.vim。听起来好像不是这样,如果你只看到源文件的问题,而没有看到任何其他问题。

+0

这些文件没有扩展名。 – 2009-06-26 22:18:47

0

这可能是:

  • 的“文件类型”选项
  • 文件类型可能不被VIM自动检测

filetype on排序的第一,第二是可以解决的与自动命令基于文件扩展名。

+0

我在.vimrc中有以下内容: – 2009-06-26 22:17:05

3

,要想让vi考虑我的jQuery(.jq)文件实际上是JavaScript的(的.js)我所做的: -

创建和/或或编辑你的vimrc文件...

[email protected]:~$ vi ~/.vimrc 

添加下面的文本(按我插入)...

if has("syntax") 
    syntax on 
    filetype on 
    au BufNewFile,BufRead *.jq set filetype=javascript 
endif 

保存vimrc文件...

[esc]:wq[enter] 

此外,找到支持的文件类型看在...的filetype.vim

[email protected]:~$ sudo locate filetype.vim 
/usr/share/vim/vim72/filetype.vim 
[email protected]:~$ sudo grep "\.js[, ]" `locate filetype.vim` 
au BufNewFile,BufRead *.js,*.javascript,*.es,*.jsx  setf javascript 

...文件类型是SETF参数...

[email protected]:~$ sudo grep "\.js[, ]" `locate filetype.vim` | cut -d " " -f 4 
javascript 

玩得开心。