Windows & Tabs

Windows & Tabs Often you'll want to be able to view multiple files at the same time, for instance to view a test file, and the associated implementation file, e.g. spec/models/user_spec.rb and app/models/user.rb. Thankfully, Vim has great support...
This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/onramp-to-vim-windows-and-tabs

I was exploring how to move a window from tab1 to tab2 (more general form of <C-w>T ). One way is:

  1. :ls to note the buffer number of the window I want to move in tab1
  2. :close to close tab1
  3. gt or gT to tab2 if not already in tab2
  4. :sbuf N where N is the buffer number noted in step 1. This will pop the window into tab2 by doing a horizontal split.
    More details in this Stackoverflow Q/A.

In the video it is mentioned that it is possible to configure the status bar to be of a different background color when it is not in focus.
Does anyone know how to achieve it?

Post-Edit: Is there a way to do the opposite of C-w T?
I mean, grabbing a tab and making it a split.
Too crazy?

Thanks!

@fmquaglia I have the following in my .vimrc, it might be wrong, as i am relatively new to vim

hi StatusLine ctermbg=yellow ctermfg=black" bg=dark
hi StatusLineNC cterm=none

1 Like

Hi @razmig !

It worked!
Although you’re new you rock, man.
Thanks! :+1:

BTW, As I’m new to cterm colors I used this plugin that came handy: xterm-color-table.vim - All 256 xterm colors with their RGB equivalents, right in Vim! : vim online

Oh! glad i could help.
The plugin looks really nice, although i am a little bit hesitate when it comes to plugins as they grow like monsters and soon things into mess :slightly_smiling:

I hear ya! :smile:

It is possible to yank and paste from tab to tab which is really nice.

Is it possible to execute shell commands on new split ?

Hi @karun-code, if I’m understanding you correctly, you’d like to run a shell command whenever you open a new split? You can use split-window and pass a shell command along with it, e.g. tmux split-winodw 'vim ~/.tmux-.conf' (this would open your tmux conf file in the split), but once that command completes, the new split window will close.

Alternatively you can set the set -g default-command 'zsh' command. Typically this defines your startup shell, but in theory you could do more with it.

The last option, and the one I’d likely look into, is to add something to your shell startup file, for example the ~/.zshrc for zsh shells, or ~/.bashrc for bash. You can run a command from it, and you could even make it conditional on being in tmux by checking for the $TMUX environment variable:

[[ ! -z "$TMUX" ]] && echo 'in tmux' || true

That checks for being in tmux, and then does echo 'in tmux' if so, or exits quietly (the || true bit). You can replace echo 'in tmux' with your preferred shell script.

Hi @christoomey, Thanks for your response and sharing your knowledge through this wonderful trail - Onramp to Vim, it has been very interesting going through it, and opens up new possibilities.

My earlier query was related to opening a new split in native vim (without using tmux) and run shell commands there, so as to test the code being written in the original split.
As I understand that may not be the correct use-case for vim and the very reason for having tmux.

Ahh, yes. Sorry for my misunderstanding. I would very much look to tmux for this sort of thing. You can see some of how I approach Vim & tmux integration in this video. That said, if you do want to stick to Vim, there is a terminal mode that you can use as well. Hope that helps!