Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch layout when in normal mode #54

Closed
coordinatio opened this issue Mar 22, 2022 · 5 comments
Closed

Switch layout when in normal mode #54

coordinatio opened this issue Mar 22, 2022 · 5 comments

Comments

@coordinatio
Copy link

First, thank you for the great plugin! It is the real life-changer when you need to edit multilingual text.

I wonder, is there a way to switch layout when in normal mode? Occasionally, I realize that I need to switch all key maps to another language when in normal mode. Now I enter insert mode, switch the layout and then switch back to the normal mode. That sequence is time-consuming. Is it possible to replace that sequence above by a key combination somehow?

@lyokha
Copy link
Owner

lyokha commented Mar 22, 2022

Hi.

I wonder, is there a way to switch layout when in normal mode?

Do you mean that Vim would alter some state after triggering system keyboard layout switch? If so, then no: system keyboard layout change cannot be caught inside Vim as it is only caught by the desktop environment.

Occasionally, I realize that I need to switch all key maps to another language when in normal mode.

What kind of key maps do you mean? The plugin does not affect Vim's Normal mode maps in any way, it only may load the Insert mode maps (i.e. imaps) which have no effects in Normal mode.

@coordinatio
Copy link
Author

For example, let's suppose that you need to edit multilingual text like that:

A word in English, а теперь слово на русском.

You have left the insert mode when you were writing the Russian text, you are at the end of the line and need to jump to the beginning of the word English by pressing FE. You cannot do that because of the mappings active. So, you must enter insert mode, switch the layout, exit the insert mode and then if you press FE that will do what you want.

The idea is to avoid that "enter insert mode - exit insert mode" sequence. Would you please recommend how to do that?

@lyokha
Copy link
Owner

lyokha commented Mar 22, 2022

Ok, this looks like an effect of the Keymap assistance in Normal mode. Removing

let g:XkbSwitchAssistNKeymap = 1
let g:XkbSwitchDynamicKeymap = 1

from the Vim's config file should fix this. Or, if you still want to use the keymap assistance, you may reset iminsert by typing

:set iminsert=0

(you can also define a map for this in Normal mode, notice also that the language in the search line can be switched easily by Ctrl-^).

Btw while digging through this issue I found a small bug: when g:XkbSwitchDynamicKeymap is on then both g:XkbSwitchAssistNKeymap and g:XkbSwitchAssistNKeymap is automatically on regardless of their values in the Vim config. I am going to fix this.

@coordinatio
Copy link
Author

Thanks for the advice!
I've made the following change in my .vimrc and it seems like the perfect solution I have been searching for!

function! ImInserToggle()
    if &iminsert
        set iminsert=0
    else
        set iminsert=1
    endif
endfunction
nnoremap <a-k> :call ImInserToggle()<cr>

Thank you so much!

lyokha added a commit that referenced this issue Mar 22, 2022
@lyokha
Copy link
Owner

lyokha commented Mar 22, 2022

@coordinatio, ImInsertToggle() looks good except you'd better use setlocal instead set in both clauses to not affect iminsert globally rather than in the current buffer. I also fixed the bug with the dynamic keymap assistance that I'd mentioned.

lyokha added a commit that referenced this issue Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants