Skip to content

Commit

Permalink
feat(window): add winshift.nvim plugin to start win-move mode
Browse files Browse the repository at this point in the history
  • Loading branch information
adoyle-h committed Sep 4, 2024
1 parent 0ae175b commit 4553c48
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doc/one.txt
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,17 @@ If bufferline plugin enabled, some keymaps will be overridden. See [Buffer Line]
- `<C-w><C-J>` = move current window to bottom
- `<C-w><C-K>` = move current window to top
- `<C-w><C-L>` = move current window to right
- `<C-w>m` = Start Win-Move mode
- `h` or `<left>` = Move window left
- `j` or `<down>` = Move window down
- `k` or `<up>` = Move window up
- `l` or `<right>` = Move window right
- `H` or `<S-left>` = Move window far_left
- `J` or `<S-down>` = Move window far_down
- `K` or `<S-up>` = Move window far_up
- `L` or `<S-right>` = Move window far_right
- `<ESC>` or `q` or `<C-c>` = Exit Win-Move mode
- `<C-w>M` = Start Win-Swap mode

--------------------------------------------------------------------------------
## Scroll *one-keymaps-scroll*
Expand Down
11 changes: 11 additions & 0 deletions doc/usage/keymaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ If bufferline plugin enabled, some keymaps will be overridden. See [Buffer Line]
- `<C-w><C-J>` = move current window to bottom
- `<C-w><C-K>` = move current window to top
- `<C-w><C-L>` = move current window to right
- `<C-w>m` = Start Win-Move mode
- `h` or `<left>` = Move window left
- `j` or `<down>` = Move window down
- `k` or `<up>` = Move window up
- `l` or `<right>` = Move window right
- `H` or `<S-left>` = Move window far_left
- `J` or `<S-down>` = Move window far_down
- `K` or `<S-up>` = Move window far_up
- `L` or `<S-right>` = Move window far_right
- `<ESC>` or `q` or `<C-c>` = Exit Win-Move mode
- `<C-w>M` = Start Win-Swap mode

## Scroll

Expand Down
1 change: 1 addition & 0 deletions lua/one/plugins/window/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ return {
require('one.plugins.window.dim'),
require('one.plugins.window.resize'),
require('one.plugins.window.maximize'),
require('one.plugins.window.winshift'),
},
}
75 changes: 75 additions & 0 deletions lua/one/plugins/window/winshift.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
return {
'sindrets/winshift.nvim',

config = function(config)
require('winshift').setup(config)
end,

defaultConfig = {
'winshift',
{
highlight_moving_win = true, -- Highlight the window being moved
focused_hl_group = 'Visual', -- The highlight group used for the moving window
moving_win_options = {
-- These are local options applied to the moving window while it's
-- being moved. They are unset when you leave Win-Move mode.
wrap = false,
cursorline = false,
cursorcolumn = false,
colorcolumn = '',
},
keymaps = {
disable_defaults = false, -- Disable the default keymaps
win_move_mode = {
['h'] = 'left',
['j'] = 'down',
['k'] = 'up',
['l'] = 'right',
['H'] = 'far_left',
['J'] = 'far_down',
['K'] = 'far_up',
['L'] = 'far_right',
['<left>'] = 'left',
['<down>'] = 'down',
['<up>'] = 'up',
['<right>'] = 'right',
['<S-left>'] = 'far_left',
['<S-down>'] = 'far_down',
['<S-up>'] = 'far_up',
['<S-right>'] = 'far_right',
},
},

---A function that should prompt the user to select a window.
---
---The window picker is used to select a window while swapping windows with
---`:WinShift swap`.
---@return integer? winid # Either the selected window ID, or `nil` to
--- indicate that the user cancelled / gave an invalid selection.
window_picker = function()
return require('winshift.lib').pick_window({
-- A string of chars used as identifiers by the window picker.
picker_chars = 'FJDKSLA;CMRUEIWOQP',
filter_rules = {
-- This table allows you to indicate to the window picker that a window
-- should be ignored if its buffer matches any of the following criteria.
cur_win = true, -- Filter out the current window
floats = true, -- Filter out floating windows
filetype = {}, -- List of ignored file types
buftype = {}, -- List of ignored buftypes
bufname = {}, -- List of vim regex patterns matching ignored buffer names
},
---A function used to filter the list of selectable windows.
---@param winids integer[] # The list of selectable window IDs.
---@return integer[] filtered # The filtered list of window IDs.
filter_func = nil,
})
end,
},
},

keymaps = {
{ 'n', '<C-w>m', ':WinShift<CR>', { silent = true } },
{ 'n', '<C-w>M', ':WinShift swap<CR>', { silent = true } },
},
}

0 comments on commit 4553c48

Please sign in to comment.