Vim: Mapping <Esc> to also clear search highlighting

Created on 9 Apr 2018  路  1Comment  路  Source: VSCodeVim/Vim

I'd like to have hlsearch set to true, so I see search highlighting when I'm using it, but I'd also like to be able to clear the search by simply hitting \

set hlsearch
noremap <ESC> :noh<CR><ESC>

However, I can't seem to figure out how to reproduce this behavior in VSCodeVim. I've tried a few combinations of settings, and here's what I've got right now:

    "vim.hlsearch": true,
    "vim.otherModesKeyBindingsNonRecursive": [
        {
            "before": ["<Esc>"],
            "after": [],
            "commands": [
                {
                    "command": ":noh",
                    "args": []
                }
            ]
        }
    ],

Searches are highlighted as expected, but hitting \typing ":noh" manually does have the desired effect.

The extension's readme contains this snippet:

       "vim.otherModesKeyBindingsNonRecursive": [
        {
            "before":["<C-n>"],
            "after":[],
            "commands": [
                {
                    "command": ":nohl",
                    "args": []
                }
            ]
        },

Putting that exact block in my settings doesn't seem to work either.

There are various related tickets (most of which have been closed), and it seems it should be working, so maybe there's just something I'm missing.
Related Issues:
https://github.com/VSCodeVim/Vim/issues/1166
https://github.com/VSCodeVim/Vim/issues/1047
https://github.com/VSCodeVim/Vim/issues/1053

Most helpful comment

normalModeKeyBindingsNonRecursiveworks okay with me

    "vim.normalModeKeyBindingsNonRecursive": [
      {
        "before":["<Esc>"],
        "commands": [
          ":nohl"
        ]
      }
    ],

>All comments

normalModeKeyBindingsNonRecursiveworks okay with me

    "vim.normalModeKeyBindingsNonRecursive": [
      {
        "before":["<Esc>"],
        "commands": [
          ":nohl"
        ]
      }
    ],
Was this page helpful?
0 / 5 - 0 ratings

Related issues

stefanoio picture stefanoio  路  3Comments

spinningarrow picture spinningarrow  路  3Comments

waltiam picture waltiam  路  3Comments

gerardmrk picture gerardmrk  路  3Comments

st-schneider picture st-schneider  路  3Comments