简体   繁体   English

vim“语法开启”不起作用

[英]vim “syntax on” does not work

Here is my .vimrc 这是我的.vimrc

  1 syntax on
  2 set ts=4
  3 set number
  4 set smartindent
  5 set shiftwidth=4

However, I tried to edit HelloWorld.java and HelloWorld.c . 但是,我尝试编辑HelloWorld.javaHelloWorld.c Both have pure regular black font. 两者都有纯正的黑色字体。 No any highlighting! 没有任何突出显示!

I also tried :syntax on after the vim is open, but no luck. 我也尝试过:syntax on在vim打开后:syntax on打开,但没有运气。

\>vim -version
VIM - Vi IMproved 7.3 (2010 Aug 15)

\>cat /etc/*-release
openSUSE 11.4 (x86_64)
VERSION = 11.4
CODENAME = Celadon

When you edit the file, are you using 编辑文件时,您使用的是

vim filename

This can matter. 这很重要。 In some server configurations, if you do vi filename you get vim, but it's a very stripped down version of vim that is very much like the original vi. 在某些服务器配置中,如果你使用vi filename你会得到vim,但它是一个非常简化的vim版本,与原版vi非常相似。 If you instead type vim filename , you get the full featured vim. 如果您改为键入vim filename ,则会获得全功能的vim。

I just worked through this with a person who was on a server that had the vim-minimal package installed as well as another vim package. 我刚刚与一个安装了vim-minimal软件包的服务器以及另一个vim软件包的人一起完成了这项工作。 I suspect (but did not verify that) the vim-minimal package installed its executable as /bin/vi . 我怀疑(但没有验证) vim-minimal软件包将其可执行文件安装为/bin/vi

The difference was very clear when you looked at the actual files (ie ls -l /bin/vi vs ls -l /usr/bin/vim )--one was about ten times the size. 当你查看实际文件时(即ls -l /bin/vi vs ls -l /usr/bin/vim ),差异非常明显 - 一个是大小的十倍。 Both of them were actually vim, same version number and everything, but the /bin/vi one was compiled with very few features enabled. 它们实际上都是vim,相同的版本号和所有内容,但/ bin / vi编译时启用了很少的功能。

To make it even more confusing: 使它更令人困惑:

vi existing.pl

opened the .pl file, gave no syntax coloring 打开.pl文件,没有给出语法着色

vi [enter]

gave the vim splash screen, and from there 给了vim启动画面,并从那里

:e existing.pl

opened the file with syntax coloring on. 用语法着色打开文件。

You'll need to install the vim-data package on openSUSE for vim syntax colouring to work. 您需要在openSUSE上安装vim-data包才能使用vim语法着色。 Sounds strange, I know that this is not pulled in by default with the vim package but AFAIK it's for people who want to create tiny base installs. 听起来很奇怪,我知道默认情况下这不是vim包,而是AFAIK,它适用于想要创建微小基础安装的人。 Package vim-data contains the runtime files. 包vim-data包含运行时文件。

Also make sure your remote environment has an appropriate TERM variable set TERM=screen-256color, TERM=xterm, TERM=xterm-256color should all work just fine with ssh and ssh with screen/tmux. 还要确保你的远程环境有一个适当的TERM变量设置TERM = screen-256color,TERM = xterm,TERM = xterm-256color应该可以正常使用ssh和ssh与screen / tmux。

in your .vimrc , I don't see filetype setting. .vimrc ,我没有看到filetype设置。 you could try to add: 你可以尝试添加:

filetype plugin indent on 

to your vimrc. 到你的vimrc。

if you don't have set nocp , add this line too. 如果你没有set nocpset nocp添加这一行。

if you read :h filetype 如果您阅读:h filetype

:filetype on

Each time a new or existing file is edited, Vim will try to recognize the type
of the file and set the 'filetype' option.  This will trigger the FileType
event, which can be used to set the syntax highlighting, set options, etc.

For some strange reason on MacOS, 'syntax on' must be the first line in your .vimrc file. 对于MacOS上的一些奇怪的原因,'syntax on'必须是.vimrc文件中的第一行。 The line appears to be ignored if placed elsewhere in the file. 如果放在文件的其他位置,则该行似乎被忽略。

如果以上所有内容都已完成并且您看到一些下划线和粗体而不是实际颜色......这可能对您有用:

export TERM=xterm-color

One item not mentioned is :set syntax=<type> , eg :set syntax=markdown . 未提及的一项是:set syntax=<type> ,例如:set syntax=markdown

This has been successful in instances where other techniques above were not. 在上述其他技术不成功的情况下,这是成功的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM