-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.lua
93 lines (83 loc) · 2.27 KB
/
utils.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
local M = {}
local map_opts = { silent = true, noremap = true }
---Create an autocommand
---@param event string | string[]
---@param opts table
M.autocmd = function(event, opts)
vim.api.nvim_create_autocmd(event, opts)
end
---Create a keymap
---@param mode string | string[]
---@param lhs string left-hand side of mapping
---@param rhs string | function right-hand side of mapping
---@param opts? table aditional options
M.keymap = function(mode, lhs, rhs, opts)
opts = opts or {}
vim.keymap.set(mode, lhs, rhs, M.merge(map_opts, opts))
end
M.map_notify = function(message)
vim.notify(message, 'info', {
title = 'Mapping',
})
end
---Merge two or more tables recursively
---@param tableA table
---@param tableB table
---@param ... table
---@return table
M.merge = function(tableA, tableB, ...)
return vim.tbl_deep_extend('force', tableA, tableB, ...)
end
---Create a nmap
---@param lhs string left-hand side of nmap
---@param rhs string | function righ-hand side of nmap
---@param opts? table aditional options
M.nmap = function(lhs, rhs, opts)
opts = opts or {}
vim.keymap.set('n', lhs, rhs, M.merge(map_opts, opts))
end
-- Move windows taken from:
-- https://vim.fandom.com/wiki/Move_current_window_between_tabs
M.move_window_to_prev_tab = function()
-- there is only one window
if vim.fn.tabpagenr('$') == 1 and vim.fn.winnr('$') == 1 then
return
end
-- preparing new window
local tab_nr = vim.fn.tabpagenr('$')
local cur_buf = vim.fn.bufnr('%')
if vim.fn.tabpagenr() ~= 1 then
vim.cmd('close!')
if tab_nr == vim.fn.tabpagenr('$') then
vim.cmd('tabprev')
end
vim.cmd('split')
else
vim.cmd('close!')
vim.cmd('0tabnew')
end
-- opening current buffer in new window
vim.cmd('b' .. cur_buf)
end
M.move_window_to_next_tab = function()
--there is only one window
if vim.fn.tabpagenr('$') == 1 and vim.fn.winnr('$') == 1 then
return
end
--preparing new window
local tab_nr = vim.fn.tabpagenr('$')
local cur_buf = vim.fn.bufnr('%')
if vim.fn.tabpagenr() < tab_nr then
vim.cmd('close!')
if tab_nr == vim.fn.tabpagenr('$') then
vim.cmd('tabnext')
end
vim.cmd('split')
else
vim.cmd('close!')
vim.cmd('tabnew')
end
--opening current buffer in new window
vim.cmd('b' .. cur_buf)
end
return M