向vim粘贴代码时,可能出现不断向右缩进的问题。
主要原因是想要粘贴进去的代码本身就已经有缩进,而vim又有设置自动缩进。这样就出现了不断向右缩进的问题。
下面是在往vim中粘贴xml配置信息时候出现的缩进问题展示(截取其中部分)
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>suse11_SP3_64_2U_raw</name>
<memory>2097152</memory>
<currentMemory>2097152</currentMemory>
<vcpu>2</vcpu>
<cpu mode='host-model'>
<topology sockets='1' cores='2' threads='1'/>
</cpu>
<os>
解决这个问题的办法有多种,下面简单介绍两种(都是在命令模式下输入)
(1):set noai nosi
取消了自动缩进和智能缩进,这样粘贴就不会错行了。但在有的vim中不行,还是排版错乱。
进入paste模式以后,可以在插入模式下粘贴内容,不会有任何变形。除此以外还可以设置很多其他的参数:
textwidth
wrapmargin
set noai
set nosi
softtabstop
revins
ruler
showmatch
formatoptions
通过:help paste可以看相关的帮助文档
使用方法(2)之后的格式正常了(仍然只是截取部分)
main type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>suse11_SP3_64_2U_raw</name>
<memory>2097152</memory>
<currentMemory>2097152</currentMemory>
<vcpu>2</vcpu>
<cpu mode='host-model'>
<topology sockets='1' cores='2' threads='1'/>
</cpu>
<os>
<type arch='x86_64'>hvm</type>
<boot dev='hd'/>
</os>
参考资料:
https://www.cnblogs.com/end/archive/2012/06/01/2531147.html
https://blog.csdn.net/victoryckl/article/details/8168245