Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I repeat the "resize window" command in vim?

Tags:

vim

I know how to resize a window (CTRL_W +). But when I want to repeat the same command, . is useless. Typing CTRL_W + repeatedly is boring. Is there anything else I can do?

In my system:

if bufwinnr(1)
  map + <C-W>+
  map - <C-W>-
endif

does not work.

if bufwinnr(1)
  map <kPlus> <C-W>+
  map <kMinus> <C-W>-
  map <kDivide> <c-w><
  map <kMultiply> <c-w>>
endif

does work.

like image 619
jinleileiking Avatar asked Dec 13 '22 10:12

jinleileiking


2 Answers

I'd recommend the mapping of + and - key like this (in your .vimrc):

if bufwinnr(1)
  map + <C-W>+
  map - <C-W>-
endif    

And please read this, there are several good tips: http://vim.wikia.com/wiki/Fast_window_resizing_with_plus/minus_keys

like image 90
Zsolt Botykai Avatar answered Dec 14 '22 22:12

Zsolt Botykai


The Ctrl-W+ shortcut takes a preceding count. The Ctrl-W_ command maximizes the window without a count, or sets absolute height with a preceding count. Using counts, you should rarely have to do repeated window resizing commands.

If you do find yourself frequently wanting to make small repeated adjustments to window sizes, maybe you could take advantage of the repeatability of ex-commands (with @:) and resize with :resize +1 instead of the keyboard shortcut. If you resize windows all the time, I'd go with mapping the + and - as Zsolt suggested. If you are just restoring the same window layout over and over, look into using a saved session file (:help sessions).

like image 38
jw013 Avatar answered Dec 15 '22 00:12

jw013