0

I have the following key mappings in my ~/.vimrc

" Format paragaph
au FileType markdown nnoremap <buffer> <space> gwip

" Send current line to tmux usind SendToTmux
au FileType python,sh,zsh nnoremap <buffer> <space> yy:call SendToTmux(@")<cr>j

I would like vim to apply / use the markdown key mapping, whenever I am in a line or a paragraph of comments.

Thomas Möbius
  • 1,702
  • 2
  • 17
  • 23

1 Answers1

2

You'll have to analyse the current context with synIDattr(synID(line('.'),col('.')-1,1),'name') like for instance:

:nnoremap <buffer> <expr> <space>  (synIDattr(synID(line('.'),col('.')-1,1),'name') =~? 'comment\\|doxygen') ? ':echo 1<cr>' : ':echo 2<cr>' 
Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
  • Mm.. It only ever echos "2". – Thomas Möbius Oct 26 '16 at 14:21
  • I had this problem because of some characters that needed to be escaped -- in the command line `\` needs to be escaped. In your case, you should not need `\\|doxygen` as this is C++ related. However it's possible that not all comment syntax highlighting have the string `"comment"` in their name. You'll have to move the cursor around and see what `:echo synIDattr(synID(line('.'),col('.')-1,1),'name') " tells you. Then, you'll be able to define your regex -- it may be better to define a function to simplify the regex definition. – Luc Hermitte Oct 26 '16 at 14:47