3

I mapped the following and tried with either and both mappings activated in hope to cover all vim modes:

map! ĸ {
map ĸ {

The mapping works in insert mode and in normal mode as expected, but when I try to do a command like di{ to delete all inside a pair of braces {}, nothing happens. Recursive mapping works for { in another command that fails if I use ino { instead, so it must be active...

I don't understand why it doesn't work in the chained commands.

2
  • You will probably get more help at Vi Stack Exchange.
    – Quasímodo
    Oct 1, 2020 at 14:22
  • alright, will try that
    – dekuShrub
    Oct 1, 2020 at 14:31

1 Answer 1

1

The problem is that i{ is a whole operator-pending command (or text object) and mappings don't really work for the later parts of an existing command or mapping. If you want to support i{ (and its friend a{) in operator-pending and visual modes, you would need an additional set of mappings to explicitly do so:

omap iĸ i{
omap aĸ a{
xmap iĸ i{
xmap aĸ a{

But a much better way to accomplish this key mapping is to use the 'langmap' feature, which allows you to remap keys in normal mode. For your particular use case you will also need to set 'langremap'.

set langmap=ĸ{
set langremap

This will take care of Normal mode, Visual mode, operator-pending mode and also mappings involving the { symbol.

It will not take care of Insert mode or command-line mode. For that, you can either keep using a :map! (which typically works fine), or there's also a 'keymap' option for the Insert mode equivalent of 'langmap', but 'keymap' is considerably more complex (it involves creating a separate mapping file with unique syntax and there are a few additional options controlling where exactly the mapping is activated.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.