mirror of
https://github.com/junegunn/goyo.vim.git
synced 2025-11-20 01:13:44 -05:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e04ccdb9d | ||
|
|
da67185e4a | ||
|
|
e2c59124cb | ||
|
|
27ea8fa731 | ||
|
|
ae04751e09 | ||
|
|
85c202264e | ||
|
|
2bc0604530 | ||
|
|
549f865ab4 | ||
|
|
a2b772fe58 | ||
|
|
7e318dbcce | ||
|
|
f303dc9307 | ||
|
|
ad87a5b35a | ||
|
|
5bea57ebf5 |
41
README.md
41
README.md
@@ -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,12 +21,17 @@ Use your favorite plugin manager.
|
||||
Usage
|
||||
-----
|
||||
|
||||
`:Goyo [width]`
|
||||
- `:Goyo`
|
||||
- Toggle Goyo
|
||||
- `:Goyo [width]`
|
||||
- Turn on or resize Goyo
|
||||
- `:Goyo!`
|
||||
- Turn Goyo off
|
||||
|
||||
You might want to define a map for toggling it:
|
||||
|
||||
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>
|
||||
nnoremap <Leader>G :Goyo<CR>
|
||||
```
|
||||
|
||||
Configuration
|
||||
@@ -34,45 +41,49 @@ Configuration
|
||||
- `g:goyo_margin_top` (default: 4)
|
||||
- `g:goyo_margin_bottom` (default: 4)
|
||||
- `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()
|
||||
function! s:goyo_enter()
|
||||
silent !tmux set status off
|
||||
set noshowmode
|
||||
set noshowcmd
|
||||
set scrolloff=999
|
||||
Limelight
|
||||
" ...
|
||||
endfunction
|
||||
|
||||
function! s:goyo_after()
|
||||
function! s:goyo_leave()
|
||||
silent !tmux set status on
|
||||
set showmode
|
||||
set showcmd
|
||||
set scrolloff=5
|
||||
Limelight!
|
||||
" ...
|
||||
endfunction
|
||||
|
||||
let g:goyo_callbacks = [function('s:goyo_before'), function('s:goyo_after')]
|
||||
autocmd! User GoyoEnter
|
||||
autocmd! User GoyoLeave
|
||||
autocmd User GoyoEnter call <SID>goyo_enter()
|
||||
autocmd User GoyoLeave 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`)
|
||||
|
||||
Inspiration
|
||||
-----------
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ function! s:setup_pad(bufnr, vert, size)
|
||||
execute win . 'wincmd w'
|
||||
execute (a:vert ? 'vertical ' : '') . 'resize ' . max([0, a:size])
|
||||
augroup goyop
|
||||
autocmd WinEnter <buffer> call s:blank()
|
||||
autocmd WinEnter,CursorMoved <buffer> call s:blank()
|
||||
augroup END
|
||||
|
||||
" To hide scrollbars of pad windows in GVim
|
||||
@@ -127,6 +127,7 @@ function! s:goyo_on(width)
|
||||
\ { 'laststatus': &laststatus,
|
||||
\ 'showtabline': &showtabline,
|
||||
\ 'fillchars': &fillchars,
|
||||
\ 'winminwidth': &winminwidth,
|
||||
\ 'winwidth': &winwidth,
|
||||
\ 'winminheight': &winminheight,
|
||||
\ 'winheight': &winheight,
|
||||
@@ -145,6 +146,12 @@ function! s:goyo_on(width)
|
||||
silent! GitGutterDisable
|
||||
endif
|
||||
|
||||
" vim-signify
|
||||
let t:goyo_disabled_signify = exists('b:sy') && b:sy.active
|
||||
if t:goyo_disabled_signify
|
||||
SignifyToggle
|
||||
endif
|
||||
|
||||
" vim-airline
|
||||
let t:goyo_disabled_airline = exists("#airline")
|
||||
if t:goyo_disabled_airline
|
||||
@@ -177,10 +184,10 @@ function! s:goyo_on(width)
|
||||
endif
|
||||
|
||||
" Global options
|
||||
set winwidth=1
|
||||
let &winheight = max([&winminheight, 1])
|
||||
set winminheight=1
|
||||
set winheight=1
|
||||
set winminwidth=1 winwidth=1
|
||||
set laststatus=0
|
||||
set showtabline=0
|
||||
set noruler
|
||||
@@ -217,6 +224,7 @@ function! s:goyo_on(width)
|
||||
if exists('g:goyo_callbacks[0]')
|
||||
call g:goyo_callbacks[0]()
|
||||
endif
|
||||
silent! doautocmd User GoyoEnter
|
||||
endfunction
|
||||
|
||||
function! s:goyo_off()
|
||||
@@ -241,9 +249,12 @@ function! s:goyo_off()
|
||||
|
||||
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
|
||||
@@ -252,7 +263,14 @@ function! s:goyo_off()
|
||||
endif
|
||||
tabclose
|
||||
execute 'normal! '.s:orig_tab.'gt'
|
||||
if winbufnr(0) == goyo_orig_buffer
|
||||
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])
|
||||
@@ -268,6 +286,12 @@ function! s:goyo_off()
|
||||
silent! GitGutterEnable
|
||||
endif
|
||||
|
||||
if goyo_disabled_signify
|
||||
silent! if !b:sy.active
|
||||
SignifyToggle
|
||||
endif
|
||||
endif
|
||||
|
||||
if goyo_disabled_airline && !exists("#airline")
|
||||
AirlineToggle
|
||||
silent! AirlineRefresh
|
||||
@@ -289,22 +313,29 @@ function! s:goyo_off()
|
||||
if exists('g:goyo_callbacks[1]')
|
||||
call g:goyo_callbacks[1]()
|
||||
endif
|
||||
silent! doautocmd User GoyoLeave
|
||||
endfunction
|
||||
|
||||
function! s:goyo(...)
|
||||
function! s:goyo(bang, ...)
|
||||
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()
|
||||
if a:bang
|
||||
if exists('#goyo')
|
||||
call s:goyo_off()
|
||||
endif
|
||||
else
|
||||
call s:goyo_off()
|
||||
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
|
||||
end
|
||||
endfunction
|
||||
|
||||
command! -nargs=? Goyo call s:goyo(<args>)
|
||||
command! -nargs=? -bar -bang Goyo call s:goyo('<bang>' == '!', <args>)
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
Reference in New Issue
Block a user