Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
71 lines
1.8 KiB
Lua
71 lines
1.8 KiB
Lua
local api = {}
|
|
|
|
local CTRL_V = vim.api.nvim_replace_termcodes('<C-v>', true, true, true)
|
|
local CTRL_S = vim.api.nvim_replace_termcodes('<C-s>', true, true, true)
|
|
|
|
api.get_mode = function()
|
|
local mode = vim.api.nvim_get_mode().mode:sub(1, 1)
|
|
if mode == 'i' then
|
|
return 'i' -- insert
|
|
elseif mode == 'v' or mode == 'V' or mode == CTRL_V then
|
|
return 'x' -- visual
|
|
elseif mode == 's' or mode == 'S' or mode == CTRL_S then
|
|
return 's' -- select
|
|
elseif mode == 'c' and vim.fn.getcmdtype() ~= '=' then
|
|
return 'c' -- cmdline
|
|
end
|
|
end
|
|
|
|
api.is_insert_mode = function()
|
|
return api.get_mode() == 'i'
|
|
end
|
|
|
|
api.is_cmdline_mode = function()
|
|
return api.get_mode() == 'c'
|
|
end
|
|
|
|
api.is_select_mode = function()
|
|
return api.get_mode() == 's'
|
|
end
|
|
|
|
api.is_visual_mode = function()
|
|
return api.get_mode() == 'x'
|
|
end
|
|
|
|
api.is_suitable_mode = function()
|
|
local mode = api.get_mode()
|
|
return mode == 'i' or mode == 'c'
|
|
end
|
|
|
|
api.get_current_line = function()
|
|
if api.is_cmdline_mode() then
|
|
return vim.fn.getcmdline()
|
|
end
|
|
return vim.api.nvim_get_current_line()
|
|
end
|
|
|
|
---@return { [1]: integer, [2]: integer }
|
|
api.get_cursor = function()
|
|
if api.is_cmdline_mode() then
|
|
return { math.min(vim.o.lines, vim.o.lines - (vim.api.nvim_get_option('cmdheight') - 1)), vim.fn.getcmdpos() - 1 }
|
|
end
|
|
return vim.api.nvim_win_get_cursor(0)
|
|
end
|
|
|
|
api.get_screen_cursor = function()
|
|
if api.is_cmdline_mode() then
|
|
local cursor = api.get_cursor()
|
|
return { cursor[1], vim.fn.strdisplaywidth(string.sub(vim.fn.getcmdline(), 1, cursor[2] + 1)) }
|
|
end
|
|
local cursor = api.get_cursor()
|
|
local pos = vim.fn.screenpos(0, cursor[1], cursor[2] + 1)
|
|
return { pos.row, pos.col - 1 }
|
|
end
|
|
|
|
api.get_cursor_before_line = function()
|
|
local cursor = api.get_cursor()
|
|
return string.sub(api.get_current_line(), 1, cursor[2])
|
|
end
|
|
|
|
return api
|