简体   繁体   English

带有空的.vimrc退格的Vim怪异行为

[英]Vim weird behaviour with backspace with empty .vimrc

I'm having a weird issue with vim on Ubuntu. 我在Ubuntu上遇到了一个奇怪的问题。 I've been using it for the last few weeks, trying to learn, on Windows and it behaves differently now that I'm using it on Linux. 过去几周我一直在使用它,尝试在Windows上学习,现在我在Linux上使用它时表现不同。

I noticed that while in insert mode pressing backspace will delete text just like any other editor on Windows, but on Linux the text is "deleted" yet it stays there until I press ESC or write over it. 我注意到在插入模式下按下退格键将删除文本,就像在Windows上的任何其他编辑器一样,但在Linux上文本被“删除”但它保持在那里直到我按下ESC或写入它。

I was trying to fix this but I'm confused as to whether this is intended behaviour or not. 我试图解决这个问题,但我对这是否是预期的行为感到困惑。 It happens in gvim too. 它也发生在gvim中。

The reason of this question is this, however: 然而,这个问题的原因是这样的:

I deleted my .vimrc file to see if any of my config was at fault and it fixed it. 我删除了我的.vimrc文件,看看我的配置是否有任何错误并修复了它。 Backspace was now back to its regular self. Backspace现在又恢复了常规。

But then I tried creating an empty .vimrc file and that made it go back to the delayed delete. 但后来我尝试创建一个空的.vimrc文件,并使其返回到延迟删除。 It's empty. 它是空的。 Why the hell? 为什么地狱?

So I have no idea what's causing this. 所以我不知道造成这种情况的原因。 Hope my question makes sense my English ain't the best. 希望我的问题有道理我的英语不是最好的。 Thanks. 谢谢。


Alright so looking at :h compatible I found this: 好吧所以看:h兼容我发现了这个:

"When a |vimrc| or |gvimrc| file is found while Vim is starting up, this option is switched off, and all options that have not been modified will be set to the Vim defaults. Effectively, this means that when a |vimrc| or |gvimrc| file exists, Vim will use the Vim defaults, otherwise it will use the Vi defaults. (Note: This doesn't happen for the system-wide vimrc or gvimrc file, nor for a file given with the |-u| argument). Also see |compatible-default| and |posix-compliance|." “当Vim启动时找到| vimrc |或| gvimrc |文件时,此选项将关闭,所有未修改的选项将被设置为Vim默认值。实际上,这意味着当| vimrc |或| gvimrc |文件存在,Vim将使用Vim默认值,否则它将使用Vi默认值。(注意:系统范围的vimrc或gvimrc文件不会发生这种情况,也不会发生| | u |参数)。另见| compatible-default |和| posix-compliance |。“

So if I'm getting this right, running Vim with a .vimrc file should automatically set nocompatible and running it without one should set compatible... ? 所以如果我做对了,用.vimrc文件运行Vim会自动设置nocompatible并运行它,而不应该设置兼容...? Whatever the case, I tried checking with :verbose set compatible? 无论如何,我尝试检查:verbose set compatible? and it always says nocompatible is on so the -N flag shouldn't do anything... Yet it fixes the issue. 并且它总是说nocompatible是在,所以-N标志不应该做任何事情......但它解决了这个问题。

Without a vimrc Vim will load /usr/share/vim/vim80/defaults.vim (depending on your vim version). 如果没有vimrc,Vim将加载/usr/share/vim/vim80/defaults.vim (取决于你的vim版本)。 In this file the bs / backspace parameter is set to 2 , or actually it is indent,eol,start which is the same as 2 (see :h bs ) 在这个文件中, bs / backspace参数设置为2 ,或实际上它是indent,eol,start2相同(参见:h bs

Now if you create an empty .vimrc , defaults.vim will not be loaded, so your bs will possibly be 0. 现在,如果您创建一个空的.vimrc ,则不会加载defaults.vim ,因此您的bs可能为0。

This behaviour is described in :h defaults.vim 此行为在:h defaults.vim内容中描述:h defaults.vim

So to solve your problem, just put set bs=2 in your .vimrc 因此,要解决您的问题,只需在.vimrc set bs=2

Alright I fixed it. 好吧我修好了。

Running vim with the -N command makes it work properly. 使用-N命令运行vim使其正常工作。 I'm not sure why but that's what's happening. 我不知道为什么,但那就是发生了什么。

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

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