当我复制并通过Vim中的一段代码时,每一行都缩进一个。例如,我有此来源:
print "Hello"
print "World"
print "I'm copying"
print "and pasting"
粘贴到Vim时会变得困惑:
print "Hello"
print "World"
print "I'm copying"
print "and pasting"
对于复制较长的代码行,这非常令人沮丧,因为所有内容都无法对齐(不适用于python)。
这是我的vimrc。它当前在换行符上自动缩进,并用标准的4个空格替换制表符。
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab
虽然此配置有效,但某些原因导致了复制粘贴问题。如何解决此问题,但仍保留我定义的行为?
最佳答案
使用:set paste
切换到粘贴模式。
This article explains paste mode
它专门用于将文本粘贴到vim中,因此不会触发任何输入映射。完成操作后,请记住使用:set nopaste
来取回映射。
关于Vim在复制粘贴时缩进每一行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41105157/