Hacker News new | comments | ask | show | jobs | submit login
Dwm.vim : Tiled Window Management for Vim (vim.org)
146 points by sciurus on Aug 22, 2012 | hide | past | web | favorite | 83 comments



The most valuable two settings I know for this are:

set ttymouse=xterm2

set mouse=n

Now you can use the mouse to resize buffers and click on tabs. You can even click to focus on a buffer and don't need to meta-press your way around when you just want to browse things. Go on, click on topics inside of the help, assign the right click to supertab[1], navigate NerdTree[2] like the explorer clone it is. Collapse and expand code folds[3] like a 21st century digital boy.[4]

Furthermore, your scrollwheel all of a sudden now scrolls through your document in putty, xterm, screen, rxvt, tmux, iterm; all of them. Yes, total heresy, I know.

The only thing more important than this is doing a visual selection[5] and then doing a :!(any program) like say: fmt, sort, mail, python, rdoc, indent, bc ...

I know what you are thinking; "But kristopolous, this is so easy; it is not possible". Relax my friend, this is unix, you know this.

PS: Here's my custom vim builder/environment maker: https://github.com/kristopolous/vimbuild

[1] http://www.vim.org/scripts/script.php?script_id=1658

[2] http://www.vim.org/scripts/script.php?script_id=1643

[3] http://vimdoc.sourceforge.net/htmldoc/fold.html

[4] http://www.youtube.com/watch?v=ZN6kCgMUjFw

[5] http://vimdoc.sourceforge.net/htmldoc/visual.html


The mouse?? But what for?


Do you mean `set mouse=a`? `n` just makes it work while in normal mode iirc, while `a` should work in any mode.


I was excited for a minute, but the ttymouse change did nothing for me on Mac OS Terminal with vim 7.3.


I thought this was fixed in Lion, but I believe it used to be the case that OS X terminal didn't support mouse. Check out iTerm 2 instead.


Thanks :) That seems to have done the trick. Now I just need to get my color scheme working right in iTerm. Still pretty new to Mac OS. I'm really a Linux guy.


I always used terminal vim when on Linux, but after I got a macbook (from work - I'd never buy one), I'm pretty happy with MacVim. Give it a shot.

Pretty much everything works out of the box as with the terminal version, you just get a few usability improvements (OS-integrated clipboard, mouse selections create vim selections and vice versa, etc).


iTerm 2 and Homebrew really make OS X a lot more bearable for me

Switching to zsh and oh-my-zsh has helped a lot too


> OS X terminal didn't support mouse

It does not, you have to use the MouseTerm SIMBL plugin.


ttymouse=xterm2 doesn't work with tmux. And generally, vim will set 'ttym' correctly for you.


"ttymouse=xterm2 doesn't work with tmux"

Works For Me™

Using lilyterm[0], a libvte based terminal.

[0] http://lilyterm.luna.com.tw/


Pretty sure it used to not work--glad to see that it does now. Thanks.


As one of the original instigators of dwm and wmii before that (mostly by shouting at garbeam) I want to point out that this kind of tiled window management was first introduced in larswm (that is sadly discontinued), which in turn was heavily inspired by Rob Pike's Acme editing environment ( http://acme.cat-v.org ).

So in a way we have gone full circle, from text editor, to window managers, back to text editor.

That said, I still prefer Acme to vim, but would be really cool if somebody added mouse chording to vim :)


   I still prefer Acme to vim
If you could expand on that (compare/contrast), I would definitely be interesting in reading it (blogpost, Show HN, etc).


The philosophies of acme and vim are so completely different that is very difficult to even compare.

One of my favorite things about Acme is that it requires basically no configuration, you can write small scripts to perform certain tasks, so in a way it is 'scriptable', but this are usually little more than shell pipelines to transform text.

I remember spending hours in vim simply looking around the huge mountains of documentation to find the right option to add to to my every growing vimrc, and when you wanted to do something slightly complex you had to use the rather bizarre vimscript.

