Skip to content

Latest commit

 

History

History
275 lines (186 loc) · 7.33 KB

README.md

File metadata and controls

275 lines (186 loc) · 7.33 KB

windex.nvim

🧼 A neovim plugin for cleeean neovim window (and tmux pane) functions. 🧼

Works with or without tmux!

✨ Features

Window Maximizing

  • Use <leader>z to toggle maximizing the current neovim window (without any of the ugly borders that other maximizing plugins create) AND the current tmux pane.
  • Works with plugins such as 'nvim-scrollview', which have floating windows (unlike other maximizing plugins).

Note: Please see maximize.nvim for using just the window maximizing feature.

Terminal Toggle

  • Use <C-\> to toggle the (improved) native terminal which will open fullscreen. (See the demo video below)

Cleaner Window Movement

  • Treats tmux panes as neovim windows which allows for easy window/pane movement.
  • Use <leader>{motion} to switch to the window (or tmux pane) in the specified direction.
  • Use <leader>x{motion} to save and quit the window (or kill the tmux pane) in the specified direction.
  • Use <leader>; to jump to the previous window (or tmux pane).
  • Use vim keymaps to create tmux panes.

Note: The {motion} keys by default are h, j, k and l, but can be replaced with the arrow keys. See 'Configuration' for details.

🔥 Demos

Maximizing Performance Comparison with Vim-Maximizer

vim-maximizer

Has weird thing in the top left where it didn't maximize properly and doesn't maximize the tmux pane. 🤢

vim-maximizer

windex.nvim

Perfectly maximizes the neovim window and tmux pane! 👑

windex

Demo Video - Terminal Toggle

Window / Pane Movement and Terminal Toggle

windexDEMO.mp4

📦 Installation

Install with your favourite plugin manager and run the setup function.

Note: I highly recommend using bufresize.nvim especially when using tmux.

Packer

use {
  'declancm/windex.nvim',
  config = function() require('windex').setup() end
}

⚙️ Configuration

A settings table can be passed into the setup function for custom options.

Default Settings

-- KEYMAPS:
default_keymaps = true, -- Enable default keymaps.
extra_keymaps = false,  -- Enable extra keymaps.
arrow_keys = false,     -- Default window movement keymaps use arrow keys instead of 'h,j,k,l'.

-- OPTIONS:
numbered_term = false,  -- Enable line numbers in the terminal.
save_buffers = false,   -- Save all buffers before switching tmux panes.
warnings = true,        -- Enable warnings before some actions such as closing tmux panes.

Example Configuration

require('windex').setup {
  extra_keymaps = true,
  save_buffers = true,
}

⌨️ Keymaps

Note: If the tmux requirement is not passed, the non-tmux keymaps will be used instead.

Default Keymaps

-- MAXIMIZE:

-- Toggle maximizing the current window:
vim.keymap.set('n', '<Leader>z', "<Cmd>lua require('windex').toggle_maximize()<CR>")

-- TERMINAL:

-- Toggle the terminal:
vim.keymap.set({ 'n', 't' }, '<C-Bslash>', "<Cmd>lua require('windex').toggle_terminal()<CR>")

-- Enter normal mode within terminal:
vim.keymap.set('t', '<C-n>', '<C-Bslash><C-n>')

-- MOVEMENT:

-- Move between nvim windows and tmux panes:
vim.keymap.set('n', '<Leader>k', "<Cmd>lua require('windex').switch_window('up')<CR>")
vim.keymap.set('n', '<Leader>j', "<Cmd>lua require('windex').switch_window('down')<CR>")
vim.keymap.set('n', '<Leader>h', "<Cmd>lua require('windex').switch_window('left')<CR>")
vim.keymap.set('n', '<Leader>l', "<Cmd>lua require('windex').switch_window('right')<CR>")

-- Save and close the nvim window or kill the tmux pane in the direction selected:
vim.keymap.set('n', '<Leader>xk', "<Cmd>lua require('windex').close_window('up')<CR>")
vim.keymap.set('n', '<Leader>xj', "<Cmd>lua require('windex').close_window('down')<CR>")
vim.keymap.set('n', '<Leader>xh', "<Cmd>lua require('windex').close_window('left')<CR>")
vim.keymap.set('n', '<Leader>xl', "<Cmd>lua require('windex').close_window('right')<CR>")

-- Switch to previous nvim window or tmux pane:
vim.keymap.set('n', '<Leader>;', "<Cmd>lua require('windex').previous_window()<CR>")

Extra Keymaps

-- MOVEMENT:

-- Create nvim panes:
vim.keymap.set('n', '<Leader>v', '<Cmd>wincmd v<CR>')
vim.keymap.set('n', '<Leader>s', '<Cmd>wincmd s<CR>')

-- Create tmux panes:
vim.keymap.set('n', '<Leader>tv', "<Cmd>lua require('windex').create_pane('vertical')<CR>")
vim.keymap.set('n', '<Leader>ts', "<Cmd>lua require('windex').create_pane('horizontal')<CR>")

🚥 statusline & winbar

Use the tabpage-scoped variable vim.t.maximized to check whether the current window is maximized or not.

Lualine

local function maximize_status()
  return vim.t.maximized and '' or ''
end

require('lualine').setup {
  sections = {
    lualine_c = { maximize_status }
  }
}

winbar

-- ~/.config/nvim/lua/winbar.lua
local M = {}

M.maximize_status = function()
  return vim.t.maximized and '' or ''
end

return M

-- ~/.config/nvim/init.lua
vim.o.winbar = "%{%v:lua.require('winbar').maximize_status()%}"

ℹ️ API

Note: Check the default keymaps on how to implement the functions in keymaps.

Maximize Current Window

  • Maximize the current neovim window completely without any of the ugly borders that other plugins create.

    require('windex').toggle_nvim_maximize()
  • Maximize the current neovim window AND tmux pane for when you need something completely fullscreen.

    require('windex').toggle_maximize()

Terminal Toggle

  • Toggle the (improved) interactive native terminal.

    require('windex').toggle_terminal([{maximize} [, {command}]])
    • The {maximize} values are:

      • 'none' - No maximizing,

      • 'nvim' - Maximize the neovim window,

      • 'all' - Maximize the neovim window and tmux pane (the default).

    • The optional {command} argument is a command to run in a non-interactive terminal.

    • Example: Custom keymap to open lazygit fullscreen.

      vim.api.nvim_set_keymap(
        'n',
        '<C-g>',
        "<Cmd>lua require('windex').toggle_terminal('all','lazygit')<CR>",
        { noremap = true, silent = true }
      )

Cleaner Window Movement

  • Treats tmux panes as neovim windows which allows for easy window/pane movement, with the same function. The {direction} values are: 'up', 'down', 'left' or 'right'.

    require('windex').switch_window({direction})
  • Save and quit the neovim window, or kill the tmux pane, in the selected direction. The {direction} values are: 'up', 'down', 'left' or 'right'.

    require('windex').close_window({direction})
  • Jump to the last neovim window or tmux pane.

    require('windex').previous_window()
  • Create a tmux pane. The {split} values are: 'vertical' or 'horizontal'.

    require('windex').create_pane({split})