Switch between two .virmc options with?

Is there a way to switch between the two settings .vimrcusing the command?

Let's say in my 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

And I want to be able to change settings 1 and 2, for example, by typing :S1or:S2

The reason for this is that I want to have the settings that I use when encoding , and the other when recording .

What is the best way to accomplish this?

+3
source share
1 answer

You can create teams :S1and :S2using :h :command. Enter these commands in the function and make sure that the settings cancel each other. For instance...

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, . reset set option&.

reset :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
+6

All Articles