folke / zen-mode.nvim

🧘 Distraction-free coding for Neovim
Apache License 2.0
1.68k stars 47 forks source link

feature: Add option to keep bufferline.nvim on #128

Closed gerazov closed 2 months ago

gerazov commented 5 months ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

Great plugin! :sunglasses:

I frequently use zen-mode to center text for editing. I usually edit latex documents that input other tex files and have several buffers open at a time. In this scenario I find using akinsho/bufferline.nvim very convenient when moving around open buffers sequentially.

In zen-mode the bufferline is turned off by default.

Describe the solution you'd like

It would be useful to be able to keep bufferline.nvim active when in Zen mode as an option.

Describe alternatives you've considered

/

Additional context

No response

iafshinafshin commented 3 months ago

Hello, Yes , I have request looks like this feature too

b0ae989c commented 3 months ago

We don't need to add new features. This is achievable with on_open. For example,

{
  "folke/zen-mode.nvim",
  opts = {
    on_open = function(win)
      local view = require("zen-mode.view")
      local layout = view.layout(view.opts)
      vim.api.nvim_win_set_config(win, {
        width = layout.width,
        height = layout.height - 1,
      })
      vim.api.nvim_win_set_config(view.bg_win, {
        width = vim.o.columns,
        height = view.height() - 1,
        row = 1,
        col = layout.col,
        relative = "editor",
      })
    end,
  },
},
gerazov commented 2 months ago

Works great - thanks! :pray:

It could be useful to add this as an example use-case in the docs?

gerazov commented 2 months ago

I've updated the code to check if bufferline is active, since I have it lazy load on BufAdd, i.e. only when multiple buffers are open.

on_open = function(win)
  local buffline = package.loaded["bufferline"]
  if buffline then
    local view = require("zen-mode.view")
    local layout = view.layout(view.opts)
    vim.api.nvim_win_set_config(win, {
      width = layout.width,
      height = layout.height - 1,
    })
    vim.api.nvim_win_set_config(view.bg_win, {
      width = vim.o.columns,
      height = view.height() - 1,
      row = 1,
      col = layout.col,
      relative = "editor",
    })
  end
end,
iafshinafshin commented 2 months ago

Hello, these codes does not work for me & i'm using lazyvim , this is my codes for bufferline:

{
  "akinsho/bufferline.nvim",
  event = "VeryLazy",
  keys = {
    { "<Tab>", "<Cmd>BufferLineCycleNext<CR>", desc = "Next tab" },
    { "<S-Tab>", "<Cmd>BufferLineCyclePrev<CR>", desc = "Prev tab" },
  },
  opts = {
    options = {
      mode = "tabs",
      -- separator_style = "slant",
      show_buffer_close_icons = false,
      show_close_icon = false,
    },
  },
}

and zen-mode codes :

{
  "folke/zen-mode.nvim",
  cmd = "ZenMode",
  opts = {
    plugins = {
      lualine = false,
      gitsigns = false,
      tmux = true,
      kitty = { enabled = false, font = "+2" },
    },
    on_open = function(win)
      local buffline = package.loaded["bufferline"]
      if buffline then
        local view = require("zen-mode.view")
        local layout = view.layout(view.opts)
        vim.api.nvim_win_set_config(win, {
          width = layout.width,
          height = layout.height - 1,
        })
        vim.api.nvim_win_set_config(view.bg_win, {
          width = vim.o.columns,
          height = view.height() - 1,
          row = 1,
          col = layout.col,
          relative = "editor",
        })
      end
    end,
  },
  keys = { { "<leader>z", "<cmd>ZenMode<cr>", desc = "Zen Mode" } },
}
gerazov commented 2 months ago

I have it in my config function, but it shouldn't make a difference :thinking:

return {
  "folke/zen-mode.nvim",
  enabled = true,
  lazy = true,
  event = 'verylazy',
  config = function ()
    require "zen-mode".setup {
      on_open = function(win)
        local buffline = package.loaded["bufferline"]
        if buffline then
          local view = require("zen-mode.view")
          local layout = view.layout(view.opts)
          vim.api.nvim_win_set_config(win, {
            width = layout.width,
            height = layout.height - 1,
          })
          vim.api.nvim_win_set_config(view.bg_win, {
            width = vim.o.columns,
            height = view.height() - 1,
            row = 1,
            col = layout.col,
            relative = "editor",
          })
        end
      end,
    }
  end
}