├── README.md ├── autoload └── obviousresize.vim ├── doc └── obviousresize.txt ├── obviousresize.gif └── plugin └── obviousresize.vim /README.md: -------------------------------------------------------------------------------- 1 | # Obvious Resize 2 | 3 | This plugin aims to provide an easy way of resizing Vim windows/splits. It 4 | may also seamlessly integrate with tmux, when the same resize keys are used. 5 | 6 | ![Alt text](obviousresize.gif?raw=true "Obvious-resize with tmux integration") 7 | 8 | Just add the following into your .vimrc file: 9 | 10 | ``` 11 | noremap :ObviousResizeUp 12 | noremap :ObviousResizeDown 13 | noremap :ObviousResizeLeft 14 | noremap :ObviousResizeRight 15 | ``` 16 | 17 | ## Specifying the Resize Amount 18 | 19 | Windows get resized 1 line by default, which you can change in your .vimrc file: 20 | 21 | ``` 22 | let g:obvious_resize_default = 2 23 | ``` 24 | 25 | Like most Vim commands, you can prefix your command with an optional count: `5` will resize by 5 lines. 26 | 27 | You can also specify a count in your remap: 28 | 29 | ``` 30 | noremap :ObviousResizeUp 5 31 | ``` 32 | 33 | If you'd like to have tmux integration (by default is disabled), then you may 34 | use the following variable: 35 | 36 | ``` 37 | let g:obvious_resize_run_tmux = 1 38 | ``` 39 | -------------------------------------------------------------------------------- /autoload/obviousresize.vim: -------------------------------------------------------------------------------- 1 | " Description: Obvious-Resize autoload buddy. 2 | " Mainainder: Alexandru Tica 3 | 4 | if &cp || exists("g:_loaded_obviousresize") 5 | finish 6 | endif 7 | let g:_loaded_obviousresize = 1 8 | 9 | if !exists("g:obvious_resize_default") 10 | let g:obvious_resize_default = 1 11 | endif 12 | 13 | if !exists("g:obvious_resize_run_tmux") 14 | let g:obvious_resize_run_tmux = 0 15 | endif 16 | 17 | let s:cpo_save = &cpo 18 | set cpo&vim 19 | 20 | function! s:TmuxCommand(args) 21 | if !g:obvious_resize_run_tmux 22 | return 23 | end 24 | 25 | let cmd = 'tmux -S ' . split($TMUX, ',')[0] . ' ' . a:args 26 | if exists('*jobstart') 27 | call jobstart(cmd) 28 | elseif executable('tmux') 29 | call system(cmd) 30 | endif 31 | endfunction 32 | 33 | " Whenever or not there is a window on the provided side. 34 | function! s:HasWindow(side) 35 | " ignore events 36 | let _eventignore = &eventignore 37 | set eventignore=all 38 | let result = 0 39 | let crr_win = winnr() 40 | exe 'wincmd ' . a:side 41 | if winnr() != crr_win 42 | let result = 1 43 | exe crr_win . 'wincmd w' 44 | endif 45 | let &eventignore = _eventignore 46 | return result 47 | endfunction 48 | 49 | " Resize the current window at the provided direction 50 | function! obviousresize#Resize(dir, ...) 51 | if v:count 52 | let counter = v:count 53 | elseif a:0 == 1 54 | let counter = a:1 55 | else 56 | let counter = g:obvious_resize_default 57 | endif 58 | let crr_win = winnr() 59 | 60 | if a:dir == 'h' 61 | " resize left 62 | if s:HasWindow('h') && !s:HasWindow('l') 63 | " right window 64 | exe counter . 'wincmd >' 65 | elseif s:HasWindow('h') && s:HasWindow('l') 66 | " middle window 67 | exe counter . 'wincmd <' 68 | elseif s:HasWindow('l') && !s:HasWindow('h') 69 | " left window 70 | exe counter . 'wincmd <' 71 | else 72 | " only window 73 | call s:TmuxCommand('resize-pane -L ' . counter) 74 | endif 75 | elseif a:dir == 'l' 76 | " resize right 77 | if s:HasWindow('l') && !s:HasWindow('h') 78 | " left window 79 | exe counter . 'wincmd >' 80 | elseif s:HasWindow('l') && s:HasWindow('h') 81 | " middle window 82 | exe counter . 'wincmd >' 83 | elseif s:HasWindow('h') && !s:HasWindow('l') 84 | " right window 85 | exe counter . 'wincmd <' 86 | else 87 | " only window 88 | call s:TmuxCommand('resize-pane -R ' . counter) 89 | endif 90 | elseif a:dir == 'j' 91 | " resize down 92 | if s:HasWindow('j') && !s:HasWindow('k') 93 | " top window 94 | exe counter . 'wincmd +' 95 | elseif s:HasWindow('j') && s:HasWindow('k') 96 | " middle window 97 | exe counter . 'wincmd +' 98 | elseif !s:HasWindow('j') && s:HasWindow('k') 99 | " botom window 100 | exe counter . 'wincmd -' 101 | else 102 | " only window 103 | call s:TmuxCommand('resize-pane -D ' . counter) 104 | endif 105 | elseif a:dir == 'k' 106 | " resize up 107 | if s:HasWindow('k') && !s:HasWindow('j') 108 | " bottom window 109 | exe counter . 'wincmd +' 110 | elseif s:HasWindow('k') && s:HasWindow('j') 111 | " middle window 112 | exe counter . 'wincmd -' 113 | elseif !s:HasWindow('k') && s:HasWindow('j') 114 | " top window 115 | exe counter . 'wincmd -' 116 | else 117 | " only window 118 | call s:TmuxCommand('resize-pane -U ' . counter) 119 | endif 120 | endif 121 | endfunction 122 | 123 | let &cpo=s:cpo_save 124 | unlet s:cpo_save 125 | -------------------------------------------------------------------------------- /doc/obviousresize.txt: -------------------------------------------------------------------------------- 1 | *obviousresize.txt* A sane way of resizing Vim splits. 2 | 3 | ============================================================================== 4 | 0. Contents *obviousresize* 5 | 6 | 1. Intro ....................................... |obviousresize-intro| 7 | 2. Configuration settings ...................... |obviousresize-config| 8 | 3. Mappings .................................... |obviousresize-mappings| 9 | 4. Source ...................................... |obviousresize-source| 10 | 11 | ============================================================================== 12 | 1. Intro *obviousresize-intro* 13 | 14 | This plugin aims to provide an easy way of resizing Vim windows/splits. It 15 | may also seamlessly integrate with tmux, when the same resize keys are used. 16 | 17 | ============================================================================== 18 | 2. Configuration settings *obviousresize-config* 19 | 20 | By default, windows get resized by 1 line at time. You may change this using 21 | the following variable: 22 | 23 | let g:obvious_resize_default = 5 24 | 25 | If you'd like to have tmux integration (by default is disabled), then you may 26 | use the following variable: 27 | 28 | let g:obvious_resize_run_tmux = 1 29 | 30 | ============================================================================== 31 | 3. Mappings *obviousresize-mappings* 32 | 33 | By default, this plugin doesn't define any key mappings. It's up to you to 34 | define them as you want. For example, you may use the following mappings into 35 | your .vimrc: 36 | 37 | inoremap :ObviousResizeUp 38 | noremap :ObviousResizeDown 39 | noremap :ObviousResizeLeft 40 | noremap :ObviousResizeRight 41 | 42 | You may also specify a count in your remap: 43 | 44 | noremap :ObviousResizeUp 5 45 | 46 | ============================================================================== 47 | 4. Source *obviousresize-source* 48 | 49 | https://github.com/talek/obvious-resize 50 | 51 | vim:tw=78:et:ft=help:norl: 52 | -------------------------------------------------------------------------------- /obviousresize.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talek/obvious-resize/ddb858c86e432c79d45eafc969d1c97db497dbdc/obviousresize.gif -------------------------------------------------------------------------------- /plugin/obviousresize.vim: -------------------------------------------------------------------------------- 1 | " ObviousResize: resize Vim windows in an obvious way 2 | " Author: Alexandru Tică 3 | " Date: 2011-08-24 4 | " Copyright: Copyright (C) 2010 Alexandru Tică 5 | " GPL, Version 3.0 6 | " http://www.gnu.org/copyleft/gpl.html 7 | 8 | if exists("g:loaded_obvious_resize") 9 | finish 10 | endif 11 | 12 | " Current version 13 | let g:loaded_obvious_resize = "1.2" 14 | 15 | " Compatibility stuff handling 16 | let s:keep_cpo = &cpo 17 | set cpo&vim 18 | 19 | " Define obvious resize mappings 20 | if exists(':ObviousResizeLeft') != 2 21 | command! -nargs=* ObviousResizeLeft :call obviousresize#Resize('h', ) 22 | nmap