blob: 541e8da9fa94b57ba5c9a4fe417758ec8c432e0a (
plain)
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
|
local F = vim.fn
local C = vim.api.nvim_create_user_command
-- :Reverse {{{1
-- Reverse a selected range in line-wise.
-- Note: directly calling `g/^/m` will overwrite the current search pattern with
-- '^' and highlight it, which is not expected.
-- :h :keeppatterns
C(
'Reverse',
'keeppatterns <line1>,<line2>g/^/m<line1>-1',
{
desc = 'Reverse lines',
bar = true,
range = '%',
}
)
-- :SmartTabEdit {{{1
-- If the current buffer is empty, open a file with the current window;
-- otherwise open a new tab.
C(
'SmartTabEdit',
function(opts)
local is_empty_buffer = (
F.bufname() == ''
and not vim.bo.modified
and F.line('$') <= 1
and F.getline('.') == ''
)
if is_empty_buffer then
vim.cmd(mods .. ' edit ' .. args)
else
vim.cmd(mods .. ' tabedit ' .. args)
end
end,
{
desc = 'Smartly open a file',
nargs = '*',
complete = 'file',
}
)
|