VIM的一次遇坑记录(已经弄清楚已解决)

kikujiro 发布于 2022-05-17 1121 次阅读


MAC连接VMWARE虚拟机一直vim没有颜色,更换termius,iterm2,nuoshell,一直都没有颜色,查询网上的教程,一直修改的是~/.vimrc,后来了解到不是修改~/.vimrc,~/.vimrc没有也是可以的,(默认情况下(即以vim filename方式启动 vim),vim 8.2 会先尝试读取system vimrc file文件,如果有先加载系统配置文件,然后按以下顺序查找初始化选项,要注意的是,当 vim 找到其中一个就会停止查找)可以通过vim --version查看vim的各个配置文件的路径,我把~/.vimrc删除了就好了,这个属于自己折磨自己了。另外VIM只有部分文件能够高亮,比如.sh .py等

遇到的坑,CSDN什么的不可信,学习还是要从原理和系统上去着手,不能只想着解决目前的这一点点问题。

https://blog.csdn.net/alexanderron/article/details/121963737 (误导人)

正解:

https://blog.csdn.net/snowlyw/article/details/115388560

http://www.mybatis.cn/archives/1303.html

Short answer:https://stackoverflow.com/questions/10921441/where-is-my-vimrc-file


To create your vimrc, start up Vim and do one of the following:

:e $HOME/.vimrc  " on Unix, Mac or OS/2

:e $HOME/_vimrc  " on Windows

:e s:.vimrc      " on Amiga


Insert the settings you want, and save the file.

Note that exisitence of this file will disable the compatible option. See below for details.

Long answer:
There are two kinds of vimrc:

the user vimrc in $HOME
the system vimrc in $VIM (on Amiga systems, s:.vimrc is considered a user vimrc)
The user vimrc file often does not exist until created by the user. If you cannot find $HOME/.vimrc (or $HOME/_vimrc on Windows) then you can, and probably should, just create it.

The system vimrc should normally be left unmodified and is located in the $VIM* directory. The system vimrc is not a good place you keep your personal settings. If you modify this file your changes may be overwritten if you ever upgrade Vim. Also, changes here will affect other users on a multi-user system. In most cases, settings in the user vimrc will override settings in the system vimrc.

From :help vimrc:

A file that contains initialization commands is called a "vimrc" file. Each line in a vimrc file is executed as an Ex command line. It is sometimes also referred to as "exrc" file. They are the same type of file, but "exrc" is what Vi always used, "vimrc" is a Vim specific name. Also see |vimrc-intro|.

Places for your personal initializations:

Unix            $HOME/.vimrc or $HOME/.vim/vimrc
OS/2            $HOME/.vimrc, $HOME/vimfiles/vimrc
                or $VIM/.vimrc (or _vimrc)
MS-Windows      $HOME/_vimrc, $HOME/vimfiles/vimrc
                or $VIM/_vimrc
Amiga           s:.vimrc, home:.vimrc, home:vimfiles:vimrc
                or $VIM/.vimrc

The files are searched in the order specified above and only the first one that is found is read.

(MacOS counts as Unix for the above.)

Note that the mere existence of a user vimrc will change Vim's behavior by turning off the compatible option. From :help compatible-default:

When Vim starts, the 'compatible' option is on. This will be used when Vim starts its initializations. But as soon as a user vimrc file is found, or a vimrc file in the current directory, or the "VIMINIT" environment variable is set, it will be set to 'nocompatible'. This has the side effect of setting or resetting other options (see 'compatible'). But only the options that have not been set or reset will be changed.

  • $VIM may not be set in your shell, but is always set inside Vim. If you want to see what it's set to, start up Vim and use the command :echo $VIM
此作者没有提供个人介绍
最后更新于 2022-05-17