Yes, vim has bindings for python and ruby and a bunch of other languages, but this brings us to another issue with vim: every installation seems to be almost unique, it has no consistent defaults, or even available features, so even carrying your personal vimrc arond (which is a pain in the ass) is not enough as it might depend on some feature not enabled in whatever vim binary you will find in a given system.

Window management and mouse chording in acme are simply a dream, while in vim i can rarely remember all the commands needed to manage windows, and the mouse is basically useless.

I could go on, but if you have tried both, you will realize that the differences are quite fundamental and even philosophical, so I don't expect every vim-head to understand and appreciate acme right away, because it will not fit with what they expect from a text editor.

All that said, I still use ed for quick edits, in part because it provides a consistent and almost universal interface, the trend some Linux distributions have of removing one of the most venerable and ancient Unix commands is very, very disturbing.


Thanks for that


HN needs more posts like this. just saying...


Indeed. My dream HN has 30 of these posts on its front page.


We're far away indeed from the "Learn how you can code how it's hard to learn new things to learn how you can code" kind of posts :)


Agreed, Thanks, Upvote


I think this might be a minority constituency at this point.


I'd posted my dotfiles pre-restructuring, I'll repost it now that it's modularized. Maybe it'll catch this time.


Not quite figuring out how this is functionally different than vim's split buffers. Just seems less flexible than splits in that it did not mention that tiled windows could be repositioned or resized.


Steamlined UX. With Vim split windows, I have to care about positioning. I need to rescale the windows so that I can see the code effectively. I need to think about window management. This automates it for me, and I have one less thing to think about.

Flexibility can be nice, but it can also get annoying. I don't want to micromanage behavior if the environment can do the right thing for me.


I frequently work with one vertical split in the middle with a class file on one side and the related spec on the other. I can relate to wanting to have a standard layout. I just frequently, split up the windows even more as I work. I used to find splits difficult to manage, but then I got used to/addicted to them. Personally, I would have difficulty with a fixed layout, but I can understand how it could be appealing.


By default Vim's split buffers have some fairly annoying behaviours -- for example, if you accidentally close the file browser you have taking up the entire left hand of the window, all of the other buffers gobble up that space instead of retaining your painstakingly assembled layout.


I guess to each their own, but I like the default behavior of when a split buffers is closed that the other buffers resize to fill the void. I'd prefer to see the space available used rather than trying to find something to fill the empty buffer with.

Unrelated, but I also enjoy being able to Ctrl+w,Shift+[hjkl] to move splits around relative to the other splits.


> I guess to each their own, but I like the default behavior of when a split buffers is closed that the other buffers resize to fill the void. I'd prefer to see the space available used rather than trying to find something to fill the empty buffer with.

Yeah, but the point is I closed it accidentally. So now I reopen NERDTree or whatever and have to spend a bunch of time micromanaging my splits back into the arrangement I just had them in.

Wasted space sucks, but so does having things wreck my layout in an over-eager attempt to avoid it.


This can be a common problem especially when working with a module which occupies a split, but doesn't depend on the file you're working on, like NERDTree. I've solved this problem in a fairly lightweight and elegant manner with the Bclose module, however, by (c)mapping bd to Bclose


I don't understand. What does this do that vim buffer windows don't already manage?


Presumably only the arrangement and sizing of windows. I.e. you don't have to :split or :vsplit manually, just create or delete windows and they'll be arranged according to the layout algorithm.


Yep, that's even better said


It forces a tiled layout that helps productivity by: - keeping all buffers visible - making jumping from one to another very easy - driving focus on the main buffer

The advantages are well-known and demonstrated by dwm from which this plugin is inspired


Ah, it helps automate the maintenance of that particular window structure. Nice.


Yep


I recommend Golden-ratio for this kind of thing:

http://www.vim.org/scripts/script.php?script_id=3690

It does not take away the ability to do :split or :vsplit or force a particular layout. It does dynamically resize your windows to maximize visibility


