mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-03-25 19:01:43 +01:00
feat: neovim - find and search globally, refactoring
This commit is contained in:
@@ -99,8 +99,7 @@ return {
|
||||
},
|
||||
}
|
||||
},
|
||||
-- The plugin offers the `:Refactor` command to refactor code.
|
||||
-- TODO not work yet
|
||||
-- The plugin offers the alibity to refactor code.
|
||||
{
|
||||
"ThePrimeagen/refactoring.nvim",
|
||||
dependencies = {
|
||||
@@ -108,8 +107,7 @@ return {
|
||||
{"nvim-treesitter/nvim-treesitter"}
|
||||
}
|
||||
},
|
||||
-- The plugin offers the `:Spectre` command to search and replace.
|
||||
-- TODO not work yet
|
||||
-- The plugin offers the abilibty to search and replace.
|
||||
{
|
||||
"nvim-pack/nvim-spectre",
|
||||
dependencies = {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
-- lower level configuration and more robust one. (which-key will
|
||||
-- automatically pick-up stored data by this setting.)
|
||||
local utils = require "astronvim.utils"
|
||||
require("telescope").load_extension("refactoring")
|
||||
return {
|
||||
-- first key is the mode
|
||||
n = {
|
||||
@@ -13,6 +14,32 @@ return {
|
||||
-- quick save
|
||||
["<C-s>"] = { ":w!<cr>", desc = "Save File" }, -- change description but the same command
|
||||
["<leader>tp"] = { function() utils.toggle_term_cmd("ipython") end, desc = "ToggleTerm python" },
|
||||
|
||||
-- search and replace globally
|
||||
['<leader>ss'] = {'<cmd>lua require("spectre").toggle()<CR>', desc = "Toggle Spectre" },
|
||||
['<leader>sw'] = {'<cmd>lua require("spectre").open_visual({select_word=true})<CR>', desc = "Search current word" },
|
||||
['<leader>sp'] ={'<cmd>lua require("spectre").open_file_search({select_word=true})<CR>', desc = "Search on current file" },
|
||||
|
||||
-- refactoring
|
||||
["<leader>ri"] = { function() require('refactoring').refactor('Inline Variable') end, desc = "Refactoring Inline 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 = "Print debug info" },
|
||||
["<leader>rv"] = { function() require('refactoring').debug.print_var() end, desc = "Print debug var" },
|
||||
["<leader>rc"] = { function() require('refactoring').debug.cleanup({}) end, desc = "Cleanup debugging" },
|
||||
},
|
||||
v = {
|
||||
-- search and replace globally
|
||||
['<leader>sw'] = {'<esc><cmd>lua require("spectre").open_visual()<CR>', desc = "Search current word" },
|
||||
},
|
||||
x = {
|
||||
-- refactoring
|
||||
["<leader>ri"] = { function() require('refactoring').refactor('Inline Variable') end, desc = "Refactoring Inline Variable" },
|
||||
["<leader>re"] = { function() require('refactoring').refactor('Extract Function') end, desc = "Extract 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 = "Extract Variable" },
|
||||
["<leader>rr"] = { function() require('telescope').extensions.refactoring.refactors() end, desc = "Prompt for a refactor to apply" },
|
||||
},
|
||||
t = {
|
||||
-- setting a mapping to false will disable it
|
||||
|
||||
@@ -85,6 +85,10 @@
|
||||
# 2. `c` means ask for confirmation before replacing.
|
||||
# 3. `i` means ignore case.
|
||||
#
|
||||
# Seach and replace globally:
|
||||
# 1. Open Spectre search and replace panel: `<Space> + ss`
|
||||
# 2. search and replace in command line: `find -name "*.nix" | sad '<pattern>' '<replacement>' | delta`
|
||||
#
|
||||
# Joining a Selection of Lines With Space: `:join`
|
||||
# Joining without spaces: `:join!`
|
||||
#
|
||||
@@ -94,12 +98,6 @@
|
||||
#
|
||||
# Save the selected text to a file: `:w filename` (will show `:'<,'>w filename`)
|
||||
#
|
||||
# Search key pattern and Replace in Multiple Files:
|
||||
# sed -ri "s/pattern_str/replace_str/g" $(grep "key_pattern" 'path_pattern' -rl)
|
||||
#
|
||||
# Search file name pattern and Replace in Multiple Files:
|
||||
# sed -ri "s/pattern_str/replace_str/g" $(find . -name "pattern")
|
||||
#
|
||||
# ......
|
||||
# See https://astronvim.com/Basic%20Usage/walkthrough
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user