nvim local functions
This commit is contained in:
parent
85b0441e57
commit
360a93c6d1
@ -5,7 +5,7 @@ local opts = { noremap = true, silent = true }
|
|||||||
vim.g.mapleader = ','
|
vim.g.mapleader = ','
|
||||||
|
|
||||||
|
|
||||||
function create_function_tabdo(command)
|
local function create_function_tabdo(command)
|
||||||
return function()
|
return function()
|
||||||
local curr_tab = vim.fn.tabpagenr()
|
local curr_tab = vim.fn.tabpagenr()
|
||||||
vim.cmd.tabdo(command)
|
vim.cmd.tabdo(command)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
function autocmd(func)
|
local function autocmd(func)
|
||||||
local create_autocmd = vim.api.nvim_create_autocmd
|
local create_autocmd = vim.api.nvim_create_autocmd
|
||||||
|
|
||||||
create_autocmd("BufEnter",
|
create_autocmd("BufEnter",
|
||||||
@ -7,23 +7,23 @@ function autocmd(func)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_keymap_base(key, cmd)
|
local function set_keymap_base(key, cmd)
|
||||||
local map = vim.keymap.set
|
local map = vim.keymap.set
|
||||||
keymap_keys = string.format([[<Leader>r%s]], key)
|
keymap_keys = string.format([[<Leader>r%s]], key)
|
||||||
map("n", keymap_keys, cmd, opts)
|
map("n", keymap_keys, cmd, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_keymap_format_file(cmd)
|
local function set_keymap_format_file(cmd)
|
||||||
local cmd_string = string.format([[:!%s %% <CR>]], cmd)
|
local cmd_string = string.format([[:!%s %% <CR>]], cmd)
|
||||||
set_keymap_base("f", cmd_string)
|
set_keymap_base("f", cmd_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_keymap_run_script(cmd)
|
local function set_keymap_run_script(cmd)
|
||||||
local cmd_string = string.format([[:tabnew %% <CR> :terminal %s %% <CR> :set nocursorline number norelativenumber <CR> G <CR>]], cmd)
|
local cmd_string = string.format([[:tabnew %% <CR> :terminal %s %% <CR> :set nocursorline number norelativenumber <CR> G <CR>]], cmd)
|
||||||
set_keymap_base("r", cmd_string)
|
set_keymap_base("r", cmd_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
function create_function_autocmd_filetype(set_keymap_func, ft, cmd)
|
local function create_function_autocmd_filetype(set_keymap_func, ft, cmd)
|
||||||
return function()
|
return function()
|
||||||
if vim.bo.filetype == ft then
|
if vim.bo.filetype == ft then
|
||||||
set_keymap_func(cmd)
|
set_keymap_func(cmd)
|
||||||
@ -31,7 +31,7 @@ function create_function_autocmd_filetype(set_keymap_func, ft, cmd)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function create_function_autocmd_filename(set_keymap_func, fn, cmd)
|
local function create_function_autocmd_filename(set_keymap_func, fn, cmd)
|
||||||
return function()
|
return function()
|
||||||
if vim.fn.expand('%:t') == fn then
|
if vim.fn.expand('%:t') == fn then
|
||||||
set_keymap_func(cmd)
|
set_keymap_func(cmd)
|
||||||
@ -39,11 +39,11 @@ function create_function_autocmd_filename(set_keymap_func, fn, cmd)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function autocmd_run_script_filetype(ft, cmd)
|
local function autocmd_run_script_filetype(ft, cmd)
|
||||||
autocmd(create_function_autocmd_filetype(set_keymap_run_script, ft, cmd))
|
autocmd(create_function_autocmd_filetype(set_keymap_run_script, ft, cmd))
|
||||||
end
|
end
|
||||||
|
|
||||||
function autocmd_format_file_by_filetype(ft, cmd)
|
local function autocmd_format_file_by_filetype(ft, cmd)
|
||||||
autocmd(create_function_autocmd_filetype(set_keymap_format_file, ft, cmd))
|
autocmd(create_function_autocmd_filetype(set_keymap_format_file, ft, cmd))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -71,7 +71,7 @@ opt.backupdir = { prefix .. "/backup//" }
|
|||||||
opt.directory = { prefix .. "/swp//" }
|
opt.directory = { prefix .. "/swp//" }
|
||||||
|
|
||||||
|
|
||||||
function makeDirIfNoExists(path)
|
local function makeDirIfNoExists(path)
|
||||||
local path = path["_value"]
|
local path = path["_value"]
|
||||||
if (vim.fn.isdirectory(path) == 0) then
|
if (vim.fn.isdirectory(path) == 0) then
|
||||||
vim.fn.mkdir(path, "p")
|
vim.fn.mkdir(path, "p")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user