improved skeleton and moved to custom plugin
This commit is contained in:
parent
ce251cd13f
commit
d45eac3184
|
@ -3,3 +3,4 @@ test.sh
|
||||||
.luarc.json
|
.luarc.json
|
||||||
nvim
|
nvim
|
||||||
lazy-lock.json
|
lazy-lock.json
|
||||||
|
session.vim
|
||||||
|
|
65
init.lua
65
init.lua
|
@ -500,65 +500,6 @@ cmp.setup {
|
||||||
-- The line beneath this is called `modeline`. See `:help modeline`
|
-- The line beneath this is called `modeline`. See `:help modeline`
|
||||||
-- vim: ts=2 sts=2 sw=2 et
|
-- vim: ts=2 sts=2 sw=2 et
|
||||||
|
|
||||||
|
require('custom.plugins.tmoyses.keymaps')
|
||||||
-- my keymaps
|
require('custom.plugins.tmoyses.sessions')
|
||||||
vim.keymap.set('i', 'jk', '<Esc>', { desc="Back to normal mode from insert mode" });
|
require('custom.plugins.tmoyses.skeleton')
|
||||||
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"});
|
|
||||||
|
|
||||||
|
|
||||||
-- my basic session management
|
|
||||||
vim.api.nvim_create_autocmd({'VimEnter'}, {
|
|
||||||
callback = function ()
|
|
||||||
if vim.fn.filereadable('session.vim') then
|
|
||||||
vim.cmd('source session.vim')
|
|
||||||
vim.notify("Session Restored", vim.log.levels.info, {title = "Sessions"})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({'VimLeave'}, {
|
|
||||||
callback = function ()
|
|
||||||
vim.cmd('mks! session.vim')
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- my basic skeleton implementation
|
|
||||||
vim.api.nvim_create_autocmd({'BufNewFile'}, {
|
|
||||||
callback = function (args)
|
|
||||||
local extension = string.match(args.file, '\\.([^\\.])+$')
|
|
||||||
local basename = string.match(args.file, '([^\\/])+$')
|
|
||||||
|
|
||||||
print(vim.inspect(args.file))
|
|
||||||
local function is_file(path)
|
|
||||||
local f=io.open(path, "r")
|
|
||||||
if f~=nil then io.close(f) return true else return false end
|
|
||||||
end
|
|
||||||
if is_file('templates/skeleton.' .. basename) then
|
|
||||||
-- we have a match to a skeleton file
|
|
||||||
vim.cmd(':so templates/skeleton.' .. basename)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if is_file('templates/skeletoni.' .. extension) then
|
|
||||||
vim.cmd(':so templates/skeleton.' .. extension)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
|
@ -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"});
|
||||||
|
|
|
@ -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"
|
||||||
|
})
|
|
@ -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"
|
||||||
|
})
|
|
@ -0,0 +1,9 @@
|
||||||
|
this is a test file!
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
|
||||||
|
</template>
|
|
@ -0,0 +1 @@
|
||||||
|
print(string.match('foo.bar', "%..$"))
|
Loading…
Reference in New Issue