2

I would like to execute a shell script, with parameters, from vim by mapping it to F6, however the current mapping I have in my .vimrc isn't working:

" Map F6 to sync project changes to dev server
nmap <F6> :! ~/path/dev_sync.sh alistair /Users/user/svn<CR>

I guess there might be a problem that it is in a different directory? Or perhaps the fact I have to pass in parameters?

I've tried a few variations on this mapping and with no such luck, if anyone has any ideas it would be very appreciated, thank you.

11
  • 2
    I just create a similar mapping and it works properly. Could you clarify what you mean by "it doesn't work"? Do you get an error message? What happens when you press <F6>? Also if I may invite you to read a question of mine about mappings debug.
    – statox
    Jul 8, 2016 at 8:48
  • @statox Thank you for the link to you comprehensive document, I will make sure to read through it. When I press <F6> it seems that nothing happens, and instead I get a default sound from my mac, not certain how to describe the sound but the same sound is produced when hitting <esc> too many times when in normal mode (on mac). I don't get any other notifications, sorry if this isn't very helpful! Jul 8, 2016 at 9:36
  • 1
    You're welcome, and if you don't find the solution by yourself don't hesitate to give more details so we can try to help you :-)
    – statox
    Jul 8, 2016 at 9:38
  • sorry @statox I accidentally submitted my reply before giving you the full details! Any idea as to what could be the problem? If not no worries, I'm still in the process of reading your question :) Jul 8, 2016 at 9:49
  • 2
    Using nnoremap <F6> instead of nmap <F6> changes anything? You could also try your mapping after starting vim with vim -u NONE -U NONE -N -i NONE.
    – mMontu
    Jul 8, 2016 at 11:06

1 Answer 1

1

You could try to :echo the command in Vim instead of executing it in the shell to ensure it is what you expected.

In any case, if you are starting to use mappings, you should definitively stick to the noremap version:

                                                *:nore* *:norem*
:no[remap]  {lhs} {rhs}         |mapmode-nvo|   *:no*  *:noremap* *:nor*
:nn[oremap] {lhs} {rhs}         |mapmode-n|     *:nn*  *:nnoremap*
:vn[oremap] {lhs} {rhs}         |mapmode-v|     *:vn*  *:vnoremap*
:xn[oremap] {lhs} {rhs}         |mapmode-x|     *:xn*  *:xnoremap*
:snor[emap] {lhs} {rhs}         |mapmode-s|     *:snor* *:snoremap*
:ono[remap] {lhs} {rhs}         |mapmode-o|     *:ono* *:onoremap*
:no[remap]! {lhs} {rhs}         |mapmode-ic|    *:no!* *:noremap!*
:ino[remap] {lhs} {rhs}         |mapmode-i|     *:ino* *:inoremap*
:ln[oremap] {lhs} {rhs}         |mapmode-l|     *:ln*  *:lnoremap*
:cno[remap] {lhs} {rhs}         |mapmode-c|     *:cno* *:cnoremap*
                        Map the key sequence {lhs} to {rhs} for the modes
                        where the map command applies.  Disallow mapping of
                        {rhs}, to avoid nested and recursive mappings.  Often
                        used to redefine a command.  {not in Vi}

Your problem may be caused by some mapping in command mode which changes the command before executing it.

If such kind of problem persists, it is often a good idea to try to reproduce it with all your settings and plugins disable, by starting Vim with vim -u NONE -U NONE -N -i NONE. You can find more about this on Vim-FAQ 2.5 - I have a "xyz" (some) problem with Vim. How do I determine it is a problem with my setup or with Vim? / Have I found a bug in Vim?.

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.