utils
This commit is contained in:
@@ -50,6 +50,10 @@ map('n', '<C-h>', '<C-w>h')
|
||||
map('n', '<C-l>', '<C-w>l')
|
||||
map('n', '<C-j>', '<C-w>j')
|
||||
map('n', '<C-k>', '<C-w>k')
|
||||
map('n', '<A-h>', cmd('vertical resize -2'))
|
||||
map('n', '<A-l>', cmd('vertical resize +2'))
|
||||
map('n', '<A-j>', cmd('resize +2'))
|
||||
map('n', '<A-k>', cmd('resize -2'))
|
||||
|
||||
-- Tab management
|
||||
map('n', ']t', cmd('tabnext'))
|
||||
@@ -113,3 +117,12 @@ map('n', 'K', vim.lsp.buf.hover)
|
||||
map('n', 'gd', vim.lsp.buf.definition)
|
||||
map('n', 'gr', vim.lsp.buf.references)
|
||||
map('n', '<C-s>', vim.lsp.buf.signature_help)
|
||||
|
||||
-- Git shortcut
|
||||
vim.keymap.set('n', '<leader>G', function()
|
||||
vim.cmd('Gwrite') -- stage current worktree file
|
||||
vim.cmd('Git') -- return to Fugitive status
|
||||
vim.cmd('only') -- optional: close old diff panes
|
||||
vim.cmd('normal! ]/') -- next file
|
||||
vim.cmd('normal! dv') -- open vertical diff
|
||||
end, { desc = 'Fugitive stage file and diff next' })
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
function M.root_markers_with_field(root_files, new_names, field, fname)
|
||||
local path = vim.fn.fnamemodify(fname, ':h')
|
||||
local found = vim.fs.find(new_names, { path = path, upward = true })
|
||||
|
||||
for _, f in ipairs(found or {}) do
|
||||
for line in io.lines(f) do
|
||||
if line:find(field) then
|
||||
root_files[#root_files + 1] = vim.fs.basename(f)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return root_files
|
||||
end
|
||||
|
||||
function M.insert_package_json(root_files, field, fname)
|
||||
return M.root_markers_with_field(root_files, { 'package.json', 'package.json5' }, field, fname)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -21,4 +21,24 @@ function M.await(fn, timeout, interval)
|
||||
return { ok = ok or false, data = data }
|
||||
end
|
||||
|
||||
function M.root_markers_with_field(root_files, new_names, field, fname)
|
||||
local path = vim.fn.fnamemodify(fname, ':h')
|
||||
local found = vim.fs.find(new_names, { path = path, upward = true })
|
||||
|
||||
for _, file in ipairs(found or {}) do
|
||||
for line in io.lines(file) do
|
||||
if line:find(field) then
|
||||
root_files[#root_files + 1] = vim.fs.basename(file)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return root_files
|
||||
end
|
||||
|
||||
function M.insert_package_json(root_files, field, fname)
|
||||
return M.root_markers_with_field(root_files, { 'package.json', 'package.json5' }, field, fname)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user