├── README.md ├── autoload └── zoom.vim ├── doc └── zoom.txt └── plugin └── zoom.vim /README.md: -------------------------------------------------------------------------------- 1 | # VIM Zoom v0.3.4 2 | 3 | A simple plugin to toggle zoom of current window within the current tab. 4 | 5 | This is heavily inspired from tmux's zoom pane feature. 6 | 7 | ## Installation 8 | 9 | Use your favorite plugin manager to install this plugin (recommended). 10 | 11 | #### [pathogen.vim](https://github.com/tpope/vim-pathogen) 12 | 13 | ``` 14 | git clone https://github.com/dhruvasagar/vim-zoom.git ~/.vim/bundle/vim-zoom 15 | ``` 16 | 17 | If however you don't use a plugin manager such as pathogen, vundle, neobundle, 18 | vim-plug then you can copy all files within this repository directly within 19 | your ~/.vim folder. (not recommended) 20 | 21 | ## Usage 22 | 23 | Simply use the provided mapping \m to toggle zoom in and out 24 | for the current window 25 | 26 | > NOTE: In an attempt to keep this plugin as lean as possible, it avoids 27 | > having to deal with special buffers created by plugins that aren't backed by 28 | > actual files. This is a trade-off we've made consiously and helps us keep 29 | > our plugin less than 100 lines of code. 30 | 31 | > If that doesn't work for you and for other more advanced use cases you may 32 | > want to consider alternate plugins such as [goyo.vim](https://github.com/junegunn/goyo.vim) 33 | 34 | ### Statusline 35 | 36 | VIM Zoom provides `zoom#statusline()` API to be used for adding 37 | `g:zoom#statustext` value to your statusline while your window is zoomed. 38 | `g:zoom#statustext` defaults to value `'zoomed'`. You may add this to your 39 | statusline like this : 40 | 41 | `set statusline+=%{zoom#statusline()}` 42 | 43 | If you're using some complex statusline plugin, you may need to refer to its 44 | documentation to figure out how to add this to your statusline. 45 | 46 | #### Example configuration for lualine.nvim 47 | 48 | ```lua 49 | -- Set lualine options 50 | sections = { 51 | -- left 52 | lualine_a = { 'mode' }, 53 | lualine_b = { 'branch', 'diff', 'diagnostic' }, 54 | lualine_c = { 'filename' }, 55 | -- right 56 | lualine_x = { "vim.fn['zoom#statusline']()", 'encoding', 'fileformat', 'filetype' }, 57 | lualine_y = { 'progress' }, 58 | lualine_z = { 'location' } 59 | }) 60 | ``` 61 | 62 | Contributions of configurations for other statusline plugins are appreciated. 63 | 64 | ## Contributing 65 | 66 | ### Contributing to code : 67 | 68 | - Fork it. 69 | - Commit your changes and give your commit message some love. 70 | - Push to your fork on github. 71 | - Open a Pull Request. 72 | 73 | ### Reporting an Issue : 74 | 75 | Use [Github Issue Tracker](https://github.com/dhruvasagar/vim-zoom/issues) 76 | 77 | ## Credits 78 | 79 | This plugin was heavily inspired by tmux's zoom pane feature. 80 | -------------------------------------------------------------------------------- /autoload/zoom.vim: -------------------------------------------------------------------------------- 1 | function! s:is_zoomed() 2 | return get(t:, 'zoomed', 0) 3 | endfunction 4 | 5 | function! s:is_only_window() 6 | return len(tabpagebuflist()) == 1 7 | endfunction 8 | 9 | function! s:set_zoomed(...) 10 | let t:zoomed = a:0 ? a:1 : 0 11 | endfunction 12 | 13 | function! s:clean_session_file() 14 | if exists('t:zoom_session_file') 15 | call delete(t:zoom_session_file) 16 | endif 17 | endfunction 18 | 19 | function! s:zoom_session_file() 20 | if !exists('t:zoom_session_file') 21 | let t:zoom_session_file = tempname().'_'.tabpagenr() 22 | if exists('##TabClosed') 23 | autocmd TabClosed * call s:clean_session_file() 24 | elseif exists('##TabLeave') 25 | autocmd TabLeave * call s:clean_session_file() 26 | end 27 | endif 28 | return t:zoom_session_file 29 | endfunction 30 | 31 | function! zoom#toggle() abort 32 | if s:is_zoomed() 33 | if exists('#User#ZoomPre') 34 | doautocmd User ZoomPre 35 | endif 36 | let cursor_pos = getpos('.') 37 | let l:current_buffer = bufnr('') 38 | exec 'silent! source' s:zoom_session_file() 39 | call setqflist(s:qflist) 40 | silent! exe 'b'.l:current_buffer 41 | call s:set_zoomed() 42 | call setpos('.', cursor_pos) 43 | if exists('#User#ZoomPost') 44 | doautocmd User ZoomPost 45 | endif 46 | else 47 | " skip if only window 48 | if s:is_only_window() | return | endif 49 | 50 | let oldsessionoptions = &sessionoptions 51 | let oldsession = v:this_session 52 | set sessionoptions-=tabpages 53 | if matchstr(&sessionoptions, 'sesdir') ==# '' 54 | set sessionoptions+=blank,buffers,curdir,terminal,help 55 | else 56 | set sessionoptions+=blank,buffers,terminal,help 57 | endif 58 | let s:qflist = getqflist() 59 | exec 'mksession!' s:zoom_session_file() 60 | wincmd o 61 | call s:set_zoomed(1) 62 | let v:this_session = oldsession 63 | let &sessionoptions = oldsessionoptions 64 | endif 65 | endfunction 66 | 67 | function! zoom#statusline() 68 | if s:is_zoomed() 69 | return get(g:, 'zoom#statustext', 'zoomed') 70 | endif 71 | return '' 72 | endfunction 73 | -------------------------------------------------------------------------------- /doc/zoom.txt: -------------------------------------------------------------------------------- 1 | *zoom.txt* Zoom Window in VIM *zoom* 2 | ------------------------------------------------------------------------------ 3 | 4 | Toggle current window zoom 5 | Inspired by tmux zoom 6 | Version 0.3.4 7 | 8 | 9 | Author: Dhruva Sagar (http://dhruvasagar.com) 10 | License: MIT (http://opensource.org/licenses/MIT) 11 | 12 | ------------------------------------------------------------------------------ 13 | CONTENTS *zoom-contents* 14 | 15 | 1. Usage ......................................... |zoom-usage| 16 | 2. Options ....................................... |zoom-options| 17 | 3. Mappings ...................................... |zoom-mappings| 18 | 4. Statusline .................................... |zoom-statusline| 19 | 5. Contributing .................................. |zoom-contributing| 20 | 6. Report Issues ................................. |zoom-report-issues| 21 | 7. Credits ....................................... |zoom-credits| 22 | 23 | ------------------------------------------------------------------------------ 24 | USAGE *zoom-usage* 25 | 26 | Use the provided mapping `m` on the current split and it will toggle 27 | it to zoom in and out on subsequent calls. 28 | 29 | ------------------------------------------------------------------------------ 30 | OPTIONS *zoom-options* 31 | 32 | *zoom-statustext* 33 | `g:zoom#statustext`: 34 | Sets the value to be returned by `zoom#statusline()` when zoomed 35 | in. > 36 | let g:zoom#statustext = 'zoomed' 37 | < 38 | *zoom-tmux_z* 39 | `g:zoom_tmux_z`: 40 | Enables the key binding `z` when not within tmux > 41 | let g:zoom_tmux_z = v:false 42 | < 43 | 44 | ------------------------------------------------------------------------------ 45 | MAPPINGS *zoom-mappings* 46 | 47 | `m`: mapping to toggle zoom of current window 48 | To change this mapping remap `(zoom-toggle)` to your 49 | desired mapping like so : > 50 | nmap (zoom-toggle) 51 | < 52 | `z`: mapping to toggle zoom of current window when not within 53 | a tmux session, enabled only if `g:zoom_tmux_z` is set to *v:true* 54 | 55 | ------------------------------------------------------------------------------ 56 | STATUSLINE *zoom-statusline* 57 | 58 | `zoom#statusline()`: 59 | If the current window is zoomed within the current tab, it returns 60 | value of option `g:zoom#statustext` otherwise it's an empty 61 | string. 62 | You may add it to your statusline using : > 63 | let statusline+=%{zoom#statusline()} 64 | < 65 | 66 | Example configuration for lualine.nvim > 67 | -- Set lualine options 68 | sections = { 69 | -- left 70 | lualine_a = { 'mode' }, 71 | lualine_b = { 'branch', 'diff', 'diagnostic' }, 72 | lualine_c = { 'filename' }, 73 | -- right 74 | lualine_x = { "vim.fn['zoom#statusline']()", 'encoding', 'fileformat', 'filetype' }, 75 | lualine_y = { 'progress' }, 76 | lualine_z = { 'location' } 77 | }) 78 | < 79 | ------------------------------------------------------------------------------ 80 | CONTRIBUTING *zoom-contributing* 81 | 82 | If you want to contribute, fork the repo, make changes and send a PR on 83 | Github at https://github.com/dhruvasagar/vim-zoom. 84 | 85 | ------------------------------------------------------------------------------ 86 | REPORT ISSUES *zoom-report-issues* 87 | 88 | If you discover any issues, please report them at 89 | https://github.com/dhruvasagar/vim-zoom/issues 90 | 91 | ------------------------------------------------------------------------------ 92 | CREDITS *zoom-credits* 93 | 94 | The idea is inspired heavily from tmux's zoom functionality 95 | -------------------------------------------------------------------------------- /plugin/zoom.vim: -------------------------------------------------------------------------------- 1 | if exists('g:loaded_zoom') 2 | finish 3 | endif 4 | let g:loaded_zoom = 1 5 | if !exists('g:zoom_tmux_z') 6 | let g:zoom_tmux_z = v:false 7 | endif 8 | 9 | nnoremap (zoom-toggle) :call zoom#toggle() 10 | 11 | if !hasmapto('(zoom-toggle)') 12 | nmap m (zoom-toggle) 13 | endif 14 | if empty($TMUX) && g:zoom_tmux_z == v:true 15 | nmap z (zoom-toggle) 16 | endif 17 | --------------------------------------------------------------------------------