且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将文本粘贴到Vim时关闭自动缩进

更新时间:2022-06-24 22:30:54

更新:此处更好的答案: https://***.com/a/38258720/62202

在粘贴代码时关闭自动缩进,有一种特殊的粘贴模式。

To turn off autoindent when you paste code, there's a special "paste" mode.

类型

:set paste

然后粘贴您的代码。请注意,工具提示中的文本现在显示为-插入(粘贴)-

Then paste your code. Note that the text in the tooltip now says -- INSERT (paste) --.

粘贴后代码,请关闭粘贴模式,以便再次键入时自动缩进。

After you pasted your code, turn off the paste-mode, so that auto-indenting when you type works correctly again.

:set nopaste

但是,我总是觉得很麻烦。这就是为什么我要映射< F3> 以便它可以在编辑文本的同时在粘贴和nopaste模式之间切换的情况。我将其添加到 .vimrc

However, I always found that cumbersome. That's why I map <F3> such that it can switch between paste and nopaste modes while editing the text! I add this to .vimrc

set pastetoggle=<F3>