向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