Mapping `<Esc>` to also clear search highlighting
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
normalModeKeyBindingsNonRecursiveworks okay with me
"vim.normalModeKeyBindingsNonRecursive": [
{
"before":["<Esc>"],
"commands": [
":nohl"
]
}
],
normalModeKeyBindingsNonRecursiveworks okay with me"vim.normalModeKeyBindingsNonRecursive": [ { "before":["<Esc>"], "commands": [ ":nohl" ] } ],
thank you