I am trying to write a pattern that would match only the first character (can be any character, whitespace as well) of a string interpreted literally.
So given this function, that uses "very no magic" to literally match a string given as argument and then highlight that string, how can I modify it, so it only highlights the first character?
function! MatchFirst(i)
highlight Red ctermbg=red ctermfg=0 guibg=#ff0000 guifg=#000000
call matchadd('Red', '\V' . escape(a:i, '\'))
endfunction
So for example calling MatchFirst('{^(sed') on the following text, would only highlight the { if { is followed by *(sed, but not in any other place. Currently it highlights the whole given string {^(sed.
Lorem ipsum do{^(lor sit amet, consectetur adipiscing elit, e{^(sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo con{^(sequat. Duis aute irure dolor in rep{^(rehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
LATER EDIT
To give a bit of context, the argument for the MatchFirst function is the text visually selected by the user, so it can literally be anything, it can be foobar, foo\ze\bar, &#@!^><..?/\\\, 国字字, etc.