views:

97

answers:

3

I have been reading a lot of the questions here on vim. I can't locate something that I want to do with vim but I am sure its possible.

I like vim(I am still new at it) using tabs and I have adjusted my vimrc so that H & L keys take me back and forth between tabs.

I was hoping to find a way to be able to use tab commands to open up a tab as output, so that if I am writing something in my case Ruby and I want to test it I could run it and flip to a new tab with the output. Or flip a tab to an interactive console to test code. This is possible?

As an aside is it possible to expand tabs to views so if I had two tabs open say script and output I could :spx or similar and have tabs come to split screen.

A: 

I know it's not the answer you want, but use buffers and ditch the tabs. I have a screencast going over how to use splits to manage your window.

http://lococast.net/archives/111

As for the ruby output, that seems like it might be covered here:

http://superuser.com/questions/133886/vim-displaying-code-output-in-a-new-window-a-la-textmate

Rick
Not sure about OP's specific situation, but it's a mistake to always disregard tabs in favor of splits. Splits within a Vim instance are analogous to windows on a desktop; tabs are analogous to multiple desktops. Also, splits sometimes don't work well.For example, I have files with complicated foldexpr folds that can take several seconds to open in a split--even if the buffer is already loaded. If I keep the buffers open on separate tabs they're immediately accessible; if I try to load them as needed into splits I have wait period each time. Splits, tabs are complementary, not either/or.
Herbert Sitz
http://superuser.com/questions/133886/vim-displaying-code-output-in-a-new-window-a-la-textmate .
sayth
sayth
@sayth: Why not just do a split window (:wincmd w or <ctrl-w>w) and then have ruby route the output directly into the window with: (:1,1!ruby foo.rb)? Does that not work for you?
Herbert Sitz
@sayth: Sorry, commands should have been using 'n' rather than 'w'. So here's sequence to use: (1) :wincmd n , and then (2) :1,1!ruby foo.rb
Herbert Sitz
@Herbert Sitz you're correct in that fact. I still don't use tabs as I prefer to use multiple gvim/terminal instances then. Then things fall under my tiling window manager and I can side by side "tabs" in that sense when required, while still backgrounding them to view only one at a time. So I agree, tabs == more window manager controls, I just think let the window manager deal with them at that point.
Rick
@Rick: That's one solution, but things then get messy if you want any buffers to be shared among your Vim "desktops", since that can't happen between Vim instances. Tabs are a good feature.
Herbert Sitz
A: 

In answer to your question about opening up a tab as output, I don't think there's any built in way to do this. There's the RunView plugin (see my answers to this question and this one), but I don't think that it supports using a separate tab (it works with a split window: what I think you refer to when you say 'view').

Regarding an interactive console: no, this is not possible. See :help design-not.

As for general use of Vim, try to get used to the idea of buffers and the fact that each 'view' (my term), whether it be a split window, a tab or whatever is just a means of looking at a particular buffer. You can have multiple views on a single buffer, so you can have a source file vertical split with two headers in one tab and the same source file vertically split with another header and a different bit of the same source file in another tab. This is very powerful once you get used to it. The Ctrl-W keyboard shortcuts are your friend (e.g. Ctrl-W, h to go left one window).

As for changing a tab into a split window, I don't think there's a direct way to do this (how would Vim know which tabs you wanted to join?). You can break a split into a tab with Ctrl-W + T, but to go back you'd have to create a couple of mappings. This is off the top of my head but something like this might work:

command! TakeThis let takebufnr = bufnr("")<CR>
command! SplitTaken exe 'split #' . takebufnr<CR>
nmap ,t :TakeThis<CR>
nmap ,s :SplitTaken<CR>

Then press ,t on the buffer you want to grab and ,s on the one you want to split with the 'taken' buffer.

Al
Regarding the "interactive console" the reality may be a little different than you suggest. While it's true that Vim can't achieve the integration possible with, say, Emacs, it's definitely possible to use Vim to interact in helpful ways. See., e.g., the Vicle plugin ( http://www.vim.org/scripts/script.php?script_id=2551 ) or the VimDebug plugin that provides some integration with the Ruby debugger (http://www.vim.org/scripts/script.php?script_id=663). I can't vouch for either in particular, but Vim is definitely able to achieve a helpful level of interaction.
Herbert Sitz
A: 

You can load the ruby output into a vim window in a couple of ways. One way would be to open a new split window and then load output of command:

" vimscript command to open new split window
wincmd n
" run ruby command and insert output at line 1
1,1!ruby foo.rb

alternatively you could get view the output on a new tab with a single window:

tabnew
1,1!ruby foo.rb
Herbert Sitz