Home:ALL Converter>vim key mapping with execute normal not working

vim key mapping with execute normal not working

Ask Time:2017-02-11T21:19:53         Author:drkicknrush

Json Formatter

I want to highlight trailing space at the end of a line in vim. The following command works:

:match Error /\v\s+\n/

But I'm having trouble mapping this to a key:

nnoremap <leader>w :execute "normal! :match Error " . '/\v\s+\n/' . "\<cr>"

Vim responds with:

E114: Missing quote: "\
E15: Invalid expression: "normal! :match Error " . '/\v\s+\n/' . "\

Update: Having just seen this: http://vim.wikia.com/wiki/Highlight_unwanted_spaces I've got the mapping working, by just writing:

nnoremap <leader>w :match Error /\v\s+\n/<cr>

Can anyone explaing what the problem is with the original execute normal! ... construct which prevents it from working?

Author:drkicknrush,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/42176326/vim-key-mapping-with-execute-normal-not-working
yy