Skip to content

Commit

Permalink
added a new global variable g:XkbSwitchIminsertToggleKey (see docs)
Browse files Browse the repository at this point in the history
this is related to #54
  • Loading branch information
lyokha committed Apr 6, 2022
1 parent d6c9b8e commit 4f940a9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,23 @@ and map g:XkbSwitchKeymapNames to keymap names instead of values of
b:keymap_name. For example

```vim
let g:XkbSwitchKeymapNames = {'ru' : 'russian-jcukenwin',
\ 'uk' : 'ukrainian-jcuken'}
let g:XkbSwitchKeymapNames =
\ {'ru' : 'russian-jcukenwin', 'uk' : 'ukrainian-jcuken'}
```

Now keymap will automatically switch to the last keyboard layout when you
leave Insert mode.

To reset commands *r* and *f* to the usual Normal mode keyboard layout simply
switch to it in Insert mode or enter command
To toggle keymap layout in Normal mode for using in commands *r* and *f*, you
may need to set a dedicated key:

```vim
:setlocal iminsert=0
let g:XkbSwitchIminsertToggleKey = '<C-^>'
```

To reset search lines press *Ctrl-^*.
Notice that toggling keymap layout when typing a pattern for a search command
can be done with the builtin key *Ctrl-^*.

There is only one problem not solved so far: the system keyboard layout
indicator when in Normal mode and search lines will show the usual Normal mode
Expand Down
13 changes: 7 additions & 6 deletions doc/xkbswitch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,19 @@ define a new variable
and map g:XkbSwitchKeymapNames to keymap names instead of values of
b:keymap_name. For example
>
let g:XkbSwitchKeymapNames = {'ru' : 'russian-jcukenwin',
\ 'uk' : 'ukrainian-jcuken'}
let g:XkbSwitchKeymapNames =
\ {'ru' : 'russian-jcukenwin', 'uk' : 'ukrainian-jcuken'}
<
Now keymap will automatically switch to the last keyboard layout when you
leave Insert mode.

To reset commands |r| and |f| to the usual Normal mode keyboard layout simply
switch to it in Insert mode or enter command
To toggle keymap layout in Normal mode for using in commands |r| and |f|, you
may need to set a dedicated key:
>
:setlocal iminsert=0
let g:XkbSwitchIminsertToggleKey = '<C-^>'
<
To reset search lines press |c_Ctrl-^|.
Notice that toggling keymap layout when typing a pattern for a search command
can be done with the builtin key |c_Ctrl-^|.

There is only one problem not solved so far: the system keyboard layout
indicator when in Normal mode and search lines will show the usual Normal mode
Expand Down
14 changes: 14 additions & 0 deletions plugin/xkbswitch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ if !exists('g:XkbSwitchDynamicKeymap')
let g:XkbSwitchDynamicKeymap = 0
endif

if !exists('g:XkbSwitchIminsertToggleKey')
let g:XkbSwitchIminsertToggleKey = ''
endif

if !exists('g:XkbSwitchSkipFt')
let g:XkbSwitchSkipFt = ['tagbar', 'gundo', 'nerdtree', 'fuf']
endif
Expand Down Expand Up @@ -353,6 +357,16 @@ fun! <SID>xkb_mappings_load()
\ " :call <SID>xkb_switch(1, 1)<CR>".cmd
endfor
endif
if !empty(g:XkbSwitchIminsertToggleKey)
exe "nnoremap <buffer> <silent> ".g:XkbSwitchIminsertToggleKey.
\ " :if !empty(&keymap) <Bar> if &iminsert == 0 <Bar>".
\ "setlocal iminsert=1 <Bar>".
\ "echo 'set keymap' &keymap <Bar>".
\ "elseif &iminsert == 1 <Bar>".
\ "setlocal iminsert=0 <Bar>".
\ "echo 'unset keymap' &keymap <Bar>".
\ "endif <Bar> endif<CR>"
endif
let b:xkb_mappings_loaded = 1
endfun

Expand Down

0 comments on commit 4f940a9

Please sign in to comment.