Re: how to use buffer variable in command-line mode, in vim?



Serafeim <serzan@xxxxxxxxxxxx> wrote:
> Hello,
>
> I'm puzzled on how to use a buffer variable in command line mode. In
> particular, I'd like to define a buffer-specific mapping for saving a
> buffer and compiling it, in which b:compiler has the appropriate compiler
> name (eg, java, gcc, pdflatex, ...) depending on the buffer's filetype.
>
> map <F1> :w^M :!b:compiler % 2>&1 \| tee %:r.err^M
>
> However, it doesn't work because b:compiler in command-line mode is treated
> as a literal. Any hints?

See

:help c_CTRL-R_=
:help mapping

I think this will work for you:

map <F1> :w<CR>:!<C-R>=b:compiler<CR> % 2>&1 \| tee %:r.err<CR>

Note that I've also replaced your ^M's by <CR>'s because I find it
easier to manage mappings when they use all printable characters
rather than including some literal control characters. You can
certainly use ^M's if you'd rather, and you can use a literal ^R
instead of <C-R>.

HTH,
Gary
.



Relevant Pages

  • Re: server scenario - variables in the right spot?
    ... If I'm correct in what I think you mean by 'data structures' then I also ... steps, the command has, and a way to mark which steps are done or not done, ... Assuming you are using the same receive callback for each BeginReceive, ... that processes the data for the first buffer. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: server scenario - variables in the right spot?
    ... ReceiveCallback calling beginReceive again: I do this but not exactly how ... Assuming you are using the same receive callback for each BeginReceive, then I don't see what the difference is. ... The posted receive won't be completed until after the command has been sent and replied to, of course, but there's no harm in being ready to receive beforehand. ... you would wind up running the code in the callback that actually processes the data for that buffer before the code in the same callback that processes the data for the first buffer. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: In vi/vim delete lines
    ... I frequently delete to a mark. ... | A buffer containing lines is put only once, ... | If the last command before a `.' ... The basic meta-characters for the replacement pattern are `&' and `~'; ...
    (comp.unix.shell)
  • Re: Spartados Help Needed
    ... All command line input, including all ... in the buffer during a key repeat. ... However, the XIO Atari ... your lomem will be at $17A2. ...
    (comp.sys.atari.8bit)
  • [SECURITY] telnet client
    ... For general information regarding FreeBSD Security Advisories, ... The telnetcommand is a TELNET protocol client, ... fixed-sized buffer. ... src/UPDATING ...
    (comp.unix.bsd.freebsd.misc)