Here is a function that return the text of the highlighting text if it match the argument:
function! GetSynWord(syname)
let l:line = line('.')
let l:col = col('.')
let l:stack = synstack(l:line, l:col)
if len(l:stack) == 0
return ''
endif
let l:syname = map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')[0]
" echo l:syname
if l:syname != a:syname
return ''
endif
let l:id = l:stack[0]
let l:start = l:col
while l:start >= 0
let l:nstack = synstack(l:line, l:start)
if len(l:nstack) == 0
break
endif
let l:nid = l:nstack[0]
if l:nid != l:id
break
endif
let l:start = l:start - 1
endwhile
let l:end = l:col
let l:sline = getbufline(bufnr(), l:line)[0]
while l:end < (len(l:sline) + 1)
let l:nstack = synstack(l:line, l:end)
if len(l:nstack) == 0
break
endif
let l:nid = l:nstack[0]
if l:nid != l:id
break
endif
let l:end = l:end + 1
endwhile
return l:sline[l:start: l:end - 2]
endfunction
The GetSynWord('markdownLink')[1:]
will give you the markdown url if your cursor is on a markdown link.
syntax
feature. Thesyntax
feature is used for colorization but I understand that you would like to map<CR>
to an action that would apply to a markdown link (like in vimwiki)vimwiki
, so when I press Enter, I can match this string.match()
in vimscript, I was wondering if it was possible to use a similar method to the one I mentioned, usingsyn
,start
andend
for example.match
but may be you could also use the result ofsyntax
and catch the part of the text that is assigned to the highlighting group.syntax
cannot be used in the way I'm thinking. I'll look into the more well known markdown plugins like vimwiki, wiki.vim and vim-markdown. Let's see how it goes haha.But anyway, thank you for your help!