如何默认启用go.vim(自动)?

huangapple go评论91阅读模式
英文:

How to enable go.vim by default (automatically)?

问题

Vim网站上的说明说只需将文件放在/syntax文件夹中。这样做效果还不错。但是,为了使用语法,我必须设置以下内容:

:set syntax=go

每次都要这样设置。所以,我知道我做错了什么。我只是不知道是什么。

以下是我从查找中找到的一些信息,

我的HTML5语法设置来自Rodrigo的HTML5 omnicomplete function and syntax vimball file。尽管这使用了一些安装脚本来启动它。

据我所知,这将是我第一次手动添加语法文件。

此外,我的VIMRUNTIME没有设置,因为没有syntax.vim文件,所以从阅读文档中我看到它通过synload.vim检查文件。

我甚至阅读了“制作自己的语法文件”部分,其中说的和上面的syntax=go选项一样。我应该像new filetype section中描述的那样检测.go文件类型吗?

如何默认启用GO的语法高亮?

这是针对Mac Snow Leopard的。

<sub>我不认为这么复杂,但我决定留下我浏览过的所有不同的文档。GO和Vim都说只需添加文件。但它绝对没有自动检测到它。</sub>

英文:

The instructions on the Vim site says to just put the file in the /syntax folder. This works all right and well. But, for me to use the syntax I must set the following

:set syntax=go

Every single time. So, I know I am doing something wrong. I just don't know what.

Here are some things from looking around,

My HTML5 syntax set is from Rodrigo's HTML5 omnicomplete function and syntax vimball file. Though this uses some installation script to get it going.

As far as I can tell this would be my first manual adding of syntax file.

Also, my VIMRUNTIME is not set, well because there is no syntax.vim file, so from reading the documentation I see it checks for files via synload.vim

I even read the "Making Your Own Syntax Files" section, which says that same as above with the syntax=go option. Am I supposed to be detecting the .go filetype as described in new filetype section?

How can I enable syntax highlighting for GO by default?

This is for Mac Snow Leopard.

<sub>I don't think it is this complicated but I decided to leave all the different documentation I skimmed. GO and Vim say to just add the file. But it is definitely not detecting it automatically </sub>

答案1

得分: 7

如果您在~/.vimrc文件中使用文件类型检测,并且有以下行:

filetype plugin indent on

那么您可以将文件放在以下文件夹中:

~/.vim/after/ftplugin/go.vim

或者对于Windows系统:

~/vimfiles/...

为了使文件类型检测起作用,您需要在ftdetect文件夹中的文件中添加autocmd:

~/.vim/ftdetect/go.vim

文件内容如下:

autocmd BufNewFile,BufReadPost *.go set filetype=go
英文:

If you are using filetype detection in your ~/.vimrc file with the following line:

filetype plugin indent on

then you can place the file in the following folder:

~/.vim/after/ftplugin/go.vim

or for windows

~/vimfiles/...

For the filetype detection to work, would would want the autocmd in a file in the ftdetect folder:

~/.vim/ftdetect/go.vim

and the contents would be:

autocmd BufNewFile,BufReadPost *.go set filetype=go

答案2

得分: 2

使用autocmd命令:
au BufRead,BufNewFile *.go setlocal filetype=go

英文:

Use autocmd:
au BufRead,BufNewFile *.go setlocal filetype=go

huangapple
  • 本文由 发表于 2011年10月2日 05:49:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/7623184.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定