Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/declancm/windex.nvim

๐Ÿงผ Clean window maximizing, terminal toggling, window/tmux pane movements and more!
https://github.com/declancm/windex.nvim

lua neovim nvim plugin tmux vim

Last synced: about 2 months ago
JSON representation

๐Ÿงผ Clean window maximizing, terminal toggling, window/tmux pane movements and more!

Awesome Lists containing this project

README

        

# windex.nvim

๐Ÿงผ __A neovim plugin for cleeean neovim window (and tmux pane) functions.__ ๐Ÿงผ

Works with or without tmux!

## โœจ Features

### Window Maximizing

* Use `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](https://github.com/declancm/maximize.nvim)
for using just the window maximizing feature.__

### Terminal Toggle

* Use `` 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 `{motion}` to switch to the window (or tmux pane) in the specified
direction.
* Use `x{motion}` to save and quit the window (or kill the tmux pane) in
the specified direction.
* Use `;` 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](https://user-images.githubusercontent.com/90937622/159694125-322f371f-4334-4731-bf02-cfde05945654.png)

### windex.nvim

Perfectly maximizes the neovim window and tmux pane! ๐Ÿ‘‘

![windex](https://user-images.githubusercontent.com/90937622/159694138-5b99ec1d-e860-42fb-9af6-ca23b98dda25.png)

Demo Video - Terminal Toggle

### Window / Pane Movement and Terminal Toggle

https://user-images.githubusercontent.com/90937622/159681079-58f36668-e78b-41fa-b929-e9ebc9dd8d3b.mp4

## ๐Ÿ“ฆ Installation

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

_Note: I highly recommend using [bufresize.nvim](https://github.com/kwkarlwang/bufresize.nvim) especially when using tmux._

### Packer

```lua
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

```lua
-- 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

```lua
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

```lua
-- MAXIMIZE:

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

-- TERMINAL:

-- Toggle the terminal:
vim.keymap.set({ 'n', 't' }, '', "lua require('windex').toggle_terminal()")

-- Enter normal mode within terminal:
vim.keymap.set('t', '', '')

-- MOVEMENT:

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

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

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

### Extra Keymaps

```lua
-- MOVEMENT:

-- Create nvim panes:
vim.keymap.set('n', 'v', 'wincmd v')
vim.keymap.set('n', 's', 'wincmd s')

-- Create tmux panes:
vim.keymap.set('n', 'tv', "lua require('windex').create_pane('vertical')")
vim.keymap.set('n', 'ts', "lua require('windex').create_pane('horizontal')")
```

## ๐Ÿšฅ statusline & winbar

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

### Lualine

```lua
local function maximize_status()
return vim.t.maximized and '๏‹ ' or ''
end

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

### winbar

```lua
-- ~/.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.

```lua
require('windex').toggle_nvim_maximize()
```

* Maximize the current neovim window __AND__ tmux pane for when you need something
completely fullscreen.

```lua
require('windex').toggle_maximize()
```

### Terminal Toggle

* Toggle the (improved) interactive native terminal.

```lua
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.

```lua
vim.api.nvim_set_keymap(
'n',
'',
"lua require('windex').toggle_terminal('all','lazygit')",
{ 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'.

```lua
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'.

```lua
require('windex').close_window({direction})
```

* Jump to the last neovim window or tmux pane.

```lua
require('windex').previous_window()
```

* Create a tmux pane. The {split} values are: 'vertical' or 'horizontal'.

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