Skip to content

Commit

Permalink
feat: implement support for visual line mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wassimk committed Jun 5, 2024
1 parent 9201410 commit d7d202d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,33 @@ The following example shows the installation process using [lazy.nvim](https://g
}
```

> [!NOTE]
> You can set the keymap to anything you wish.
## Usage

Using **scalpel.nvim** is simple:
#### Normal Mode

1. Move the cursor over the word to replace
2. Trigger the substitution with your keymap
3. Begin typing the desired substitution and hit return

#### Visual Mode

1. Use visual mode (`v`) to select the word(s) to replace within a *single line*
2. Trigger the substitution with your keymap
3. Begin typing the desired substitution and hit return

1. Move the cursor over the word you wish to replace.
2. Trigger the substitution with the `<leader>e` keymap.
3. Begin typing your desired substitution and hit return. Note that the original word is being captured, so if you would like to incorporate it into your replacement, use `\1`.
#### Visual Line Mode

This plugin also supports visual mode selection for substitutions within a single line.
1. Highlight word(s) to substitute with `*` or `/`
2. Use visual line mode (`V`) to highlight the lines with the word(s) to substitute
3. Trigger the substitution with your keymap
4. Begin typing the desired substitution and hit return

> [!TIP]
> The word(s) being replaced during substitution are available in the replacement text using `&`.
>
## Acknowledgments

This project was inspired by [Scalpel](https://github.com/wincent/scalpel), a Vimscript plugin I've used for many years. **scalpel.nvim** is my version reimagined and implemented in Lua for fun.
This project was inspired by [Scalpel](https://github.com/wincent/scalpel), a Vimscript plugin I've used for many years. **scalpel.nvim** is my version, which was reimagined and implemented in Lua for fun.
5 changes: 3 additions & 2 deletions lua/scalpel/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ function M.substitute()
local word = get_substitution_word()

if vim.fn.mode() == 'V' then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', false, true, true), 'nx', false)
vim.notify('Visual line mode not supported for substitution selection', vim.log.levels.WARN)
local pattern = ':s///gc'
local cursor_move = vim.api.nvim_replace_termcodes('<Left><Left><Left>', true, false, true)
vim.api.nvim_feedkeys(pattern .. cursor_move, 'n', true)
elseif word == nil then
vim.notify('Cannot substitute this selection', vim.log.levels.INFO)
elseif is_blank(word) then
Expand Down

0 comments on commit d7d202d

Please sign in to comment.