print bufname on current line

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

print bufname on current line

Ven Tadipatri
I found out there's a neat command called bufname which prints out the
name of the buffer that I'm working on. Now, I can't believe I'm
having trouble with this, but how do I actually *paste* the output of
that on the current line? I've tried :echo bufname("%"), which prints
it on the command line. That's not what I want. :bufname("%") gives an
error about an unrecognized command, and various other combinations of
:, %, and ! don't seem to do the trick either.
   This seems like it's relatively basic - executing a command and
putting the output on the current line. I'm not quite sure what I'm
doing wrong. Any ideas?

Thanks,
Ven

--
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
Reply | Threaded
Open this post in threaded view
|

Re: print bufname on current line

Tim Chase
On 01/10/2011 05:22 PM, Ven Tadipatri wrote:
> how do I actually *paste* the output of that on the current
> line? I've tried :echo bufname("%"), which prints it on the
> command line. That's not what I want.

You can use the expression register.  In insert-mode, press
control+R followed by "=" and type in "bufname('%')" and hit
enter.  It works for evaluating any expression you want.  If you
do it frequently, you can map it:

   :inoremap <f4> <c-r>=bufname('%')<cr>

which will allow you to press <f4> in insert-mode and get the
desired text inserted.

Using the ability to insert a register's contents is pretty useful.

   :help i_CTRL-R

for more information (in this case, the tail bit about the
expression-register)

-tim

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