mirror of
https://github.com/junegunn/goyo.vim.git
synced 2025-11-16 23:33:42 -05:00
Define CTRL-W mappings for resizing Goyo window (#46)
This commit is contained in:
@@ -28,11 +28,8 @@ Usage
|
|||||||
- `:Goyo!`
|
- `:Goyo!`
|
||||||
- Turn Goyo off
|
- Turn Goyo off
|
||||||
|
|
||||||
You might want to define a map for toggling it:
|
The window can be resized with the usual `[count]<CTRL-W>` + `>`, `<`, `+`,
|
||||||
|
`-` keys.
|
||||||
```vim
|
|
||||||
nnoremap <Leader>G :Goyo<CR>
|
|
||||||
```
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
|
|||||||
@@ -85,17 +85,21 @@ function! s:hmargin()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:resize_pads()
|
function! s:resize_pads()
|
||||||
|
let t:goyo_width = max([2, t:goyo_width])
|
||||||
|
let t:goyo_margin_top = min([max([2, t:goyo_margin_top]), &lines / 2 - 1])
|
||||||
|
let t:goyo_margin_bottom = min([max([2, t:goyo_margin_bottom]), &lines / 2 - 1])
|
||||||
|
|
||||||
let hmargin = s:hmargin()
|
let hmargin = s:hmargin()
|
||||||
let tmargin = get(g:, 'goyo_margin_top', 4)
|
|
||||||
let bmargin = get(g:, 'goyo_margin_bottom', 4)
|
|
||||||
|
|
||||||
augroup goyop
|
augroup goyop
|
||||||
autocmd!
|
autocmd!
|
||||||
augroup END
|
augroup END
|
||||||
call s:setup_pad(t:goyo_pads.t, 0, tmargin - 1, 'j')
|
call s:setup_pad(t:goyo_pads.t, 0, t:goyo_margin_top - 1, 'j')
|
||||||
call s:setup_pad(t:goyo_pads.b, 0, bmargin - 2, 'k')
|
call s:setup_pad(t:goyo_pads.b, 0, t:goyo_margin_bottom - 2, 'k')
|
||||||
call s:setup_pad(t:goyo_pads.l, 1, hmargin / 2 - 1, 'l')
|
call s:setup_pad(t:goyo_pads.l, 1, hmargin / 2 - 1, 'l')
|
||||||
call s:setup_pad(t:goyo_pads.r, 1, hmargin / 2 - 1, 'h')
|
call s:setup_pad(t:goyo_pads.r, 1, hmargin / 2 - 1, 'h')
|
||||||
|
|
||||||
|
let t:goyo_width = winwidth(0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:tranquilize()
|
function! s:tranquilize()
|
||||||
@@ -130,6 +134,29 @@ function! s:hide_linenr()
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:maps_nop()
|
||||||
|
let mapped = filter(['R', 'H', 'J', 'K', 'L', '|', '_', '='],
|
||||||
|
\ "empty(maparg(\"\<c-w>\".v:val, 'n'))")
|
||||||
|
for c in mapped
|
||||||
|
execute 'nnoremap <c-w>'.escape(c, '|').' <nop>'
|
||||||
|
endfor
|
||||||
|
return mapped
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:maps_resize()
|
||||||
|
let commands = {
|
||||||
|
\ '>': ':<c-u>let t:goyo_width = winwidth(0) + 2 * v:count1 <bar> call <sid>resize_pads()<cr>',
|
||||||
|
\ '<': ':<c-u>let t:goyo_width = winwidth(0) - 2 * v:count1 <bar> call <sid>resize_pads()<cr>',
|
||||||
|
\ '+': ':<c-u>let t:goyo_margin_top -= v:count1 <bar> let t:goyo_margin_bottom -= v:count1 <bar> call <sid>resize_pads()<cr>',
|
||||||
|
\ '-': ':<c-u>let t:goyo_margin_top += v:count1 <bar> let t:goyo_margin_bottom += v:count1 <bar> call <sid>resize_pads()<cr>'
|
||||||
|
\ }
|
||||||
|
let mapped = filter(keys(commands), "empty(maparg(\"\<c-w>\".v:val, 'n'))")
|
||||||
|
for c in mapped
|
||||||
|
execute 'nnoremap <silent> <c-w>'.c.' '.commands[c]
|
||||||
|
endfor
|
||||||
|
return mapped
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:goyo_on(width)
|
function! s:goyo_on(width)
|
||||||
let s:orig_tab = tabpagenr()
|
let s:orig_tab = tabpagenr()
|
||||||
|
|
||||||
@@ -138,6 +165,8 @@ function! s:goyo_on(width)
|
|||||||
|
|
||||||
let t:goyo_master = winbufnr(0)
|
let t:goyo_master = winbufnr(0)
|
||||||
let t:goyo_width = a:width
|
let t:goyo_width = a:width
|
||||||
|
let t:goyo_margin_top = get(g:, 'goyo_margin_top', 4)
|
||||||
|
let t:goyo_margin_bottom = get(g:, 'goyo_margin_bottom', 4)
|
||||||
let t:goyo_pads = {}
|
let t:goyo_pads = {}
|
||||||
let t:goyo_revert =
|
let t:goyo_revert =
|
||||||
\ { 'laststatus': &laststatus,
|
\ { 'laststatus': &laststatus,
|
||||||
@@ -151,6 +180,7 @@ function! s:goyo_on(width)
|
|||||||
\ 'sidescroll': &sidescroll,
|
\ 'sidescroll': &sidescroll,
|
||||||
\ 'sidescrolloff': &sidescrolloff
|
\ 'sidescrolloff': &sidescrolloff
|
||||||
\ }
|
\ }
|
||||||
|
let t:goyo_maps = extend(s:maps_nop(), s:maps_resize())
|
||||||
if has('gui_running')
|
if has('gui_running')
|
||||||
let t:goyo_revert.guioptions = &guioptions
|
let t:goyo_revert.guioptions = &guioptions
|
||||||
endif
|
endif
|
||||||
@@ -253,6 +283,10 @@ function! s:goyo_off()
|
|||||||
augroup END
|
augroup END
|
||||||
augroup! goyop
|
augroup! goyop
|
||||||
|
|
||||||
|
for c in t:goyo_maps
|
||||||
|
execute 'nunmap <c-w>'.escape(c, '|')
|
||||||
|
endfor
|
||||||
|
|
||||||
let goyo_revert = t:goyo_revert
|
let goyo_revert = t:goyo_revert
|
||||||
let goyo_disabled_gitgutter = t:goyo_disabled_gitgutter
|
let goyo_disabled_gitgutter = t:goyo_disabled_gitgutter
|
||||||
let goyo_disabled_signify = t:goyo_disabled_signify
|
let goyo_disabled_signify = t:goyo_disabled_signify
|
||||||
|
|||||||
Reference in New Issue
Block a user