summaryrefslogtreecommitdiff
path: root/nvim/lua/myplugins/resize.lua
diff options
context:
space:
mode:
Diffstat (limited to 'nvim/lua/myplugins/resize.lua')
-rw-r--r--nvim/lua/myplugins/resize.lua97
1 files changed, 97 insertions, 0 deletions
diff --git a/nvim/lua/myplugins/resize.lua b/nvim/lua/myplugins/resize.lua
new file mode 100644
index 0000000..8af6c3b
--- /dev/null
+++ b/nvim/lua/myplugins/resize.lua
@@ -0,0 +1,97 @@
+local M = {}
+
+M.setup = function(opts) end
+
+M.isRightMost = function()
+ local curWin = vim.fn.winnr()
+ vim.cmd([[wincmd l]])
+ local rightWin = vim.fn.winnr()
+ if curWin == rightWin then
+ return true
+ else
+ vim.cmd([[wincmd h]])
+ return false
+ end
+end
+
+M.isLeftMost = function()
+ local curWin = vim.fn.winnr()
+ vim.cmd([[wincmd h]])
+ local leftWin = vim.fn.winnr()
+ if curWin == leftWin then
+ return true
+ else
+ vim.cmd([[wincmd l]])
+ return false
+ end
+end
+
+M.isBottomMost = function()
+ local curWin = vim.fn.winnr()
+ vim.cmd([[wincmd j]])
+ local bottomWin = vim.fn.winnr()
+ if curWin == bottomWin then
+ return true
+ else
+ vim.cmd([[wincmd k]])
+ return false
+ end
+end
+
+M.isTopMost = function()
+ local curWin = vim.fn.winnr()
+ vim.cmd([[wincmd k]])
+ local topWin = vim.fn.winnr()
+ if curWin == topWin then
+ return true
+ else
+ vim.cmd([[wincmd j]])
+ return false
+ end
+end
+
+M.ResizeLeft = function()
+ if M.isRightMost() then
+ if not M.isLeftMost() then
+ vim.cmd([[wincmd 5 >]])
+ end
+ else
+ vim.cmd([[wincmd 5 <]])
+ end
+end
+
+M.ResizeRight = function()
+ if M.isRightMost() then
+ if not M.isLeftMost() then
+ vim.cmd([[wincmd 5 <]])
+ end
+ else
+ vim.cmd([[wincmd 5 >]])
+ end
+end
+
+M.ResizeUp = function()
+ if M.isBottomMost() then
+ if not M.isTopMost() then
+ vim.cmd([[wincmd 5 +]])
+ else
+ vim.cmd([[wincmd 5 -]])
+ end
+ else
+ vim.cmd([[wincmd 5 -]])
+ end
+end
+
+M.ResizeDown = function()
+ if M.isBottomMost() then
+ if not M.isTopMost() then
+ vim.cmd([[wincmd 5 -]])
+ else
+ vim.cmd([[wincmd 5 +]])
+ end
+ else
+ vim.cmd([[wincmd 5 +]])
+ end
+end
+
+return M