Hi,
sorry for this offtopic mail, but I asked this on the vim-user
mailing list and git no answer…
What I wnat to do seems to be simple: I want to write a script
with vim and – without saveing it – pass it to the ruby interpreter
and get back the output including stderr AND stdout back into a new
buffer.
this.possible? && if true
anser = how.ask(self)
end
Evening.nice!
mcc
Meino Christian C. wrote:
this.possible? && if true
anser = how.ask(self)
end
Evening.nice!
mcc
I pulled this from the web, or the mailing list, somewhere… a google
on it should point you to the correct author…
in .gvimrc/.vimrc add
map :!rm -f /tmp/*put :w /tmp/input :!/bin/ruby
/tmp/input > /tmp/output 2>&1 :vs +e! /tmp/outputl
map o
short form of descriptions
execute and paste results in left side of vertical split
close left side of vertical split
From: Reid T. [email protected]
Subject: Re: OT: Vim->Ruby and back ?
Date: Fri, 28 Apr 2006 03:05:21 +0900
short form of descriptions
execute and paste results in left side of vertical split
close left side of vertical split
Thanks a lot for that trick, Reid !
But this only write the buffer, start ruby, exute that file with ruby
with ridirected output to another file and reads back that file into
vim. Additionally it does not check, whether both files already
exist…thex will be overwritten simply.
I wanted to exeute ruby with the buffer contents without writing to
the disk at all for that reason.
Is this possible ?
Ruby!
mcc
On 4/27/06, Meino Christian C. [email protected] wrote:
I wanted to exeute ruby with the buffer contents without writing to
the disk at all for that reason.
map :!ruby %
On 4/27/06, Gregory B. [email protected] wrote:
On 4/27/06, Meino Christian C. [email protected] wrote:
I wanted to exeute ruby with the buffer contents without writing to
the disk at all for that reason.
map :!ruby %
sorry… did not fully read your post. I don’t know how to load it
into another buffer without saving it. :-/
From: “Gregory B.” [email protected]
Subject: Re: OT: Vim->Ruby and back ?
Date: Fri, 28 Apr 2006 12:35:32 +0900
On 4/27/06, Meino Christian C. [email protected] wrote:
I wanted to exeute ruby with the buffer contents without writing to
the disk at all for that reason.
map :!ruby %
I inserted the above mapping into $HOME/.vimrc .>
In a buffer I wrote:
#!/usr/bin/ruby
print “hallo”
and pressed
An error pops up saying:
E499: Empty file name for ‘%’ or ‘#’, only works with “:p:h”
(dont know before, that the error message are in Chinese … ;O)
And now ?
Gregory B. schrieb:
I hope that someone finds a solution to this, because I would like to
add somethign to my .vimrc that can do what you want.
How about
:vmap y:exe "ruby " . getreg()
Mark some text in visual mode and press to send it to the builtin
Ruby interpreter. Note that the interpreter isn’t restarted upon each
invocation, so previous definitions stay valid, which may or may not be
what you need.
Regards,
Pit
On 4/27/06, Meino Christian C. [email protected] wrote:
E499: Empty file name for ‘%’ or ‘#’, only works with “:p:h”
(dont know before, that the error message are in Chinese … ;O)
And now ?
hmm… looks like it needs to be run against a saved file.
I hope that someone finds a solution to this, because I would like to
add somethign to my .vimrc that can do what you want.
On Fri, 2006-04-28 at 02:56 +0900, Meino Christian C. wrote:
What I wnat to do seems to be simple: I want to write a script
with vim and – without saveing it – pass it to the ruby interpreter
and get back the output including stderr AND stdout back into a new
buffer.
I’ve wanted this myself, but never quite got there.
- You can use :w !ruby to run the current buffer without saving it and
see the output.
- You can use :r !ruby % to run the current buffer AFTER saving it and
and get it’s output to the same buffer.
- You can use :e to open new buffers
I’ve never found a good way to bring them together into a nice round
trip shortcut, and unfortunately I don’t know if they’ll suit your needs
anyway since :r still writes out a temporary file…
On Fri, Apr 28, 2006 at 11:29:35AM +0900, Meino Christian C. wrote:
[…]
} > Meino Christian C. wrote:
} > > Hi,
} > >
} > > sorry for this offtopic mail, but I asked this on the vim-user
} > > mailing list and git no answer…
} > >
} > > What I wnat to do seems to be simple: I want to write a script
} > > with vim and – without saveing it – pass it to the ruby
interpreter
} > > and get back the output including stderr AND stdout back into a
new
} > > buffer.
[…]
}
} Thanks a lot for that trick, Reid !
}
} But this only write the buffer, start ruby, exute that file with ruby
} with ridirected output to another file and reads back that file into
} vim. Additionally it does not check, whether both files already
} exist…thex will be overwritten simply.
}
} I wanted to exeute ruby with the buffer contents without writing to
} the disk at all for that reason.
}
} Is this possible ?
I can get you stderr and stdout mised together, not in separate files:
0G"ryG:new
"rp:%!ruby
This yanks the entire buffer into register r, opens a new window, pastes
register r into the window, feeds the entire buffer into ruby’s stdin
and
replaces the buffer with what the script writes to stdout or stderr.
Unfortunately, I don’t know how to distinguish between output to stdout
and
stderr. Since you are writing the script, however, you should know which
is
which.
} Ruby!
} mcc
–Greg
On Fri, Apr 28, 2006 at 07:50:27AM -0400, Gregory S. wrote:
[…]
} I can get you stderr and stdout mised together, not in separate files:
}
} 0G"ryG:new
} "rp:%!ruby
Sorry to respond to my own post, but this is a much nicer-looking (and
tested!) version of the above:
:%y r|new|pu r|%!ruby
} This yanks the entire buffer into register r, opens a new window,
pastes
} register r into the window, feeds the entire buffer into ruby’s stdin
and
} replaces the buffer with what the script writes to stdout or stderr.
} Unfortunately, I don’t know how to distinguish between output to
stdout and
} stderr. Since you are writing the script, however, you should know
which is
} which.
}
} } Ruby!
} } mcc
} --Greg
–Greg
On Fri, Apr 28, 2006 at 12:55:02PM +0900, Gregory B. wrote:
I hope that someone finds a solution to this, because I would like to
add somethign to my .vimrc that can do what you want.
Here’s one idea + cheap implementation:
- F7 in visual mode evaluates the selected area; temporary files are
used so
the original one isn’t overwritten. The output (stdout & stderr) is
shown in
a new vsplit window (on the right)
- F7 in normal and insert modes evaluate the whole buffer; the cursor
position
is preserved (warning: overwrites the ‘z’ mark)
- S-F7 kills the stdout/stderr buffer; it is also removed from the
minibufexplorer
function! Ruby_eval_vsplit() range
let src = tempname()
let dst = tempname()
execute ": " . a:firstline . “,” . a:lastline . "w " . src
execute ":silent ! ruby " . src . " > " . dst . " 2>&1 "
execute “:redraw!”
execute “:vsplit”
execute “normal <C-W>l”
execute ":e! " . dst
execute “normal <C-W>h”
endfunction
vmap :call Ruby_eval_vsplit()
nmap mzggVG`z
imap a
map l:bw
imap