summaryrefslogtreecommitdiff
path: root/neovim/.config/nvim/lua/plugins/goyo.lua
blob: 5f700487e04a399f24c6b7c3ba813a9e5e508ebd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
return {
  {
    'junegunn/goyo.vim',
    cond = function() return vim.fn.has('gui_running') == 1 end,
    dependencies = {
      {
        'junegunn/limelight.vim',
      },
    },
    keys = {
      { '<leader>z', '<cmd>Goyo<CR>', desc = 'Goyo' },
    },
    config = function()
      local goyo_enter = function()
        vim.opt.showmode = false
        vim.opt.showcmd = false
        vim.opt.scrolloff = 999

        vim.opt.laststatus = 0
        require('lualine').hide()

        vim.cmd('Limelight')
        if vim.fn.exists('g:gui_vimr') == 1 then
          vim.cmd('VimRToggleFullscreen')
        end
      end

      local goyo_leave = function()
        local function script_path()
          local str = debug.getinfo(2, 'S').source:sub(2)
          return str:match('(.*/)') or './'
        end

        vim.opt.showmode = true
        vim.opt.showcmd = true
        vim.opt.scrolloff = 5
        require('lualine').hide({ unhide = true })
        vim.opt.laststatus = 3
        vim.cmd('Limelight!')
        if vim.fn.exists('g:gui_vimr') == 1 then
          vim.cmd('VimRToggleFullscreen')
        end
      end

      local goyo_augroup = vim.api.nvim_create_augroup('Goyo', { clear = true })
      vim.api.nvim_create_autocmd('User',
        {
          pattern = 'GoyoEnter',
          group = goyo_augroup,
          callback = goyo_enter,
        })
      vim.api.nvim_create_autocmd('User',
        {
          pattern = 'GoyoLeave',
          group = goyo_augroup,
          callback = goyo_leave,
        })
    end,
  },
}