Yep, that's a different religion. But it's just as good.


Here's a screenshot as well http://i.imgur.com/TKL4i.png available on the github of the script https://github.com/spolu/dwm.vim


I use TMUX with VIM for that.


Better yank/paste | over SSH support


Is there any way to run multiple vim windows from one vim process, with them sharing the same internal clipboard?

To me, the window manager handling the window arrangement feels like The Right Thing, but vim handling the clipboard also feels right (because it interacts with many commands). So I'd like some hybrid of the two options of: 1) running multiple WM-managed vim instances; vs. 2) running one vim with vim-internal window management. I basically agree with the goal of running vim with dwm window management, but it seems wrong to have to reimplement dwm inside of vim, instead of using dwm itself to manage vim windows.


As an aside, you should also note that you can interact with the X clipboard from within vim or gvim. It's represented by the * register, so you can do things like "[asterisk]p to paste from other programs or "*Y to yank to them. Replace [asterisk] with the actual symbol. HN thought I was trying to italicize.


I bound some keys to this and works pretty well

  nnoremap <Leader>y "+yy  
  nnoremap <Leader>d "+dd
  noremap  <Leader>p "+p
  noremap  <Leader>P "+P
  vnoremap <Leader>y "+y
  vnoremap <Leader>d "+d


If your vim is on a box with an X server, look into client/server mode. You can then specify if you want to open a file in its own process or in the server process you spawned earlier.

Also, you can set the default yank register to be your X clipboard. Look into set clipboard = unnamed+ (make sure your vim is complied with X support for both of these)


For 2) you can use tabs in Vim to provide different workspaces, with each workspace having a certain layout of windows.

I've just found out that dwm.vim doesn't work well with tabs just yet though - it copies all buffer windows to the current tab on Ctrl-f (make active window the master focus).


Yep this has to be fixed.


"Is there any way to run multiple vim windows from one vim process, with them sharing the same internal clipboard?"

Yes, though you will need a Vim with support for it built. See `:h client-server` for details. (I never really got into using it regularly)


I use XMONAD with VIM for that. :)


I got into Awesome Window Manager a couple of months ago and have been getting to know how to manage remote Vim split windows with the help of NERDTree. A remote in-Vim managed tiling aproach would be cool though. Googling around, there's also https://github.com/fabi1cazenave/suckless.vim which emulates wmii and has "[s]tacked, [d]ivided, [f]ullscreen" modes. I need to learn tabs also. Things can get busy on 1024*768!


awesome wm, urxvt, ssh, tmux, vim, dwm.vim http://i.imgur.com/fC556.png

