improved skeleton and moved to custom plugin
This commit is contained in:
parent
ce251cd13f
commit
d45eac3184
7 changed files with 85 additions and 62 deletions
22
lua/custom/plugins/tmoyses/keymaps/init.lua
Normal file
22
lua/custom/plugins/tmoyses/keymaps/init.lua
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
-- my keymaps
|
||||
vim.keymap.set('i', 'jk', '<Esc>', { desc="Back to normal mode from insert mode" });
|
||||
vim.keymap.set('i', 'kj', '<Esc>', { desc="Back to normal mode from insert mode" });
|
||||
vim.keymap.set({'n', 'x'}, 'B', '0', { desc="Move to beginning of line" });
|
||||
vim.keymap.set({'n', 'x'}, 'E', '$', { desc="Move to end of line" });
|
||||
|
||||
-- move text up or down
|
||||
vim.keymap.set('n', '<A-j>', ':m .+1<CR>==', { desc="Move line down one line" });
|
||||
vim.keymap.set('n', '<A-k>', ':m .-2<CR>==', { desc="Move line up one line" });
|
||||
vim.keymap.set('i', '<A-j>', '<Esc>:m .+1<CR>==gi', { desc="Move line down one line" });
|
||||
vim.keymap.set('i', '<A-k>', '<Esc>:m .-2<CR>==gi', { desc="Move line up one line" });
|
||||
vim.keymap.set('x', '<A-j>', ":m '>+1<CR>gv=gv", { desc="Move selection down one line" });
|
||||
vim.keymap.set('x', '<A-k>', ":m '<-2<CR>gv=gv", { desc="Move selection up one line" });
|
||||
|
||||
-- move text across and back (indenting)
|
||||
vim.keymap.set('n', '<A-l>', '>>_', { desc="Move (indent) text right" });
|
||||
vim.keymap.set('n', '<A-h>', '<<_', { desc="Move (de-indent text left" });
|
||||
vim.keymap.set('i', '<A-l>', '<C-t>', { desc="Move (indent) text right" });
|
||||
vim.keymap.set('i', '<A-h>', '<C-d>', { desc="Move (de-indent) text left" });
|
||||
vim.keymap.set('x', '<A-l>', '>gv', { desc="Move (indent) text right" });
|
||||
vim.keymap.set('x', '<A-h>', '<gv', { desc="Move (de-indent) text left"});
|
||||
|
||||
22
lua/custom/plugins/tmoyses/sessions/init.lua
Normal file
22
lua/custom/plugins/tmoyses/sessions/init.lua
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
-- my basic session management
|
||||
|
||||
local session_file = 'session.vim'
|
||||
|
||||
vim.api.nvim_create_autocmd({'VimEnter'}, {
|
||||
callback = function ()
|
||||
if vim.fn.argc() == 0 and vim.fn.filereadable(session_file) == 1 then
|
||||
vim.cmd('source ' .. session_file)
|
||||
vim.notify("Session restored from " .. session_file, vim.log.levels.INFO, {title = "Sessions"})
|
||||
end
|
||||
end,
|
||||
desc = "Load session file on start up - start vim with no args to load the session file in current working directory"
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd({'VimLeave'}, {
|
||||
callback = function ()
|
||||
if vim.fn.argc() == 0 then
|
||||
vim.cmd('mks! ' .. session_file)
|
||||
end
|
||||
end,
|
||||
desc = "Write session file on close"
|
||||
})
|
||||
27
lua/custom/plugins/tmoyses/skeleton/init.lua
Normal file
27
lua/custom/plugins/tmoyses/skeleton/init.lua
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
-- my basic skeleton implementation
|
||||
vim.api.nvim_create_autocmd({'BufNewFile'}, {
|
||||
callback = function (args)
|
||||
local lines = vim.api.nvim_buf_get_lines(0, 0, vim.api.nvim_buf_line_count(0), false)
|
||||
local skeleton_files = vim.api.nvim_get_runtime_file('templates/skeleton.*', true)
|
||||
local skeleton_path = 'templates/skeleton.'
|
||||
|
||||
-- fist bail out if we have any lines in this file
|
||||
if #lines ~= 1 or lines[1] ~= "" then return end
|
||||
|
||||
-- now bail if we don't have any skeleton files
|
||||
if #skeleton_files == 0 then return end
|
||||
table.sort(skeleton_files, function (a, b) return #a>#b end)
|
||||
|
||||
for i,v in pairs(skeleton_files) do
|
||||
local start, finish = string.find(v, skeleton_path)
|
||||
local match = string.sub(v, finish+1, -1)
|
||||
if string.match(args.file, match .. '$') then
|
||||
-- we have a matching skel file so read it in
|
||||
vim.cmd('%!cat ' .. v)
|
||||
vim.notify("Skeleton file used to create file: " .. v, vim.log.levels.INFO, { title = "Sessions" })
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
desc = "Simple skeleton file function to match buffer name to a template and add the content to the new file"
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue