A small Neovim plugin for pattern-based renames with cgn and . repeat.
{
'zmunk/dot-rename.nvim',
opts = {
mappings = {
visual = '<leader>r',
normal = '<leader>rw',
},
},
}The plugin now starts renames with :RenamePattern / :rename and applies the
first replacement immediately with cgn.
- no separate resume mapping
- works from a pattern/replacement pair
- uses whatever delimiter you put first
You can start a rename in any of these forms:
:RenamePattern /from/to
:rename /from/to
:rename/from/toRules:
- the first character is the delimiter
fromis a Vim search patterntois inserted as plain replacement text- escape the delimiter inside either side, e.g.
:rename /foo\/bar/baz/
If the pattern is found, the plugin:
- stores it in the search register
- enables search highlighting
- runs
cgnwith the replacement on the current match - lets you continue with
n+.
With the normal mapping:
- place the cursor on a word
- trigger your mapping (for example
<leader>rw) - edit the command line
- press
<CR> - use
nand.to keep renaming matches
The mapping pre-fills this command shape:
:RenamePattern/\<word\>/wordSo normal-mode rename matches whole words only.
With the visual mapping:
- select text
- trigger your mapping (for example
<leader>r) - edit the command line
- press
<CR> - use
nand.to keep renaming matches
The visual mapping pre-fills the selected text as both pattern and replacement, so you can quickly change the replacement or both sides.
require('dot-rename').setup({
mappings = {
visual = '<leader>r',
normal = '<leader>rw',
},
})mappings.visual and mappings.normal are optional.
njumps to the next matchNjumps to the previous match.repeats the last rename on the current match:nohclears highlight when you are done
MIT. See LICENSE.