Neovim zenmode setup for focused writing

|700

Although Copilot and other intelligent autocompletion tools are incredibly useful for coding, they can also be annoying. Having LLM autocompletion enabled during a writing session initially felt helpful, especially for overcoming writer’s block. However, I soon realized that, even when it autocompletes many sentences for me, it inhibits my ability to think through and properly structure my writing, eventually slowing me down substantially. Often, I end up scrapping, restructuring, and rewriting a lot. It also feels like someone who doesn’t fully understand what I’m trying to say is constantly interrupting me while I’m trying to think.

So, I’ve started using Vim more for my writing sessions. One of the Vim plugins I’ve used for a long time is some form of focused mode plugin. My current choice is zen-mode and before this, I used goyo. These plugins can be combined with twilight or limelight to add a dimming effect for enhanced focus.

With the Zen mode plugin, I can turn off everything (number, signcolumn, relativenumber, gitsigns), as shown below, and also disable autocompletion and copilot using the on_open hook.

A super compact and clean writing environment with the full capacity of neovim at your disposal. :wq

lua/custom/plugins.lua

return function(use)
  use {
    "folke/zen-mode.nvim",
    config = function()
      require("zen-mode").setup {
        window = {
          width = 70,
          options = {
            number = false,
            signcolumn = "no",
            relativenumber = false,
          },
        },
        plugins = {
          twilight = { enabled = true },
          gitsigns = { enabled = false },
        },
        on_open = function()
          require('cmp').setup { enabled = false }
          vim.cmd("Copilot disable")
        end,
        on_close = function()
          require('cmp').setup { enabled = true }
          vim.cmd("Copilot enable")
        end,
      }
    end
  }

  use {
    "folke/twilight.nvim",
    config = function()
      require("twilight").setup {
        treesitter = true,
        dimming = {
          alpha = 0.2,
        },
        context = 2,
      }
    end
  }

  ...
end

And the above setting is loaded via packer in my init.lua:

init.lua

require('packer').startup(function(use)

  ...

  local has_plugins, plugins = pcall(require, 'custom.plugins')
  if has_plugins then
    plugins(use)
  end

  ...