0

I have a custom "plugin" I use extensively for verilog development, and I have a few functions I obviously call using respective mapping.

For example:

function! FormatIoInstance() range

   silent! :'<,'>v/\/\//normal! I.
   silent! :'<,'>v/\/\//s/\s\+$//g
   silent! :'<,'>v/\/\//s/,$/( ),/g
   silent! :'<,'>v/\/\/\|,/normal! A( )
   silent! :'<,'>v/\/\//Tab /(/l0
   
endfunction

with the following mapping for insert and select mode

inoremap <buffer> <silent> <nowait> <M-8> <C-o>:call FormatIoInstance()<CR>
snoremap <buffer> <silent> <nowait> <M-8> <C-o>:call FormatIoInstance()<CR>

However, extending the mapping to visual mode does not work (nothing happens) in visual mode:

xnoremap <buffer> <silent> <nowait> <M-8> <C-o>:call FormatIoInstance()<CR>

So what am I missing?

4
  • Quoting from :help :v: Instead of the '/' which surrounds the {pattern}, you can use any other single byte character, but not an alphabetic character, '\', '"', '|' or '!'. This is useful if you want to include a '/' in the search pattern or replacement string.
    – Friedrich
    Commented Feb 16 at 9:35
  • How do you think we can help you fix your non-working code if all you show us is your working code?
    – romainl
    Commented Feb 16 at 9:39
  • @romainl, what else would you need? If you are not prone to help, do not reply. It's better.
    – simzz
    Commented Feb 19 at 11:16
  • 1
    Well, your visual mode mapping, with which you are supposedly having trouble with. That would be a good start.
    – romainl
    Commented Feb 19 at 12:39

1 Answer 1

2

I wonder what "doesn't work" mean and what exactly your xnoremap mapping looks like?

Did you try

xnoremap <buffer> <silent> <nowait> <M-8> :call FormatIoInstance()<CR>

?

6
  • I have tried the version of @Maxim and it works fine on my end. Commented Feb 16 at 9:48
  • Doesn't work means it doesn't work.. The C-o was the problem.... Thanks.
    – simzz
    Commented Feb 16 at 10:07
  • 2
    @xyx usually "doesn't work" is vague—does anything happen? Does nothing happen? Do you get a beep, flash, error message? Any of these are useful details beyond "didn't do what I expected."
    – D. Ben Knoble
    Commented Feb 16 at 17:21
  • Honestly, I though that the question was quiet clear since I posted the syntax for inoremap and snoremap. "extending the mapping to visual mode" simply means adding one line as, for example, vnoremap <buffer> <silent> <nowait> <M-8> <C-o>:call FormatIoInstance()<CR>. Is it really poorly intuitive ? "Doesn't work" means "nothing happens". If Vim shows up some message and in this case it is relatively easy to track the problem, or error would be reported here as well.
    – simzz
    Commented Feb 19 at 11:13
  • I believe Maxim wonders why you keep the <C-o> that probably only make sense when you are in insert mode. Did you already had the chance to test the solution he proposes? It seems to work fine for me. Commented Feb 19 at 11:39

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.