您可以使用:h :command
创建:S1
和:S2
命令。将这些命令键入功能并确保设置互相取消。例如...
command! S1 call Settings1()
command! S2 call Settings2()
fun! Settings1()
setlocal formatoptions=1
setlocal noexpandtab
silent! unmap <buffer> h
silent! unmap <buffer> l
nnoremap j gj
nnoremap k gk
endfun
fun! Settings2()
setlocal formatoptions=2
setlocal expandtab
silent! unmap <buffer> j
silent! unmap <buffer> k
nnoremap h gj
nnoremap l gk
endfun
如果你不想进行设置抵消,最简单的解决方案可能是重新启动VIM有不同的配置文件。您还可以使用set option!
切换选项,并使用mapclear
命令清除映射。但是,您必须针对无法切换的选项(如formatoptions
)进行特定设置。您可以使用set option&
将它们重置为默认值。
但是,您可以将所有选项重置为默认值:set all&
。例如,使用此功能,您可以拨打Settings1()
致电:set all&
和source $MYVIMRC
。然后Settings2()
也可以调用它们,然后设置各种选项。例如...
" tons of settings
command! S1 call Settings1()
command! S2 call Settings2()
fun! Settings1()
set all&
mapclear
source $MYVIMRC
endfun
fun! Settings2()
set all&
mapclear
setlocal formatoptions=2
setlocal expandtab
nnoremap h gj
nnoremap l gk
endfun
谢谢!有没有办法取消功能而不是个人设置?因为我的编码设置太多了,我不得不寻找每一个,并找出如何逐个取消它。 – alexchenco
我不知道没有重新启动vim的简单方法,但我更新了答案以反映这一点。 – Conner
非常感谢!我会试试这个。我想知道colorcheme会发生什么,我认为它不会改变? – alexchenco