what does &<CR> mean in the vim command?

2,651 views
Skip to first unread message

elear...@gmail.com

unread,
Jul 8, 2015, 2:00:07 AM7/8/15
to vim...@googlegroups.com
Here is a viim command

nnoremap <silent> <F6>f :!firefox 'http://127.0.0.1/%:t' &<CR>

What does &<CR> in the end of the command mean?

Eric Christopherson

unread,
Jul 8, 2015, 2:06:40 AM7/8/15
to vim...@googlegroups.com
The <CR> means a carriage return is sent at the end. The & is a Unix
shell directive (I'm not sure if that's the right word) to make it
execute the command (i.e., the firefox command) in the background and
immediately return control.

--
Eric Christopherson

Paul Isambert

unread,
Jul 8, 2015, 4:03:42 AM7/8/15
to vim...@googlegroups.com
“<CR>” is simply return; without it, the mapping would enter the
commandline but not execute it. As for “&”, it is used to run jobs in
the background in Linux, so Vim doesn’t hang.

Nikolay Pavlov

unread,
Jul 8, 2015, 1:18:30 PM7/8/15
to vim...@googlegroups.com
It is not a directive, it is officially an operator:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_03.
And it does not need to return control at all; the only thing that
standard says on the matter is that “the shell shall not wait for the
command to finish before executing the next command”. I have not found
anything regarding what shall be done with backgrounded commands when
shell exits, but all shell implementations I know simply exit without
sending backgrounded processes anything, thus letting init take the
parentship and background process continue to run.

Shell does not return control intentionally, it simply exits when
there are no more commands to run.

>
> --
> Eric Christopherson
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Eric Christopherson

unread,
Jul 8, 2015, 10:44:18 PM7/8/15
to vim...@googlegroups.com
On Wed, Jul 08, 2015, Nikolay Pavlov wrote:
> 2015-07-08 9:06 GMT+03:00 Eric Christopherson <echrist...@gmail.com>:
> > On Tue, Jul 07, 2015, elear...@gmail.com wrote:
> >> Here is a viim command
> >>
> >> nnoremap <silent> <F6>f :!firefox 'http://127.0.0.1/%:t' &<CR>
> >>
> >> What does &<CR> in the end of the command mean?
> >
> > The <CR> means a carriage return is sent at the end. The & is a Unix
> > shell directive (I'm not sure if that's the right word) to make it
> > execute the command (i.e., the firefox command) in the background and
> > immediately return control.
>
> It is not a directive, it is officially an operator:
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_03.
> And it does not need to return control at all; the only thing that
> standard says on the matter is that “the shell shall not wait for the
> command to finish before executing the next command”. I have not found
> anything regarding what shall be done with backgrounded commands when
> shell exits, but all shell implementations I know simply exit without
> sending backgrounded processes anything, thus letting init take the
> parentship and background process continue to run.
>
> Shell does not return control intentionally, it simply exits when
> there are no more commands to run.

Weird. I just tried it (in the shell, not Vim) and it seems you're
right. I always thought it would send the subprocess HUP.

--
Eric Christopherson

Sam IBM

unread,
Aug 18, 2016, 12:59:19 AM8/18/16
to vim_use

can someone please explain what does the f after the <F6> means ..cause its really confusing me ...

Tony Mechelynck

unread,
Aug 18, 2016, 1:06:33 AM8/18/16
to vim...@googlegroups.com
The f after <F6> and with no space between them means that the f is
part of the {lhs} (q.v.): when you type F6 followed by f, Vim will
execute the command :!firefox etc., starting Firefox and (as said
above) not waiting for it to finish.

Best regards,
Tony.

On Thu, Aug 18, 2016 at 5:01 AM, Sam IBM <sami...@gmail.com> wrote:
>
> can someone please explain what does the f after the <F6> means ..cause its really confusing me ...
>

Sam IBM

unread,
Aug 18, 2016, 10:33:51 AM8/18/16
to vim_use
thanks alot Tony...
i am trying to figure it out.. i am kinda new to vim thats why ...
when i keep the f in that map command the whole map don't work and vim do nothing .. but when i remove the f it just works right way ...to even get stranger .. after i put back the f .. it works again until i change something in the map .. it then keeps doing the old map behavior until i remove the f again .
for example ..
nnoremap <silent> <F6>f :!firefox 'http://127.0.0.1/' &<CR> ... won;'t work right aways
it needs to be like this
nnoremap <silent> <F6> :!firefox 'http://127.0.0.1/' &<CR>

but after that if i put the f again its keeps working .. i.e opening firefox
nnoremap <silent> <F6>f :!firefox 'http://127.0.0.1/' &<CR>

but if i changed this to that
nnoremap <silent> <F6>f :!firefox 'www.google.com' &<CR> ... it keeps opening the local host page' the old map vlaue' and ignores the new changes ..
to force it to work i need to remove the f and make my change
.. i hope i described the problem right ... forgive my confusion

Shawn H Corey

unread,
Aug 18, 2016, 11:10:41 AM8/18/16
to vim...@googlegroups.com

I'm not sure where you see this but usually it means you have to press "f" after <F6>. That is, to invoke the command, you have to press the sequence <F6> followed by an "f".

This allows a choice of commands from the <F6> key. For example, there may be <F6>a, <F6>b, ... commands which can be invoke by pressing the corresponding letter after the <F6>.

Sam IBM

unread,
Aug 18, 2016, 4:32:14 PM8/18/16
to vim_use
thanks a lot Shawn ... now its working .. the problem was that everytime i change somthing in the map it keeps the old one too .. so i end with two maps for the same key <F6> .. but after i noticed that its working just fine ... thank you so much
Reply all
Reply to author
Forward
0 new messages