0

I'm trying to bind <C-S-S> (Control + Shift + S) to send the selected test to a system command, and to then replace the selected text with the output of the system call.

This is what I have tried:

vnoremap <C-S-S> :'<,'>!echo 'Output of system call'<CR>

However, it only seems to work in gvim (and with an annoying confirmation message from the vim console, making the user press Enter to get rid of it). In addition, even if this would work, it doesn't actually send the selected text as an input to echo.

How to fix this so that it works in terminal vim as desired?

2 Answers 2

1

There are a couple things I notice.

  1. You can't map to <C-S-S>. I wrote a more extensive answer on that here, but the basic problem is that <C-S-S> does not produce an ASCII value different then <C-s> so vim is unable to distinguish the difference between them.

  2. It's quite possible mapping to <C-s> will not work in your terminal. This is because the terminal receives and processes the command before it's ever sent to vim, so vim never gets to process the key. To verify that <C-s> really is being processed by vim, try typing i<C-v><C-s>. If anything comes up, you're good to go. Otherwise, you'll be unable to map <C-s> unless you configure your terminal to send a specific escape code. (IMO this is more trouble than it's worth) Gvim is better at handling control characters, so the easiest solution is to switch to gvim.

    Another easy solution is just to use a leader mapping instead of a ctrl-x mapping.

  3. This one is more of a style thing, but the '<,'> you included in the mapping is unnecessary. When you are in visual mode, typing : will automatically fill it in for you. You could simplify your mapping if you take it out.

  4. This one is also a style thing, but generally xnoremap works better than vnoremap. You can read more about the reasons why in :h mapmode-x

All of this leads to the number one thing you're missing: You're not actually sending the selected command. To do this is actually pretty simply. You'll just need to yank your selection before running the command, and then use <C-r> to insert the yanked text.

Putting all of these recommendations together, I would do the following:

xnoremap <leader>s ygv:!<C-r>"<cr>
0
  1. You can't use multiple modifiers in CLI Vim mappings. Find another mapping.

  2. See :help hit-enter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.