Hacker News new | past | comments | ask | show | jobs | submit login
Vim Splits: A Guide to Doing What You Want (2010) (technotales.wordpress.com)
60 points by polm23 12 months ago | hide | past | favorite | 21 comments

If you use vim + tmux this plugin[0] is super handy. It allows ctrl-h|j|k|l to switch between tmux or vim splits so you don't have to know whether it's a different terminal window or a vim split—just that you want to go right (for example).

[0] https://github.com/christoomey/vim-tmux-navigator

As a new~ish vim/tmux user, thank you. I stopped using vim splits because tmux.

You can easily copy stuff between vim splits, though. The window movements can also be part of vim macros. I have a couple macros that will assume I'm on the left window, make a change to the right window, save the file, and return me to the left side. I also have one to delete the second line from two side-by-side files for playlist management. At one point I used several vim instances in tmux panes, but only because I hadn't learned of vim's own advanced features.

It seems like there are a lot of different ways to get tiling windows. You can do it in window managers by using different instances of applications. You can do it in terminal sessions using tmux and screen. You can do it in VIM, you can do it in IDEs. You can use suckless tabbed.

I use a tiling window manager, which means I have a unified interface for tiling with all of my windows. I don't ever use tiling window management features of specific programs, outside of tabs in my browser. But I do sometimes miss out on things like sharing VIM registers, or TMUX session management.

Does anybody use tiling features at multiple points in their system?

I pretty much use them at every point. The only special window management I've never liked is tabs or splits at the level of the terminal emulator (like in terminator). It really does just feel like worse/clunkier tmux. I use Sway, tmux, and splits in vim/emacs. I like to have all my terminal stuff glued together and in a certain arrangement. I like that this whole layout of panes I'm used to can then neatly take up half my screen thanks to the wm. Vim has registers and macros that benefit from a single session. Emacs has commands to scroll the "other window", also it often opens a temporary window when you use something like M-x describe-mode or M-x describe-char. You could maybe remove some of this overlap if everything had some sort of ipc and your wm just sent commands to it all.

I use bspwm splits, tmux splits and vim splits simultaneously on up to three monitors. I would recommend to create keybindings for split rotation, clockwise and counterclockwise.

Not in years although in Visual Studio there's the "preview" feature for function definitions that's kind of like a split. I appreciate that feature a lot.

Yep. I often want a group of windows to behave as one window so that e.g. I don't have to alt tab through them individually. So I will use tmux to set up my editor, shell and dev server. I also use vim splits because that is more convenient than creating a new wm frame, opening a new terminal, navigating to the working directory and starting up vim again.

I typically use I3 with multiple tabs in VIM, mainly for sharing VIM registers as you pointed out.

If you use macOS you can also use iTerm2 to make splits without additional keystrokes to move around them like in tmux.

I use dwm for my windows and both tabs and splits in vim

Vim never ceases to amaze me. Opening remote files over scp, splits, file explorer, and the built in cli w/ 8. Such a beautiful program.

I chose using vim + tmux instead of using the vim-specific tiling. The main benefit for me is that all tiles are using same mechanism, as opposed to tmux for shells and vim for code

you can also use vim's built in terminal multiplexer if you have vim 8 or newer. The benefit with using the vim variant is that you can apply most of the vim features to terminal use. i.e. you can use vim to sift through terminal output, you can make vim macros that leverage the terminal as well, and you can yank and paste using vim registers.

Still not as polished as tmux in some ways but I've found it to be a very nice improvement over tmux with vim. Mind you when doing this I still use vim inside tmux so that I can detach and so that I get a bit more consistent terminal output between devices.

ctrl-z will suspend vim. then just type fg from command prompt to get it back.

This doesn't work over ssh unfortunately. The tmux method works locally and remotely. Vim has server mode which is similar but significantly less ergonomic than just using tmux and requires vim to be compiled with non default flags.

multiplexers in multiplexers? woah.gif :p

I promise I’m not trying to start a flame war, but as an Emacs user this seems… commonplace. Are splits not a commonly used feature? I’ve used the equivalent for as long as I can remember in Emacs, so it doesn’t feel particularly esoteric. Or is it that this is just a commonly not fully-understood/utilized feature of Vim? If that’s the case, that is totally understandable. That’s basically my life with Emacs. :)

I’m curious: what features of Vim do you feel are essential to become a power user?

Vim is great but ancient. It was designed on/for systems that just don't exist any more. E.g. looking at the popular keyboard of the time hints at why "escape" was such a critical key : https://i.imgur.com/Hn174TJ.jpg

In order to get the most from Vim, you have to take a huge step back and look at your screen configuration and usage patterns.

* The escape key is too difficult to reach on modern keyboards, use ctrl-c

* Code file sizes are becoming really large. Use search rather than directional navigation/paging to save some time

* The search key is too difficult to hit, remap to space

* Most people are on a wide screen. So, try to make vertical splits as easy as possible to do.

* Folder based search is now very fast and efficient. Use a modified search command (<leader>space) and map it to Rg/Ack

There's some good work recently done for vim with language servers. I'm counting on redoing the key mapping once more. IMHO the poor defaults of vim isn't a bug of vim, it's a feature.

__EDIT__: "tabs" not "windows" sorry. I mixed up

I use vim as my main IDE and I consider splits to be essential in vim too.

About that, I understand the point other people make about using tmux or a tiling wm instead, but this generally means that the register are not shared between those vim instances, which is a huge penalty for me.

"Essential power user features" could be different things for me. For now, I would say using the multiple registers, macros, navigating the undo tree and marks to be both essential and advanced (they are not hard to understand, but you have to remember a lot of things before you dive into all that).

But with vim, you often discover new features after years of usage which become essential when you integrate it in your workflow and muscle memories. For example, I never really grasped the "tabs" concepts and its use cases for now, but I wouldn't be surprised if I make heavy usage of them in the future.

I would thus guess that other vim users might have very different answers.

I'd say I'm an intermediate+ user of VIM. Its my main text editor and has been for 6 years or so. I use splits extensively, but not as described here.

I basically just do :sp or :vsp to divide the current spit in half vertically or horizontally, and then if I care (rarely) I use C-W H/J/K/L to send one of the windows to the appropriate part of the screen. I also switch windows with arrow keys (mapped to fn+HJKL) and use tabs for "workspaces". I also have a custom bit of vimscript that lets me select and swap splits with <leader>w (I do this more than "moving" splits).

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