I have the following function in my .vimrc:
autocmd Filetype mkd call SetWritingOptions()
function SetWritingOptions()
colorscheme pencil
setlocal background=light
setlocal guifont=Cousine\ 11
setlocal spell! spelllang=en_us
setlocal noexpandtab
setlocal textwidth=52
setlocal linespace=4
setlocal noruler
setlocal nonumber
setlocal wrap
setlocal linebreak
setlocal nolist
setlocal display+=lastline
execute "Goyo"
endfunction
(Goyo is a distration-free mode plugin for Vim: https://github.com/junegunn/goyo.vim)
I added this for the purpose of working with markdown files
Now everything works OK except I end up with filetype=conf, which doesn't happend if I remove execute "Goyo"
Why is this? How can I modify the function so I end up with filetype=mkd instead?
(I tried adding filetype=mkd at the end, but Vim just keeps calling the function until it breaks).
Goyo command opens the current document in a new window in a new tab surrounded by 4 invisible padding windows. Window-local settings (setlocal) will not be applied to this new Goyo window.
So the right way to achieve this is to use g:goyo_callbacks, with which you can specify two functions that are called when a new Goyo window is created and when it's closed.
Please notice that the most of the settings in your example are global that cannot be applied locally, so you might want to revert those settings in the second callback function.
function! SetWritingOptions()
colorscheme pencil
setlocal background=light
setlocal guifont=Cousine\ 11
setlocal spell! spelllang=en_us
setlocal noexpandtab
setlocal textwidth=52
setlocal linespace=4
setlocal noruler
setlocal nonumber
setlocal wrap
setlocal linebreak
setlocal nolist
setlocal display+=lastline
endfunction
function! UnsetWritingOptions()
" Fill in!
" Revert global options
endfunction
let g:goyo_callbacks = [function('SetWritingOptions'), function('UnsetWritingOptions')]
augroup GoyoMarkdown
autocmd!
autocmd FileType mkd nested if !has('vim_starting')|execute 'Goyo'|endif
autocmd VimEnter *.md,*.mkd,*.markdown nested Goyo
augroup END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With