Re: how to use buffer variable in command-line mode, in vim?
- From: Gary Johnson <garyjohn@xxxxxxxxxxxxxxx>
- Date: Fri, 28 Oct 2005 02:22:23 +0000 (UTC)
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
.
- Follow-Ups:
- Re: how to use buffer variable in command-line mode, in vim?
- From: Serafeim
- Re: how to use buffer variable in command-line mode, in vim?
- References:
- how to use buffer variable in command-line mode, in vim?
- From: Serafeim
- how to use buffer variable in command-line mode, in vim?
- Prev by Date: how to use buffer variable in command-line mode, in vim?
- Next by Date: diff problem
- Previous by thread: how to use buffer variable in command-line mode, in vim?
- Next by thread: Re: how to use buffer variable in command-line mode, in vim?
- Index(es):
Relevant Pages
|