Monday, January 25, 2021

Re: how to replace selected text using keyboard shortcut

Another mapping that does the job: vnoremap <C-b> s<h1><C-r>"</h1>

"s" in visual mode deletes the selected text (which puts the deleted text in the " register) and then enters insert mode.

In insert mode, <C-r>" inserts the contents of the " register. See ":help i^r" for more about inserting registers during insert.

On Wednesday, January 6, 2021 at 2:12:44 AM UTC-5 pengembar...@gmail.com wrote:
Dear all,

Sorry if this question is already asked before, but googling does not give enough result, maybe wrong search key.

what i want to do is:
- select text using mouse/trackpad (i'm in wondows).
- press some control-key to replace that text.

example, i have following line in file:
===
one
two
three
===

result:
===
<h1>one</h1>
<h2>two</h2>
three
===

usually what i am doing is:
:%s'one'<h1>one</h1>'
:%s'two'<h2>two</h2>'

can i change with:
1. select 'one' with mouse
2. Press <Ctrl-B> (or some other combination) to convert it to <h1>one</h1>.
So Ctrl-B is associated with <h1> and </h1> tag.
3. select 'two' with mouse
4. press Ctrl-2 (or other combination) to convert to '<h2>two</h2>'.
Ctrl-2 is associated with <h2> and </h2> tag.

thanks.


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/02dbb4ff-fb6d-4a15-97af-5ba8862e24b7n%40googlegroups.com.

No comments:

Post a Comment