nerdtree <cr> opens things in the active window, nerdtree i opens a split in the master window, and a dwm.vim focus tidies things up. no fullscreen mode is unhandy though (i've not learnt how to unmaximise from Ctrl-w _ and Ctrl-w | yet).

edit; silly me, doing Ctrl-f now unmaximises the window.


THAT's AWESOME!!! Please file an issue with how you would see the user interface for a fullscreen mode. I'll be happy to add it asap! -> https://github.com/spolu/dwm.vim


done. as noted there, Ctrl-w | Ctrl-w _ to fullscreen does leave the other windows crushed at the edge, but i guess there might be a better method?


Actually I have an idea... CTRL-L goes fullscreen while CTRL-H brings back to tiled mode...


yep, you just navigate where you want and focus


CtrlP + tabbar has done a lot to make this Emacs user tolerate the occasional vim outing.


Wonderful, ta, I'll check them out soon! Links for the lazy yet interested; https://github.com/kien/ctrlp.vim http://www.vim.org/scripts/script.php?script_id=1338


nice.


That looks cool!


+1 for tmux, I've been using it for a few months and loving every minute of it. One question about tmux/dwm.vim, though: Is there a way we could have the "focus"/automatic layout feature in tmux?

I'd love to press a key combo and have tmux bring my current pane to the large left panel, switching it with whatever I had there before.


I have this in my vimrc which provides 90% of this:

    noremap <C-h> <C-w>h
    noremap <C-j> <C-w>j
    noremap <C-k> <C-w>k
    noremap <C-l> <C-w>l
You can then jump between splits with Ctrl and the navigation keys.


Same here.

I do not really understand the need to have a 'window manager' inside vim. I'm a long xmonad user and I think tiling window managers are great (wish there would be a worthy native os x implementation), but adding yet another plugin to my vim setup doesn't really seem feasible, especially when one can map its core functions with a couple of lines. Vim provides uncountable ways to manage splits, including resizing, switching etc, and then there is still vim's great tabs feature to be discovered to reduce the on-screen mess splits can produce...

That said, hat-tips to the author for managing to create a plugin for vim using its rather obscure vi/ex language.


I've also done that. Using it with NERDTree, my typical vim session looks like (I select files in NERTree using `i` most of the time):

    +-----------+
    |   |       |
    | F | S1    |
    | i |       |
    | l |-------|
    | e |       |
    | s | S2    |
    |   |       |
    +-----------+


Not sure it provides "90% of this". Your mappings ARE really cool (in fact I've just added them to my .vimrc, thanks).

I think the nicest feature of dwm.vim, though, is the "focus" and automatic layout of windows. Big left pane + lots of small panes on the right seems like a nice way of doing things...


it would be awesome, if I could somehow use the same keys to switch between vim splits and my (tiling) window manager's windows. First move focus in vim, if I'm already in the utmost split then move the focus to the next window.

Oh, and make it work with tmux's splits, too!



I would also love to have vim brush my teeth! ;-)


Now this is what happens when you do: dwm.vim < vim < tmux < vps < ssh < tmux < gnome terminal http://i.imgur.com/WR9JC.png (courtesy of romainl on reddit/r/wim)


One vertical split and two horizontal splits. Vim already does that. What does this add?


It lays out the windows automatically in Vim like dwm and similar window managers do on X11. Manually opening and moving windows is a bit tedious, this might help.


Yep, this is almost exactly what I do normally with vim, but that I have another column for nerdtree and possibly 6-8 splits. I find that it's pretty easy to move around, and that I can bring out tabs with a work-area for each thing I'm working on.


Absolutely wonderful. I had another plugin like this (that probably came with `janus`) and did the tiling, but was really complicated and I never get to use it anymore.

Something odd though: Isn't ^f supposed to do a 'page down' by default? The 'focus' part of his plugin didn't work for me and I had to change the mapping to ^m instead.


This has been changed to ^h (https://github.com/spolu/dwm.vim/issues/2) You still need to download from github at this stage. Will push a new version today. Thanks!


I use iTerm2 on OS X with window splitting, with focus that follows mouse. Here is an example using several vim processes:

http://i.imgur.com/Xsh8f.png

Of course, you lose the ability to use vim copy buffers between the processes, but it works well and I like the look of it.


I badly want your status bar layout (arrows and colours). How did you do that?



This thread is full of great tips. Thanks for the power line pointer.


I think it's a mistake to overload ctrl+b. That's taken by standard vi functionality. If I'd written this, I'd have been tempted to use ` as a leader. So `n would open a new window. `b would open that buffers view currently bound to ctrl+b.


This is a really nice plugin. I actually already had Ctrl-N mapped to a horizontal split, but this adds more functionality.


The ^F for focus doesn't seem to work - but the rest are really nice and helpful. Thanks very much.


Possible that there is a mapping conflict with some of your scripts. (see https://github.com/spolu/dwm.vim/issues/2)


fast tiling splits in vim? hell yeah i say. one thing that would be nice, would be to preserve window width ratio on ctrl-f


Yep, that's a good point. I'll file an issue on that (https://github.com/spolu/dwm.vim/issues/5)


Emacs has awesome window management built in, just sayin'.




Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: