Vim icon indicating copy to clipboard operation
Vim copied to clipboard

Mapping `<Esc>` to also clear search highlighting

Open knetworx opened this issue 7 years ago • 2 comments

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 <Esc>. I've done this in Vim for years using the following:

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 <Esc> doesn't clear the search. However, 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

knetworx avatar Apr 09 '18 18:04 knetworx

normalModeKeyBindingsNonRecursiveworks okay with me

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

Aleksandern avatar Dec 21 '18 13:12 Aleksandern

normalModeKeyBindingsNonRecursiveworks okay with me

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

thank you

GoglichidzeMike avatar Aug 26 '22 08:08 GoglichidzeMike