2

While reading through this answer, I found these useful commands:

  • Ctrl+W +/-: increase/decrease height
  • Ctrl+W >/<: increase/decrease width

These are super useful, but I hate how it defaults to resizing by a single column at a time. I'd like it to move 10 columns at a time. I could do this:

nnoremap <C-w>+ 10<C-w>+
nnoremap <C-w>- 10<C-w>-
nnoremap <C-w>< 10<C-w><
nnoremap <C-w>> 10<C-w>>

But I dislike this solution. For one, it doesn't work well with counts. Sure, I could use <expr>, but that just makes it more complicated. The other thing is, this just feels like the wrong way to do it. Is there any setting such as :set resize_amount = 10?

1
  • Isn't the real question, how can vim be made to behave like tmux for resizing windows? i.e. in tmux (through a custom mapping) I just hit <prefix> then just keep hammering <C-J>,<C-K>,<C-H>,<C-L> until the windows are where I want them. Even Bram moolenaar himself states that vim's resize feature is most easily used with a mouse. Commented Sep 8, 2016 at 7:28

1 Answer 1

2

There is not a setting that works as you've described, so you're probably on the best track already. Using <expr> and v:count can get you what you want:

nnoremap <expr> <C-w>+ v:count1 * 10 . '<C-w>+'
nnoremap <expr> <C-w>- v:count1 * 10 . '<C-w>-'
nnoremap <expr> <C-w>< v:count1 * 10 . '<C-w><'
nnoremap <expr> <C-w>> v:count1 * 10 . '<C-w>>'

v:count1 returns 1 if there is no count, as opposed to v:count which would return 0 if there is no count, which wouldn't be what we'd want here.

If you didn't want to move in increments of 10, but rather always just move at least 10 lines, just swap * for +.

In either case, if you need to resize by an amount that is either not multiple of 10 or is less than 10, :resize and :vertical resize will still cover that. See :help window-resize for more details on those. Alternately, see @Sato Katsura's comment for a method that works as stock with a count but uses a variable when no count is provided.

4
  • 3
    Just so you know you can use v:count1 to get rid of the ternary. :)
    – DJMcMayhem
    Commented Sep 1, 2016 at 1:26
  • So basically nnoremap <expr> <C-w>+ (v:count ? v:count : g:resize_amount) . '<C-w>+' etc. would do as requested except for the "no <expr>" condition, right? :) Commented Sep 1, 2016 at 5:19
  • @DJMcMayhem I saw that referenced somewhere but didn't see any explanation for what it did. Definitely nicer than a ternary. Commented Sep 1, 2016 at 13:31
  • @SatoKatsura That wasn't how understood the question, but looking at it again, I think your interpretation/solution was more accurate Commented Sep 1, 2016 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.