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.

nobe4
  • 16,033
  • 4
  • 48
  • 81
  • 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 08 '16 at 08: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!

    – Alistair Hughes Jul 08 '16 at 09: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 08 '16 at 09: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 :) – Alistair Hughes Jul 08 '16 at 09:49
  • What is the exact command you tried in shell? Did It worked there? – SibiCoder Jul 08 '16 at 10:55
  • @SibiCoder this is my exact key mapping in my vimrc nmap <F6> :! ~/svn/company-utl/client/dev_sync.sh alistair /Users/user/svn/<cr>

    And when I run this command in my terminal: ~/svn/company-utl/client/dev_sync.sh alistair /Users/user/svn/

    it works perfectly but still I hear the noise when pressing <F6>

    – Alistair Hughes Jul 08 '16 at 11:03
  • 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 08 '16 at 11:06
  • Do you see the command executed in shell, any errors? Give :verbose map <F6> to check anything overridden your mapping – SibiCoder Jul 08 '16 at 11:10
  • When I execute it directly in the terminal it runs no problem. It appears that it doesn't execute at all which is strange because when I do :verbose map <F6> everything is correct and as it should be: n <F6> :! ~/svn/company-utl/client/dev_sync.sh alistair /Users/user/svn/<CR> – Alistair Hughes Jul 08 '16 at 11:18
  • @mMontu changing nmap to noremap made it work perfectly, thank you very much! I don't completely understand the reason why though?

    If you don't want to explain that is also okay, I still have a lot of reading up to do on vim before I'm fully comfortable with the these sorts of things. I've only just made the first real switch to making it my IDE after a gradually learning and setting up my environment so I'm running into these sort of 'noobie' issues.

    (Thank you to others for you help along the way too ofc :))

    – Alistair Hughes Jul 08 '16 at 11:30
  • I included the explanation below (note that Vim has an extraordinary help system included -- in this case you could try :help noremap). Please let me know if you find something unclear. And I hope you enjoy using Vim :-) – mMontu Jul 08 '16 at 11:47

1 Answers1

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?.

mMontu
  • 6,630
  • 21
  • 31