Skip to content

Commit

Permalink
✨ add yank_history,undo_history and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shelken committed Apr 18, 2024
1 parent 397e195 commit deccde7
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 21 deletions.
20 changes: 20 additions & 0 deletions lua/plugins/astrocore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ return {
["<Leader>b"] = { desc = "Buffers" },
-- quick save
-- ["<C-s>"] = { ":w!<cr>", desc = "Save File" }, -- change description but the same command

-- comment-box
["<Leader>mm"] = {":CBccbox", desc = "美化注释"},

-- undo history
["<Leader>uh"] = { "<cmd>Telescope undo<cr>", desc = "Telescope undo" },
-- yank_history
["<Leader>yh"] = {
function() require("telescope").extensions.yank_history.yank_history() end,
desc = "Preview Yank History",
},

},
x = {
-- comment-box
["<Leader>mm"] = {":CBccbox", desc = "美化注释"},
},
v = {
-- comment-box
["<Leader>mm"] = {":CBccbox", desc = "美化注释"},
},
t = {
-- setting a mapping to false will disable it
Expand Down
52 changes: 51 additions & 1 deletion lua/plugins/astrolsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
---@type LazySpec
return {
"AstroNvim/astrolsp",
---@type AstroLSPOpts
opts = {
-- Configuration table of features provided by AstroLSP
features = {
Expand Down Expand Up @@ -118,8 +117,59 @@ return {
-- desc = "Toggle LSP semantic highlight (buffer)",
-- cond = function(client) return client.server_capabilities.semanticTokensProvider and vim.lsp.semantic_tokens end,
-- },

-- refactoring
["<Leader>ri"] = {
function() require("refactoring").refactor "Inline Variable" end,
desc = "Inverse of extract variable",
},
["<Leader>rb"] = { function() require("refactoring").refactor "Extract Block" end, desc = "Extract Block" },
["<Leader>rbf"] = {
function() require("refactoring").refactor "Extract Block To File" end,
desc = "Extract Block To File",
},
["<Leader>rr"] = {
function() require("telescope").extensions.refactoring.refactors() end,
desc = "Prompt for a refactor to apply",
},
["<Leader>rp"] = {
function() require("refactoring").debug.printf { below = false } end,
desc = "Insert print statement to mark the calling of a function",
},
["<Leader>rv"] = {
function() require("refactoring").debug.print_var() end,
desc = "Insert print statement to print a variable",
},
["<Leader>rc"] = {
function() require("refactoring").debug.cleanup {} end,
desc = "Cleanup of all generated print statements",
},
},
x = {
-- refactoring
["<Leader>ri"] = {
function() require("refactoring").refactor "Inline Variable" end,
desc = "Inverse of extract variable",
},
["<Leader>re"] = {
function() require("refactoring").refactor "Extract Function" end,
desc = "Extracts the selected code to a separate function",
},
["<Leader>rf"] = {
function() require("refactoring").refactor "Extract Function To File" end,
desc = "Extract Function To File",
},
["<Leader>rv"] = {
function() require("refactoring").refactor "Extract Variable" end,
desc = "Extracts occurrences of a selected expression to its own variable",
},
["<Leader>rr"] = {
function() require("telescope").extensions.refactoring.refactors() end,
desc = "Prompt for a refactor to apply",
},
},
},
-- visual mode(what's the difference between v and x???)
-- A custom `on_attach` function to be run after the default `on_attach` function
-- takes two parameters `client` and `bufnr` (`:h lspconfig-setup`)
on_attach = function(client, bufnr)
Expand Down
13 changes: 7 additions & 6 deletions lua/plugins/auto-save.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---@type LazySpec
return {
-- "0x00-ketsu/autosave.nvim",
-- -- lazy-loading on events
-- event = { "InsertLeave", "TextChanged" },
-- opts = function(_, opts)
-- opts.prompt_style = "stdout" -- notify or stdout
-- end,
"0x00-ketsu/autosave.nvim",
-- lazy-loading on events
event = { "InsertLeave", "TextChanged" },
opts = function(_, opts)
opts.prompt_style = "stdout" -- notify or stdout
end,
enabled = false,
}
14 changes: 0 additions & 14 deletions lua/plugins/comment-box.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
---@type LazySpec
return {
"LudoPinelli/comment-box.nvim",
keys = {
{
mode = "v",
"<leader>mm",
":CBccbox",
desc = "美化注释",
},
{
mode = "n",
"<leader>mm",
":CBccbox",
desc = "美化注释",
},
},
}
8 changes: 8 additions & 0 deletions lua/plugins/refactoring.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---@type LazySpec
return {
"ThePrimeagen/refactoring.nvim",
dependencies = {
{ "nvim-lua/plenary.nvim" },
{ "nvim-treesitter/nvim-treesitter" },
},
}
51 changes: 51 additions & 0 deletions lua/plugins/telescope.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---@type LazySpec
return {
"nvim-telescope/telescope.nvim",
branch = "0.1.x",
dependencies = { "nvim-lua/plenary.nvim" },
init = function()
-- 1. Disable highlighting for certain filetypes
-- 2. Ignore files larger than a certain filesize
local previewers = require "telescope.previewers"

local _bad = { ".*%.csv", ".*%.min.js" } -- Put all filetypes that slow you down in this array
local filesize_threshold = 300 * 1024 -- 300KB
local bad_files = function(filepath)
for _, v in ipairs(_bad) do
if filepath:match(v) then return false end
end
return true
end

local new_maker = function(filepath, bufnr, opts)
opts = opts or {}
if opts.use_ft_detect == nil then opts.use_ft_detect = true end

-- 1. Check if the file is in the bad_files array, and if so, don't highlight it
opts.use_ft_detect = opts.use_ft_detect == false and false or bad_files(filepath)

-- 2. Check the file size, and ignore it if it's too big(preview nothing).
filepath = vim.fn.expand(filepath)
vim.loop.fs_stat(filepath, function(_, stat)
if not stat then return end
if stat.size > filesize_threshold then
return
else
previewers.buffer_previewer_maker(filepath, bufnr, opts)
end
end)

-- Load Extensions
require("telescope").load_extension "refactoring"
require("telescope").load_extension "yank_history"
require("telescope").load_extension "undo"
end

require("telescope").setup {
defaults = {
buffer_previewer_maker = new_maker,
},
}
end,

}
4 changes: 4 additions & 0 deletions lua/plugins/undo-tree.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---@type LazySpec
return {
"debugloop/telescope-undo.nvim"
}
62 changes: 62 additions & 0 deletions lua/plugins/yank.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
-- clipboard manager
return {
"gbprod/yanky.nvim",
opts = function()
local mapping = require "yanky.telescope.mapping"
local mappings = mapping.get_defaults()
mappings.i["<c-p>"] = nil
return {
highlight = { timer = 200 },
picker = {
telescope = {
use_default_mappings = false,
mappings = mappings,
},
},
}
end,
keys = {
{
"y",
"<Plug>(YankyYank)",
mode = { "n", "x" },
desc = "Yank text",
},
{
"p",
"<Plug>(YankyPutAfter)",
mode = { "n", "x" },
desc = "Put yanked text after cursor",
},
{
"P",
"<Plug>(YankyPutBefore)",
mode = { "n", "x" },
desc = "Put yanked text before cursor",
},
-- {
-- "gp",
-- "<Plug>(YankyGPutAfter)",
-- mode = { "n", "x" },
-- desc = "Put yanked text after selection",
-- },
-- {
-- "gP",
-- "<Plug>(YankyGPutBefore)",
-- mode = { "n", "x" },
-- desc = "Put yanked text before selection",
-- },
-- { "[y", "<Plug>(YankyCycleForward)", desc = "Cycle forward through yank history" },
-- { "]y", "<Plug>(YankyCycleBackward)", desc = "Cycle backward through yank history" },
-- { "]p", "<Plug>(YankyPutIndentAfterLinewise)", desc = "Put indented after cursor (linewise)" },
-- { "[p", "<Plug>(YankyPutIndentBeforeLinewise)", desc = "Put indented before cursor (linewise)" },
-- { "]P", "<Plug>(YankyPutIndentAfterLinewise)", desc = "Put indented after cursor (linewise)" },
-- { "[P", "<Plug>(YankyPutIndentBeforeLinewise)", desc = "Put indented before cursor (linewise)" },
-- { ">p", "<Plug>(YankyPutIndentAfterShiftRight)", desc = "Put and indent right" },
-- { "<p", "<Plug>(YankyPutIndentAfterShiftLeft)", desc = "Put and indent left" },
-- { ">P", "<Plug>(YankyPutIndentBeforeShiftRight)", desc = "Put before and indent right" },
-- { "<P", "<Plug>(YankyPutIndentBeforeShiftLeft)", desc = "Put before and indent left" },
-- { "=p", "<Plug>(YankyPutAfterFilter)", desc = "Put after applying a filter" },
-- { "=P", "<Plug>(YankyPutBeforeFilter)", desc = "Put before applying a filter" },
},
}

0 comments on commit deccde7

Please sign in to comment.