summaryrefslogtreecommitdiff
path: root/ar/.config/LazyVim/lua/plugins/goyo.lua
blob: 9d0f8605a6f370bb7aab7d54731a288a3071b495 (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
vim.g.is_goyo_active = false

vim.g.goyo_enter = function()
  if vim.fn.executable("tmux") == 1 and vim.fn.strlen(vim.env.TMUX) > 0 then
    vim.fn.system("tmux set status off")
    if not string.find(vim.fn.system("tmux list-panes -F '#F'"), "Z") then
      vim.fn.system("tmux resize-pane -Z")
    end
  end

  vim.g.default_colorscheme = vim.g.colors_name or "default"
  vim.o.background = "light"
  vim.wo.linebreak = true
  vim.wo.wrap = true
  vim.bo.textwidth = 0
  vim.bo.wrapmargin = 0
  vim.cmd("Goyo 80x85%")
  vim.cmd("colorscheme seoul256")
  vim.g.is_goyo_active = true
end

vim.g.goyo_leave = function()
  if vim.fn.executable("tmux") == 1 and vim.fn.strlen(vim.env.TMUX) > 0 then
    vim.fn.system("tmux set status on")
    if string.find(vim.fn.system("tmux list-panes -F '#F'"), "Z") then
      vim.fn.system("tmux resize-pane -Z")
    end
  end
  vim.cmd("Goyo!")
  vim.cmd("colorscheme " .. vim.g.default_colorscheme)
  vim.g.is_goyo_active = false
end

vim.g.toggle_goyo = function()
  if vim.g.is_goyo_active then
    vim.g.goyo_leave()
  else
    vim.g.goyo_enter()
  end
end

return {
  "junegunn/goyo.vim",
  cmd = "Goyo",
  keys = {
    vim.api.nvim_set_keymap(
      "n",
      "<leader>gy",
      "<cmd>lua vim.g.toggle_goyo()<CR>",
      { noremap = true, silent = true, desc = "Toggle Goyo" }
    ),
  },
}