Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to write a command that will close a tree-browser (vim-tree) window and resize the other windows.

,to opens the window and adjusts the window size so that all open windows retain a normal size (using :set columns+=30CTRL-W =).

,tc should close the tree window (full-length, far left) and resize the main window (:set columns-=30).

How can I write a command that closes the leftmost window so that I can type ,tc to close the window and resize in one shot?

  • I can navigate to it with CTRL-W h, but it is inelegant and potentially annoying (audible bell!) to use 10CTRL-W h in the command.
  • :topleft c unfortunately doesn't work.

Can you think of an elegant way to do this?

share|improve this question
    
Are you sure that the bell is from the 10CTRL-W h command? I just tried it and it doesn't generate a bell for me, while other commands (e.g.,h when the cursor is in column 1) do. – garyjohn Jan 10 '11 at 1:38
    
@garyjohn – I'll give it a try, but it's still inelegant! ;) – msutherl Jan 14 '11 at 5:58

If the window really is full length at the far left, it will have window number 1, so a mapping like this should work:

:nmap ,tc :exe '1wincmd w' | close<CR>

This jumps to the first window, then closes it. The drawback is that the active window will become whatever was window number 2 (which becomes window number 1 when the original window number 1 is closed), rather than the last window you were in.

Unfortunately :1wincmd c does not close the first window, since ctrl-w c does not accept a count, so I cannot see a way to avoid first moving to the window you want to close.

share|improve this answer
    
thanks – will give this a try when I get a chance! – msutherl Jan 14 '11 at 5:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .