0

Using neovim. Since hlsearch is on, after the search and replace operation the strings are highlighted. Pressing <C-l> clears the highlight.

I have this keymap to convert a line to title caps:

map('n', 'tc', ':s/\\v<(.)(\\w*)/\\u\\1\\L\\2/g<cr><C-l>', default_opts)

The above works except for clearing the highlighting.

If I use from within neovim:

:nmap tc :s/\v<(.)(\w*)/\u\1\L\2/g<cr><C-l>

things work properly.

What is wrong with the earlier sequence?

1
  • I'll test more but it looks odd to me that <c-l> clear the highlight. The :noh is there for that. Commented Feb 16, 2023 at 5:30

1 Answer 1

0

I would do:

:nmap tc :s/\v<(.)(\w*)/\u\1\L\2/g<cr>:noh<cr>

If you have a mapping that link <C-l> to :noh your solution rely on the recursivity of the mapping.

map('n', '<C-l>', ':noh<cr>', { noremap = false })
map('n', 'tc', ':s/\\v<(.)(\\w*)/\\u\\1\\L\\2/g<cr><C-l>', { noremap = false })
2
  • It works. I have defined <c-l> as :set nohls<cr>. My question is why it works one way and not the other?
    – mas
    Commented Feb 16, 2023 at 8:12
  • I suspect that your default_options make the mapping non recursive and that in the second mapping the <C-l> is a pure redraw not including :noh. Commented Feb 16, 2023 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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