将文本粘贴到Vim时关闭自动缩进 [英] Turning off auto indent when pasting text into vim
问题描述
我正在努力学习Vim。
I am making the effort to learn Vim.
当我从剪贴板将代码粘贴到文档中时,每一行的开头都有多余的空格:
When I paste code into my document from the clipboard, I get extra spaces at the start of each new line:
line
line
line
我知道您可以关闭自动缩进,但由于其他设置有冲突或其他原因(在我的.vimrc中看起来很明显,当我将它们取出时似乎并不重要)。
I know you can turn off auto indent but I can't get it to work because I have some other settings conflicting or something (which look pretty obvious in my .vimrc but don't seem to matter when I take them out).
如何在粘贴代码时关闭自动缩进功能,但是在编写代码时仍然具有vim自动缩进功能?这是我的 .vimrc
文件:
How do I turn off auto indenting when I paste code but still have vim auto indent when I am writing code? Here is my .vimrc
file:
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent
set bg=dark
set nowrap
推荐答案
更新:此处更好的答案: https://stackoverflow.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>
这篇关于将文本粘贴到Vim时关闭自动缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!