Vim 使用命令在两个.virmc设置之间切换?

Vim 使用命令在两个.virmc设置之间切换?,vim,Vim,有没有办法用命令在两个.vimrc设置之间切换 假设我的vimrc: * Settings 1 setlocal formatoptions=1 setlocal noexpandtab map j gj map k gk * Settings 2 setlocal formatoptions=2 map h gj map l gk 我希望能够在设置1和设置2之间进行更改,比如键入:S1或:S2 原因是我想在编码时使用设置,在写作时使用另一组设置。

有没有办法用命令在两个
.vimrc
设置之间切换

假设我的
vimrc:

  * Settings 1
  setlocal formatoptions=1 
  setlocal noexpandtab 
  map j gj 
  map k gk

  * Settings 2
  setlocal formatoptions=2
  map h gj 
  map l gk
我希望能够在设置1和设置2之间进行更改,比如键入
:S1
:S2

原因是我想在编码时使用设置,在写作时使用另一组设置。


实现这一点的最佳方法是什么?

您可以使用
: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的简单方法,但我更新了答案以反映这一点。非常感谢!我来试试这个。我想知道colorscheme会发生什么,我认为它不会改变?它不应该改变,因为
colorscheme
不是
的“选项”
" 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