Browse Source

feat: add refactor plugin

master
Tovi Jaeschke-Rogers 6 days ago
parent
commit
11829946e6
5 changed files with 77 additions and 45 deletions
  1. +47
    -11
      .config/nvim/lua/core/autocmd.lua
  2. +20
    -0
      .config/nvim/lua/core/remaps.lua
  3. +1
    -0
      .config/nvim/lua/plugins/hardtime.lua
  4. +9
    -0
      .config/nvim/lua/plugins/refactor.lua
  5. +0
    -34
      .config/nvim/lua/plugins/telescope.lua

+ 47
- 11
.config/nvim/lua/core/autocmd.lua View File

@ -1,18 +1,20 @@
vim.api.nvim_set_hl(0, "YankColor", { fg = "#C8C093", bg = "#000000", ctermfg = 59, ctermbg = 41 })
local aucmd_dict = {
VimEnter = {
{
callback = function()
local function find_project_root()
local current_dir = vim.fn.getcwd()
local current_dir = vim.fn.getcwd()
while current_dir ~= "/" do
if vim.fn.isdirectory(current_dir .. "/.git") == 1 or vim.fn.filereadable(current_dir .. "/.nvim.lua") then
return current_dir
while current_dir ~= "/" do
if vim.fn.isdirectory(current_dir .. "/.git") == 1 or vim.fn.filereadable(current_dir .. "/.nvim.lua") then
return current_dir
end
current_dir = vim.fn.fnamemodify(current_dir, ":h")
end
current_dir = vim.fn.fnamemodify(current_dir, ":h")
end
return vim.fn.getcwd()
return vim.fn.getcwd()
end
local project_root = find_project_root()
@ -21,14 +23,14 @@ local aucmd_dict = {
if vim.fn.filereadable(project_specific_conf_file) == 1 then
vim.cmd("source " .. project_specific_conf_file)
print("Sourced project specific config file: " .. project_specific_conf_file)
end
end
end
}
},
FileType = {
{
-- Set tabstop to 2 for Dart, Vue, JavaScript, TypeScript, and JSON files
-- Set tabstop to 2 for Dart, Vue, JavaScript, TypeScript, and JSON files
pattern = "html,dart,vue,javascript,typescript,typescriptreact,json,markdown,css,sass",
callback = function()
vim.opt_local.tabstop = 2
@ -38,7 +40,7 @@ local aucmd_dict = {
},
{
pattern = 'dart',
callback = function ()
callback = function()
vim.bo.commentstring = '// %s'
end
},
@ -61,6 +63,27 @@ local aucmd_dict = {
},
},
BufReadPost = {
{
callback = function(event)
local exclude = { 'gitcommit', 'commit', 'gitrebase' }
local buf = event.buf
if
vim.tbl_contains(exclude, vim.bo[buf].filetype)
or vim.b[buf].lazyvim_last_loc
then
return
end
vim.b[buf].lazyvim_last_loc = true
local mark = vim.api.nvim_buf_get_mark(buf, '"')
local lcount = vim.api.nvim_buf_line_count(buf)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
},
},
BufNewFile = {
{
-- Set syntax for Dockerfiles
@ -70,6 +93,20 @@ local aucmd_dict = {
end
},
},
TextYankPost = {
{
callback = function()
vim.hl.on_yank { higroup = "YankColor", timeout = 250 }
end
},
},
VimResized = {
{
command="wincmd ="
},
},
}
for event, opt_tbls in pairs(aucmd_dict) do
@ -77,4 +114,3 @@ for event, opt_tbls in pairs(aucmd_dict) do
vim.api.nvim_create_autocmd(event, opt_tbl)
end
end

+ 20
- 0
.config/nvim/lua/core/remaps.lua View File

@ -62,3 +62,23 @@ vim.keymap.set("t", "<C-space>", "<C-\\><C-n>", { silent = true })
vim.keymap.set("n", "<leader>e", function() vim.cmd("edit notes.ignore.md") end)
vim.keymap.set("n", "<leader>.a", function() vim.cmd("edit app/api/.env") end)
vim.keymap.set("n", "<leader>.f", function() vim.cmd("edit app/frontend/.env.development.local") end)
-- Delete a buffer, without closing the window, see https://stackoverflow.com/q/4465095/6064933
vim.keymap.set("n", [[\d]], "<cmd>bprevious <bar> bdelete #<cr>", {
silent = true,
desc = "delete current buffer",
})
vim.keymap.set("n", [[\D]], function()
local buf_ids = vim.api.nvim_list_bufs()
local cur_buf = vim.api.nvim_win_get_buf(0)
for _, buf_id in pairs(buf_ids) do
-- do not Delete unlisted buffers, which may lead to unexpected errors
if vim.api.nvim_get_option_value("buflisted", { buf = buf_id }) and buf_id ~= cur_buf then
vim.api.nvim_buf_delete(buf_id, { force = true })
end
end
end, {
desc = "delete other buffers",
})

+ 1
- 0
.config/nvim/lua/plugins/hardtime.lua View File

@ -1,5 +1,6 @@
return {
"m4xshen/hardtime.nvim",
enabled = false,
lazy = false,
dependencies = {
"MunifTanjim/nui.nvim",


+ 9
- 0
.config/nvim/lua/plugins/refactor.lua View File

@ -0,0 +1,9 @@
return {
"ThePrimeagen/refactoring.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
},
lazy = false,
opts = {},
}

+ 0
- 34
.config/nvim/lua/plugins/telescope.lua View File

@ -169,39 +169,5 @@ return {
end)
vim.keymap.set("n", "<leader>u", "<cmd>Telescope undo<cr>")
keymap.set("n", "/", function()
builtin.current_buffer_fuzzy_find({
attach_mappings = function(prompt_bufnr, map)
-- Override the default select action
map('i', '<CR>', function()
local selection = action_state.get_selected_entry()
local prompt = action_state.get_current_line()
actions.close(prompt_bufnr)
-- Set the search register to the prompt text
if prompt and prompt ~= "" then
vim.fn.setreg('/', prompt)
end
-- Jump to the selected result with proper error handling
if selection then
-- Try different possible field names for line/column
local line = selection.lnum or selection.line_number or selection.row or 1
local col = selection.col or selection.column or selection.start_col or 0
-- Ensure we have valid numbers
if type(line) == "number" and type(col) == "number" then
-- Vim uses 1-based indexing for lines, 0-based for columns
vim.api.nvim_win_set_cursor(0, { line, col })
end
end
end)
return true
end,
})
end, {})
end,
}

Loading…
Cancel
Save