54 Commits

Author SHA1 Message Date
Junegunn Choi
fa0263d456 Fix E1312 error after vim/vim@d63a855
Fix #275
2023-03-04 20:25:38 +09:00
Junegunn Choi
7f5d35a655 Add FAQ section 2022-09-05 14:13:33 +09:00
Junegunn Choi
d0bb582dd4 Create FUNDING.yml 2022-08-03 11:17:40 +09:00
Junegunn Choi
a9c7283dce Add LICENSE
Close #235
2021-11-18 10:25:37 +09:00
Junegunn Choi
a865dec7ca Remove :PlugInstall tag 2020-08-29 10:42:33 +09:00
Greg Anders
3e129198bb Fix signify detection (#223)
Fix #222
2020-06-09 08:37:04 +09:00
David Ben Knoble
6b6ed27340 Revert to nested for backwards compat 2019-06-13 16:22:44 +02:00
David Ben Knoble
e3ed30fdb1 Add ++nested modifier to TabLeave autocommand
This allows autocommands to fire for commands during s:goyo_off.

A prominent example would be any autocommands user's installed on the
ColorScheme event (e.g., to set User highlights, like @benknoble does in
his Dotfiles).
2019-06-13 16:22:44 +02:00
Erich Gubler
012290431a Fix tmux invocation conditions in README
There are two cases where the current documentation would cause issues:
1. `tmux` isn't available in `$PATH`.
2. The current terminal isn' actually running `tmux`.
2019-04-30 00:11:06 +09:00
Michael Gaffney
1897929092 Allow 'goyo.txt' to be listed in the LOCAL ADDITIONS section of help.txt
The first field on the first line of a help file should be a link to the
help file name. (See :h help-writing)
2019-04-29 13:32:49 +09:00
Junegunn Choi
057fe68e44 Describe CTRL-W = in the documentation
Duplicate of #79
Close #193
Close #172
2019-02-20 16:58:19 +09:00
orland0m
5b8bd03787 Added .gitignore (#153) 2017-06-01 02:17:29 +09:00
Junegunn Choi
64e750f726 Deduplicate help tag 2017-04-02 04:27:22 +09:00
Junegunn Choi
204f65b2d1 Add doc/goyo.txt converted from README.md
Close #145
Close #144
2017-04-01 11:25:36 +09:00
J
14696abd45 Fix set_color to use gui_running or termguicolors (#140)
Close #139
2017-03-09 15:25:13 +09:00
Junegunn Choi
ebdd67fd61 No need to manually fill statusline with spaces 2017-01-03 00:49:29 +09:00
Junegunn Choi
2fd0fcb691 Use space as fillchars:stl 2017-01-03 00:42:26 +09:00
Junegunn Choi
8e8f1d45b6 Resize windows after TermClose on Neovim
Based on the patch submitted by @romanoaugusto88 (#108).

Close #97.
2016-04-03 20:20:16 +09:00
Junegunn Choi
53b808d777 Merge pull request #107 from Starefossen/patch-1
README: Toggle tmux zoom when entering and leaving Goyo
2016-03-30 19:51:54 +09:00
Hans Kristian Flaatten
0f298fe1fa Toggle tmux full-screen pane when entering and leaving Goyo 2016-03-30 11:56:04 +02:00
Junegunn Choi
9a10a306f3 Merge pull request #102 from rperce/master
Fix for lightline naming convention change
2016-03-17 15:56:39 +09:00
Robert Perce
26f06ba05c Use single quotes wherever possible 2016-03-17 01:11:14 -05:00
Robert Perce
9cea5e5c7d Fix lightline check, per itchyny/lightline.vim@0f62126 2016-03-17 01:09:30 -05:00
Junegunn Choi
cb697998cc Check bg# attribute instead of bg (#92)
On GVim:
  hi StatusLine guibg=red
  echo synIDattr(synIDtrans(hlID('StatusLine')), 'bg')
    " red
  echo synIDattr(synIDtrans(hlID('StatusLine')), 'bg#')
    " #ff0000
2016-02-15 10:40:13 +09:00
Junegunn Choi
8faad54942 Fix #92 - Workaround for Neovim truecolor support 2016-02-15 00:38:14 +09:00
Junegunn Choi
630f5d8086 Do not ignore messages from goyo callbacks
Related: #16
/cc @kminh
2015-11-15 15:18:04 +09:00
Junegunn Choi
635109f514 Restart Goyo on :Goyo DIM when surrounding windows are gone
Close #83
2015-10-13 02:17:16 +09:00
Junegunn Choi
c1293a91a3 Merge pull request #75 from thirtythreeforty/airline-bugfix
Avoid rendering issues in Airline
2015-08-08 13:07:10 +09:00
George Hilliard
eb12d053a1 Avoid rendering issues in Airline
Closes #63.
2015-08-07 13:57:08 -05:00
Junegunn Choi
eb4ec21fe6 autocmd! 2015-05-19 14:09:13 +09:00
Junegunn Choi
f660ca376e Add g:goyo_height and deprecate g:goyo_margin_{top,bottom} 2015-05-05 22:59:00 +09:00
Junegunn Choi
dbcb337b22 Do not change xoff and yoff on resize 2015-05-05 15:16:38 +09:00
Junegunn Choi
fb5d2dc1b9 Update README 2015-05-05 14:50:40 +09:00
Junegunn Choi
eed886c0c8 Extended dimension expression (#68) 2015-05-05 14:36:31 +09:00
Junegunn Choi
26f06e2272 Save settings before opening a new tab (#58)
Problem identified by @ches
2015-02-20 01:07:14 +09:00
Junegunn Choi
b447d34143 Move the code to autoload directory (#55)
Thanks to @edkolev
2015-01-31 01:28:25 +09:00
Junegunn Choi
f9d0a69eaa Map CTRL-W = for restoring the initial size (#53) 2015-01-26 19:17:23 +09:00
Junegunn Choi
e7eb3f19cc Define CTRL-W mappings for resizing Goyo window (#46) 2014-11-26 01:26:17 +09:00
Junegunn Choi
b16a80ac9e Allow switching of buffers in Goyo mode (Fix #31) 2014-11-24 02:24:15 +09:00
Junegunn Choi
8b74a603e5 Hide statusline on WinEnter and WinLeave 2014-09-22 12:19:48 +09:00
Junegunn Choi
9eadf29430 Update README: GoyoEnter and GoyoLeave as nested
- in case you change colorscheme inside them
2014-09-01 17:09:45 +09:00
Junegunn Choi
9e04ccdb9d Promote the use of User events instead of g:goyo_callbacks
This does not break backward compatibility, g:goyo_callbacks is still
allowed.
2014-08-11 02:16:31 +09:00
Junegunn Choi
da67185e4a Fix error when vim-signify is not installed (#39) 2014-07-26 23:50:54 +09:00
Junegunn Choi
e2c59124cb Merge pull request #39 from prurigro/toggle-signify
Added vim-signify to the list of toggled plugins
2014-07-26 23:46:18 +09:00
Kevin MacMartin
27ea8fa731 Following junegunn's advice, both checks are made together 2014-07-23 23:19:04 -04:00
Kevin MacMartin
ae04751e09 Added git-signify to the list of toggled plugins 2014-07-20 23:39:13 -04:00
Junegunn Choi
85c202264e Update callback examples in README 2014-07-21 01:42:04 +09:00
Junegunn Choi
2bc0604530 Update README 2014-07-05 23:18:51 +09:00
Junegunn Choi
549f865ab4 Add Goyo! command for turning it off 2014-07-05 23:13:13 +09:00
Junegunn Choi
a2b772fe58 Never allow cursor on pad windows 2014-07-04 02:56:46 +09:00
Junegunn Choi
7e318dbcce Fix winminwidth issue (#35) 2014-07-03 23:37:29 +09:00
Junegunn Choi
f303dc9307 Best served with limelight.vim 2014-07-03 01:41:31 +09:00
Junegunn Choi
ad87a5b35a Doc update: Function name must start with a capital
see: ftp://ftp.vim.org/pub/vim/patches/7.4/7.4.260
2014-06-03 10:14:27 +09:00
Junegunn Choi
5bea57ebf5 Retain cursor position on close (#27)
This however doesn't work if Goyo window is closed with `:q`
2014-04-28 12:29:33 +09:00
7 changed files with 745 additions and 309 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
github: junegunn

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
doc/tags

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013-2021 Junegunn Choi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

123
README.md
View File

@@ -7,6 +7,8 @@ Distraction-free writing in Vim.
(Color scheme: [seoul256](https://github.com/junegunn/seoul256.vim))
Best served with [limelight.vim](https://github.com/junegunn/limelight.vim).
Installation
------------
@@ -19,59 +21,141 @@ Use your favorite plugin manager.
Usage
-----
`:Goyo [width]`
- `:Goyo`
- Toggle Goyo
- `:Goyo [dimension]`
- Turn on or resize Goyo
- `:Goyo!`
- Turn Goyo off
The window can be resized with the usual `[count]<CTRL-W>` + `>`, `<`, `+`,
`-` keys, and `<CTRL-W>` + `=` will resize it back to the initial size.
### Dimension expression
The expected format of a dimension expression is
`[WIDTH][XOFFSET][x[HEIGHT][YOFFSET]]`. `XOFFSET` and `YOFFSET` should be
prefixed by `+` or `-`. Each component can be given in percentage.
You might map this to a key combo in your `.vimrc` like so:
```vim
"" Map Goyo toggle to <Leader> + spacebar
nnoremap <Leader><Space> :Goyo<CR>
" Width
Goyo 120
" Height
Goyo x30
" Both
Goyo 120x30
" In percentage
Goyo 120x50%
" With offsets
Goyo 50%+25%x50%-25%
```
Configuration
-------------
- `g:goyo_width` (default: 80)
- `g:goyo_margin_top` (default: 4)
- `g:goyo_margin_bottom` (default: 4)
- `g:goyo_height` (default: 85%)
- `g:goyo_linenr` (default: 0)
- `g:goyo_callbacks` ([before_funcref, after_funcref])
### Callbacks
By default, [vim-airline](https://github.com/bling/vim-airline),
[vim-powerline](https://github.com/Lokaltog/vim-powerline),
[powerline](https://github.com/Lokaltog/powerline),
[lightline.vim](https://github.com/itchyny/lightline.vim), and
[vim-gitgutter](https://github.com/airblade/vim-gitgutter) are temporarily
[lightline.vim](https://github.com/itchyny/lightline.vim),
[vim-signify](https://github.com/mhinz/vim-signify),
and [vim-gitgutter](https://github.com/airblade/vim-gitgutter) are temporarily
disabled while in Goyo mode.
If you have other plugins that you want to disable/enable, or if you want to
change the default settings of Goyo window, you can define before and after
callbacks as follows in your .vimrc.
change the default settings of Goyo window, you can set up custom routines
to be triggered on `GoyoEnter` and `GoyoLeave` events.
```vim
function! s:goyo_before()
silent !tmux set status off
function! s:goyo_enter()
if executable('tmux') && strlen($TMUX)
silent !tmux set status off
silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
endif
set noshowmode
set noshowcmd
set scrolloff=999
Limelight
" ...
endfunction
function! s:goyo_after()
silent !tmux set status on
function! s:goyo_leave()
if executable('tmux') && strlen($TMUX)
silent !tmux set status on
silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
endif
set showmode
set showcmd
set scrolloff=5
Limelight!
" ...
endfunction
let g:goyo_callbacks = [function('s:goyo_before'), function('s:goyo_after')]
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
```
More examples can be found here:
[Customization](https://github.com/junegunn/goyo.vim/wiki/Customization)
(If you get the error `Unknown function: s:goyo_before`, define the callback
functions as globals. e.g. `g:goyo_before`)
FAQ
---
> _"My custom colors are lost when I exit Goyo!"_
That's because Goyo restores the base color scheme using `:colorscheme
CURRENT_COLOR_SCHEME` command on exit, and it resets your tweaks. Goyo can try
to remember all your customizations and restore them on exit, but it doesn't,
because there is a better, more robust way to address the issue.
The real problem here is that you will lose all your changes when you switch
between color schemes, even when you're not using Goyo.
```vim
" In your Vim configuration file
" - Base color scheme
colorscheme molokai
" - Your color customizations
hi LineNr ctermfg=red guifg=red
```
It works, only when you stick to a single color scheme. When you switch
between color schemes,
```vim
" Switch to another color scheme
colorscheme Tomorrow-Night
" Switch back to the original one
colorscheme molokai
```
And all the customizations you have made are lost.
What you should to do is to customize the colors on `autocmd ColorScheme`,
which is automatically triggered whenever you change color schemes.
```vim
function! s:tweak_molokai_colors()
" Your molokai customizations
hi LineNr ...
hi FoldColumn ...
endfunction
autocmd! ColorScheme molokai call s:tweak_molokai_colors()
colorscheme molokai
```
Inspiration
-----------
@@ -85,8 +169,7 @@ Pros.
1. Works well with splits. Doesn't mess up with the current window arrangement
1. Works well with popular statusline plugins
1. Prevents accessing the empty windows around the central buffer
1. Can be closed with any of `:q[uit]`, `:clo[se]`, `:tabc[lose]`, `:bd[elete]`,
or `:Goyo`
1. Can be closed with any of `:q[uit]`, `:clo[se]`, `:tabc[lose]`, or `:Goyo`
1. Can dynamically change the width of the window
1. Adjusts its colors when color scheme is changed
1. Realigns the window when the terminal (or window) is resized or when the size

449
autoload/goyo.vim Normal file
View File

@@ -0,0 +1,449 @@
" Copyright (c) 2015 Junegunn Choi
"
" MIT License
"
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be
" included in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
" LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
let s:cpo_save = &cpo
set cpo&vim
function! s:const(val, min, max)
return min([max([a:val, a:min]), a:max])
endfunction
function! s:get_color(group, attr)
return synIDattr(synIDtrans(hlID(a:group)), a:attr)
endfunction
function! s:set_color(group, attr, color)
let gui = has('gui_running') || has('termguicolors') && &termguicolors
execute printf('hi %s %s%s=%s', a:group, gui ? 'gui' : 'cterm', a:attr, a:color)
endfunction
nnoremap <silent> <Plug>(goyo-off) :call <sid>goyo_off()<cr>
function! s:blank(repel)
if bufwinnr(t:goyo_pads.r) <= bufwinnr(t:goyo_pads.l) + 1
\ || bufwinnr(t:goyo_pads.b) <= bufwinnr(t:goyo_pads.t) + 3
call feedkeys("\<Plug>(goyo-off)")
endif
execute 'noautocmd wincmd' a:repel
endfunction
function! s:init_pad(command)
execute a:command
setlocal buftype=nofile bufhidden=wipe nomodifiable nobuflisted noswapfile
\ nonu nocursorline nocursorcolumn winfixwidth winfixheight statusline=\
if exists('&rnu')
setlocal nornu
endif
if exists('&colorcolumn')
setlocal colorcolumn=
endif
let bufnr = winbufnr(0)
execute winnr('#') . 'wincmd w'
return bufnr
endfunction
function! s:setup_pad(bufnr, vert, size, repel)
let win = bufwinnr(a:bufnr)
execute win . 'wincmd w'
execute (a:vert ? 'vertical ' : '') . 'resize ' . max([0, a:size])
augroup goyop
execute 'autocmd WinEnter,CursorMoved <buffer> nested call s:blank("'.a:repel.'")'
autocmd WinLeave <buffer> call s:hide_statusline()
augroup END
" To hide scrollbars of pad windows in GVim
let diff = winheight(0) - line('$') - (has('gui_running') ? 2 : 0)
if diff > 0
setlocal modifiable
call append(0, map(range(1, diff), '""'))
normal! gg
setlocal nomodifiable
endif
execute winnr('#') . 'wincmd w'
endfunction
function! s:resize_pads()
augroup goyop
autocmd!
augroup END
let t:goyo_dim.width = s:const(t:goyo_dim.width, 2, &columns)
let t:goyo_dim.height = s:const(t:goyo_dim.height, 2, &lines)
let vmargin = max([0, (&lines - t:goyo_dim.height) / 2 - 1])
let yoff = s:const(t:goyo_dim.yoff, - vmargin, vmargin)
let top = vmargin + yoff
let bot = vmargin - yoff - 1
call s:setup_pad(t:goyo_pads.t, 0, top, 'j')
call s:setup_pad(t:goyo_pads.b, 0, bot, 'k')
let nwidth = max([len(string(line('$'))) + 1, &numberwidth])
let width = t:goyo_dim.width + (&number ? nwidth : 0)
let hmargin = max([0, (&columns - width) / 2 - 1])
let xoff = s:const(t:goyo_dim.xoff, - hmargin, hmargin)
call s:setup_pad(t:goyo_pads.l, 1, hmargin + xoff, 'l')
call s:setup_pad(t:goyo_pads.r, 1, hmargin - xoff, 'h')
endfunction
function! s:tranquilize()
let bg = s:get_color('Normal', 'bg#')
for grp in ['NonText', 'FoldColumn', 'ColorColumn', 'VertSplit',
\ 'StatusLine', 'StatusLineNC', 'SignColumn']
" -1 on Vim / '' on GVim
if bg == -1 || empty(bg)
call s:set_color(grp, 'fg', get(g:, 'goyo_bg', 'black'))
call s:set_color(grp, 'bg', 'NONE')
else
call s:set_color(grp, 'fg', bg)
call s:set_color(grp, 'bg', bg)
endif
call s:set_color(grp, '', 'NONE')
endfor
endfunction
function! s:hide_statusline()
setlocal statusline=\
endfunction
function! s:hide_linenr()
if !get(g:, 'goyo_linenr', 0)
setlocal nonu
if exists('&rnu')
setlocal nornu
endif
endif
if exists('&colorcolumn')
setlocal colorcolumn=
endif
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_dim = <sid>parse_arg(t:goyo_dim_expr) <bar> call <sid>resize_pads()<cr>',
\ '>': ':<c-u>let t:goyo_dim.width = winwidth(0) + 2 * v:count1 <bar> call <sid>resize_pads()<cr>',
\ '<': ':<c-u>let t:goyo_dim.width = winwidth(0) - 2 * v:count1 <bar> call <sid>resize_pads()<cr>',
\ '+': ':<c-u>let t:goyo_dim.height += 2 * v:count1 <bar> call <sid>resize_pads()<cr>',
\ '-': ':<c-u>let t:goyo_dim.height -= 2 * 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
nnoremap <silent> <plug>(goyo-resize) :<c-u>call <sid>resize_pads()<cr>
function! s:goyo_on(dim)
let dim = s:parse_arg(a:dim)
if empty(dim)
return
endif
let s:orig_tab = tabpagenr()
let settings =
\ { 'laststatus': &laststatus,
\ 'showtabline': &showtabline,
\ 'fillchars': &fillchars,
\ 'winminwidth': &winminwidth,
\ 'winwidth': &winwidth,
\ 'winminheight': &winminheight,
\ 'winheight': &winheight,
\ 'ruler': &ruler,
\ 'sidescroll': &sidescroll,
\ 'sidescrolloff': &sidescrolloff
\ }
" New tab
tab split
let t:goyo_master = winbufnr(0)
let t:goyo_dim = dim
let t:goyo_dim_expr = a:dim
let t:goyo_pads = {}
let t:goyo_revert = settings
let t:goyo_maps = extend(s:maps_nop(), s:maps_resize())
if has('gui_running')
let t:goyo_revert.guioptions = &guioptions
endif
" vim-gitgutter
let t:goyo_disabled_gitgutter = get(g:, 'gitgutter_enabled', 0)
if t:goyo_disabled_gitgutter
silent! GitGutterDisable
endif
" vim-signify
let t:goyo_disabled_signify = !empty(getbufvar(bufnr(''), 'sy'))
if t:goyo_disabled_signify
SignifyToggle
endif
" vim-airline
let t:goyo_disabled_airline = exists('#airline')
if t:goyo_disabled_airline
AirlineToggle
endif
" vim-powerline
let t:goyo_disabled_powerline = exists('#PowerlineMain')
if t:goyo_disabled_powerline
augroup PowerlineMain
autocmd!
augroup END
augroup! PowerlineMain
endif
" lightline.vim
let t:goyo_disabled_lightline = exists('#lightline')
if t:goyo_disabled_lightline
silent! call lightline#disable()
endif
call s:hide_linenr()
" Global options
let &winheight = max([&winminheight, 1])
set winminheight=1
set winheight=1
set winminwidth=1 winwidth=1
set laststatus=0
set showtabline=0
set noruler
set fillchars+=vert:\
set fillchars+=stl:\
set fillchars+=stlnc:\
set sidescroll=1
set sidescrolloff=0
" Hide left-hand scrollbars
if has('gui_running')
set guioptions-=l
set guioptions-=L
endif
let t:goyo_pads.l = s:init_pad('vertical topleft new')
let t:goyo_pads.r = s:init_pad('vertical botright new')
let t:goyo_pads.t = s:init_pad('topleft new')
let t:goyo_pads.b = s:init_pad('botright new')
call s:resize_pads()
call s:tranquilize()
augroup goyo
autocmd!
autocmd TabLeave * nested call s:goyo_off()
autocmd VimResized * call s:resize_pads()
autocmd ColorScheme * call s:tranquilize()
autocmd BufWinEnter * call s:hide_linenr() | call s:hide_statusline()
autocmd WinEnter,WinLeave * call s:hide_statusline()
if has('nvim')
autocmd TermClose * call feedkeys("\<plug>(goyo-resize)")
endif
augroup END
call s:hide_statusline()
if exists('g:goyo_callbacks[0]')
call g:goyo_callbacks[0]()
endif
if exists('#User#GoyoEnter')
doautocmd User GoyoEnter
endif
endfunction
function! s:goyo_off()
if !exists('#goyo')
return
endif
" Oops, not this tab
if !exists('t:goyo_revert')
return
endif
" Clear auto commands
augroup goyo
autocmd!
augroup END
augroup! goyo
augroup goyop
autocmd!
augroup END
augroup! goyop
for c in t:goyo_maps
execute 'nunmap <c-w>'.escape(c, '|')
endfor
let goyo_revert = t:goyo_revert
let goyo_disabled_gitgutter = t:goyo_disabled_gitgutter
let goyo_disabled_signify = t:goyo_disabled_signify
let goyo_disabled_airline = t:goyo_disabled_airline
let goyo_disabled_powerline = t:goyo_disabled_powerline
let goyo_disabled_lightline = t:goyo_disabled_lightline
let goyo_orig_buffer = t:goyo_master
let [line, col] = [line('.'), col('.')]
if tabpagenr() == 1
tabnew
normal! gt
bd
endif
tabclose
execute 'normal! '.s:orig_tab.'gt'
if winbufnr(0) == goyo_orig_buffer
" Doesn't work if window closed with `q`
execute printf('normal! %dG%d|', line, col)
endif
let wmw = remove(goyo_revert, 'winminwidth')
let ww = remove(goyo_revert, 'winwidth')
let &winwidth = ww
let &winminwidth = wmw
let wmh = remove(goyo_revert, 'winminheight')
let wh = remove(goyo_revert, 'winheight')
let &winheight = max([wmh, 1])
let &winminheight = wmh
let &winheight = wh
for [k, v] in items(goyo_revert)
execute printf('let &%s = %s', k, string(v))
endfor
execute 'colo '. get(g:, 'colors_name', 'default')
if goyo_disabled_gitgutter
silent! GitGutterEnable
endif
if goyo_disabled_signify
silent! if !b:sy.active
SignifyToggle
endif
endif
if goyo_disabled_airline && !exists('#airline')
AirlineToggle
" For some reason, Airline requires two refreshes to avoid display
" artifacts
silent! AirlineRefresh
silent! AirlineRefresh
endif
if goyo_disabled_powerline && !exists('#PowerlineMain')
doautocmd PowerlineStartup VimEnter
silent! PowerlineReloadColorscheme
endif
if goyo_disabled_lightline
silent! call lightline#enable()
endif
if exists('#Powerline')
doautocmd Powerline ColorScheme
endif
if exists('g:goyo_callbacks[1]')
call g:goyo_callbacks[1]()
endif
if exists('#User#GoyoLeave')
doautocmd User GoyoLeave
endif
endfunction
function! s:relsz(expr, limit)
if a:expr !~ '%$'
return str2nr(a:expr)
endif
return a:limit * str2nr(a:expr[:-2]) / 100
endfunction
function! s:parse_arg(arg)
if exists('g:goyo_height') || !exists('g:goyo_margin_top') && !exists('g:goyo_margin_bottom')
let height = s:relsz(get(g:, 'goyo_height', '85%'), &lines)
let yoff = 0
else
let top = max([0, s:relsz(get(g:, 'goyo_margin_top', 4), &lines)])
let bot = max([0, s:relsz(get(g:, 'goyo_margin_bottom', 4), &lines)])
let height = &lines - top - bot
let yoff = top - bot
endif
let dim = { 'width': s:relsz(get(g:, 'goyo_width', 80), &columns),
\ 'height': height,
\ 'xoff': 0,
\ 'yoff': yoff }
if empty(a:arg)
return dim
endif
let parts = matchlist(a:arg, '^\s*\([0-9]\+%\?\)\?\([+-][0-9]\+%\?\)\?\%(x\([0-9]\+%\?\)\?\([+-][0-9]\+%\?\)\?\)\?\s*$')
if empty(parts)
echohl WarningMsg
echo 'Invalid dimension expression: '.a:arg
echohl None
return {}
endif
if !empty(parts[1]) | let dim.width = s:relsz(parts[1], &columns) | endif
if !empty(parts[2]) | let dim.xoff = s:relsz(parts[2], &columns) | endif
if !empty(parts[3]) | let dim.height = s:relsz(parts[3], &lines) | endif
if !empty(parts[4]) | let dim.yoff = s:relsz(parts[4], &lines) | endif
return dim
endfunction
function! goyo#execute(bang, dim)
if a:bang
if exists('#goyo')
call s:goyo_off()
endif
else
if exists('#goyo') == 0
call s:goyo_on(a:dim)
elseif !empty(a:dim)
if winnr('$') < 5
call s:goyo_off()
return goyo#execute(a:bang, a:dim)
endif
let dim = s:parse_arg(a:dim)
if !empty(dim)
let t:goyo_dim = dim
let t:goyo_dim_expr = a:dim
call s:resize_pads()
endif
else
call s:goyo_off()
end
end
endfunction
let &cpo = s:cpo_save
unlet s:cpo_save

168
doc/goyo.txt Normal file
View File

@@ -0,0 +1,168 @@
*goyo.txt* goyo Last change: April 2 2017
GOYO - TABLE OF CONTENTS *goyo* *goyo-toc*
==============================================================================
goyo.vim (고요)
Installation
Usage
Dimension expression
Configuration
Callbacks
Inspiration
Pros.
License
GOYO.VIM (고요) *goyo-vim*
==============================================================================
Distraction-free writing in Vim.
https://raw.github.com/junegunn/i/master/goyo.png
(Color scheme: {seoul256}{1})
Best served with {limelight.vim}{2}.
{1} https://github.com/junegunn/seoul256.vim
{2} https://github.com/junegunn/limelight.vim
INSTALLATION *goyo-installation*
==============================================================================
Use your favorite plugin manager.
- {vim-plug}{3}
1. Add `Plug'junegunn/goyo.vim'` to .vimrc
2. Run `:PlugInstall`
{3} https://github.com/junegunn/vim-plug
USAGE *goyo-usage*
==============================================================================
*:Goyo*
- `:Goyo`
- Toggle Goyo
- `:Goyo[dimension]`
- Turn on or resize Goyo
- `:Goyo!`
- Turn Goyo off
The window can be resized with the usual [count]`CTRL-W` + `>`, `<`, `+`, `-` keys,
and `CTRL-W` + `=` will resize it back to the initial size.
< Dimension expression >______________________________________________________~
*goyo-dimension-expression*
The expected format of a dimension expression is
`[WIDTH][XOFFSET][x[HEIGHT][YOFFSET]]`. `XOFFSET` and `YOFFSET` should be
prefixed by `+` or `-`. Each component can be given in percentage.
>
" Width
Goyo 120
" Height
Goyo x30
" Both
Goyo 120x30
" In percentage
Goyo 120x50%
" With offsets
Goyo 50%+25%x50%-25%
<
CONFIGURATION *goyo-configuration*
==============================================================================
*g:goyo_width* *g:goyo_height* *g:goyo_linenr*
- `g:goyo_width` (default: 80)
- `g:goyo_height` (default: 85%)
- `g:goyo_linenr` (default: 0)
< Callbacks >_________________________________________________________________~
*goyo-callbacks*
By default, {vim-airline}{4}, {vim-powerline}{5}, {powerline}{6},
{lightline.vim}{7}, {vim-signify}{8}, and {vim-gitgutter}{9} are temporarily
disabled while in Goyo mode.
If you have other plugins that you want to disable/enable, or if you want to
change the default settings of Goyo window, you can set up custom routines to
be triggered on `GoyoEnter` and `GoyoLeave` events.
>
function! s:goyo_enter()
silent !tmux set status off
silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
set noshowmode
set noshowcmd
set scrolloff=999
Limelight
" ...
endfunction
function! s:goyo_leave()
silent !tmux set status on
silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
set showmode
set showcmd
set scrolloff=5
Limelight!
" ...
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
<
More examples can be found here: {Customization}{10}
{4} https://github.com/bling/vim-airline
{5} https://github.com/Lokaltog/vim-powerline
{6} https://github.com/Lokaltog/powerline
{7} https://github.com/itchyny/lightline.vim
{8} https://github.com/mhinz/vim-signify
{9} https://github.com/airblade/vim-gitgutter
{10} https://github.com/junegunn/goyo.vim/wiki/Customization
INSPIRATION *goyo-inspiration*
==============================================================================
- {LiteDFM}{11}
- {VimRoom}{12}
{11} https://github.com/bilalq/lite-dfm
{12} http://projects.mikewest.org/vimroom/
PROS. *goyo-pros*
==============================================================================
1. Works well with splits. Doesn't mess up with the current window arrangement
2. Works well with popular statusline plugins
3. Prevents accessing the empty windows around the central buffer
4. Can be closed with any of `:q[uit]`, `:clo[se]`, `:tabc[lose]`, or `:Goyo`
5. Can dynamically change the width of the window
6. Adjusts its colors when color scheme is changed
7. Realigns the window when the terminal (or window) is resized or when the size
of the font is changed
8. Correctly hides colorcolumns and Emojis in statusline
9. Highly customizable with callbacks
LICENSE *goyo-license*
==============================================================================
MIT
==============================================================================
vim:tw=78:sw=2:ts=2:ft=help:norl:nowrap:

View File

@@ -1,4 +1,4 @@
" Copyright (c) 2013 Junegunn Choi
" Copyright (c) 2015 Junegunn Choi
"
" MIT License
"
@@ -21,291 +21,4 @@
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
let s:cpo_save = &cpo
set cpo&vim
function! s:get_color(group, attr)
return synIDattr(synIDtrans(hlID(a:group)), a:attr)
endfunction
function! s:set_color(group, attr, color)
let gui = has('gui_running')
execute printf("hi %s %s%s=%s", a:group, gui ? 'gui' : 'cterm', a:attr, a:color)
endfunction
function! s:blank()
let main = bufwinnr(t:goyo_master)
if main != -1
execute main . 'wincmd w'
else
call s:goyo_off()
endif
endfunction
function! s:init_pad(command)
execute a:command
setlocal buftype=nofile bufhidden=wipe nomodifiable nobuflisted noswapfile
\ nonu nocursorline nocursorcolumn winfixwidth winfixheight statusline=\
if exists('&rnu')
setlocal nornu
endif
if exists('&colorcolumn')
setlocal colorcolumn=
endif
let bufnr = winbufnr(0)
execute winnr('#') . 'wincmd w'
return bufnr
endfunction
function! s:setup_pad(bufnr, vert, size)
let win = bufwinnr(a:bufnr)
execute win . 'wincmd w'
execute (a:vert ? 'vertical ' : '') . 'resize ' . max([0, a:size])
augroup goyop
autocmd WinEnter <buffer> call s:blank()
augroup END
" To hide scrollbars of pad windows in GVim
let diff = winheight(0) - line('$') - (has('gui_running') ? 2 : 0)
if diff > 0
setlocal modifiable
call append(0, map(range(1, diff), '""'))
normal! gg
setlocal nomodifiable
endif
execute winnr('#') . 'wincmd w'
endfunction
function! s:hmargin()
let nwidth = max([len(string(line('$'))) + 1, &numberwidth])
let width = t:goyo_width + (&number ? nwidth : 0)
return (&columns - width)
endfunction
function! s:resize_pads()
let hmargin = s:hmargin()
let tmargin = get(g:, 'goyo_margin_top', 4)
let bmargin = get(g:, 'goyo_margin_bottom', 4)
augroup goyop
autocmd!
augroup END
call s:setup_pad(t:goyo_pads.t, 0, tmargin - 1)
call s:setup_pad(t:goyo_pads.b, 0, bmargin - 2)
call s:setup_pad(t:goyo_pads.l, 1, hmargin / 2 - 1)
call s:setup_pad(t:goyo_pads.r, 1, hmargin / 2 - 1)
endfunction
function! s:tranquilize()
let bg = s:get_color('Normal', 'bg')
for grp in ['NonText', 'FoldColumn', 'ColorColumn', 'VertSplit',
\ 'StatusLine', 'StatusLineNC', 'SignColumn']
" -1 on Vim / '' on GVim
if bg == -1 || empty(bg)
call s:set_color(grp, 'fg', get(g:, 'goyo_bg', 'black'))
call s:set_color(grp, 'bg', 'NONE')
else
call s:set_color(grp, 'fg', bg)
call s:set_color(grp, 'bg', bg)
endif
call s:set_color(grp, '', 'NONE')
endfor
endfunction
function! s:goyo_on(width)
let s:orig_tab = tabpagenr()
" New tab
tab split
let t:goyo_master = winbufnr(0)
let t:goyo_width = a:width
let t:goyo_pads = {}
let t:goyo_revert =
\ { 'laststatus': &laststatus,
\ 'showtabline': &showtabline,
\ 'fillchars': &fillchars,
\ 'winwidth': &winwidth,
\ 'winminheight': &winminheight,
\ 'winheight': &winheight,
\ 'statusline': &statusline,
\ 'ruler': &ruler,
\ 'sidescroll': &sidescroll,
\ 'sidescrolloff': &sidescrolloff
\ }
if has('gui_running')
let t:goyo_revert.guioptions = &guioptions
endif
" vim-gitgutter
let t:goyo_disabled_gitgutter = get(g:, 'gitgutter_enabled', 0)
if t:goyo_disabled_gitgutter
silent! GitGutterDisable
endif
" vim-airline
let t:goyo_disabled_airline = exists("#airline")
if t:goyo_disabled_airline
AirlineToggle
endif
" vim-powerline
let t:goyo_disabled_powerline = exists("#PowerlineMain")
if t:goyo_disabled_powerline
augroup PowerlineMain
autocmd!
augroup END
augroup! PowerlineMain
endif
" lightline.vim
let t:goyo_disabled_lightline = exists('#LightLine')
if t:goyo_disabled_lightline
silent! call lightline#disable()
endif
if !get(g:, 'goyo_linenr', 0)
setlocal nonu
if exists('&rnu')
setlocal nornu
endif
endif
if exists('&colorcolumn')
setlocal colorcolumn=
endif
" Global options
set winwidth=1
let &winheight = max([&winminheight, 1])
set winminheight=1
set winheight=1
set laststatus=0
set showtabline=0
set noruler
set fillchars+=vert:\
set fillchars+=stl:.
set fillchars+=stlnc:\
set sidescroll=1
set sidescrolloff=0
" Hide left-hand scrollbars
if has('gui_running')
set guioptions-=l
set guioptions-=L
endif
let t:goyo_pads.l = s:init_pad('vertical topleft new')
let t:goyo_pads.r = s:init_pad('vertical botright new')
let t:goyo_pads.t = s:init_pad('topleft new')
let t:goyo_pads.b = s:init_pad('botright new')
call s:resize_pads()
call s:tranquilize()
let &statusline = repeat(' ', winwidth(0))
augroup goyo
autocmd!
autocmd BufWinLeave <buffer> call s:goyo_off()
autocmd TabLeave * call s:goyo_off()
autocmd VimResized * call s:resize_pads()
autocmd ColorScheme * call s:tranquilize()
augroup END
if exists('g:goyo_callbacks[0]')
call g:goyo_callbacks[0]()
endif
endfunction
function! s:goyo_off()
if !exists('#goyo')
return
endif
" Oops, not this tab
if !exists('t:goyo_revert')
return
endif
" Clear auto commands
augroup goyo
autocmd!
augroup END
augroup! goyo
augroup goyop
autocmd!
augroup END
augroup! goyop
let goyo_revert = t:goyo_revert
let goyo_disabled_gitgutter = t:goyo_disabled_gitgutter
let goyo_disabled_airline = t:goyo_disabled_airline
let goyo_disabled_powerline = t:goyo_disabled_powerline
let goyo_disabled_lightline = t:goyo_disabled_lightline
if tabpagenr() == 1
tabnew
normal! gt
bd
endif
tabclose
execute 'normal! '.s:orig_tab.'gt'
let wmh = remove(goyo_revert, 'winminheight')
let wh = remove(goyo_revert, 'winheight')
let &winheight = max([wmh, 1])
let &winminheight = wmh
let &winheight = wh
for [k, v] in items(goyo_revert)
execute printf("let &%s = %s", k, string(v))
endfor
execute 'colo '. get(g:, 'colors_name', 'default')
if goyo_disabled_gitgutter
silent! GitGutterEnable
endif
if goyo_disabled_airline && !exists("#airline")
AirlineToggle
silent! AirlineRefresh
endif
if goyo_disabled_powerline && !exists("#PowerlineMain")
doautocmd PowerlineStartup VimEnter
silent! PowerlineReloadColorscheme
endif
if goyo_disabled_lightline
silent! call lightline#enable()
endif
if exists('#Powerline')
doautocmd Powerline ColorScheme
endif
if exists('g:goyo_callbacks[1]')
call g:goyo_callbacks[1]()
endif
endfunction
function! s:goyo(...)
let width = a:0 > 0 ? a:1 : get(g:, 'goyo_width', 80)
if exists('#goyo') == 0
call s:goyo_on(width)
elseif a:0 > 0
let t:goyo_width = width
call s:resize_pads()
else
call s:goyo_off()
end
endfunction
command! -nargs=? Goyo call s:goyo(<args>)
let &cpo = s:cpo_save
unlet s:cpo_save
command! -nargs=? -bar -bang Goyo call goyo#execute(<bang>0, <q-args>)