How to replace text on a multiselection - vim

Suppose I have the following text selected in vim using ctrl-v e e:
To delete all the text I can press x (or d) and to insert new text I can do shift-I, but is there a way to replace that text directly? I want all those four items to say "video frame rate" instead of video resolution. How would I do that in the most efficient way in vim?

ctrl-v and other magic to select the block
press s or c
write the text you want
press ESC

Related

How can I easily edit after finding text in Sublime Text 3?

Whenever I do a sublime find, at some match I wish to add the text. But is there a shortcut to edit without moving mouse and clicking the text (to bring cursor to that location)
Example gif (issue I'm facing) - https://imgur.com/wTe3vcA
Just press Esc after finding your text.

How do I paste text at multi-line selection in vi?

I know how to use this with manual typing:
Use Ctrl+V to enter visual block mode
Move Up/Downto select the columns of text in the lines you want to comment.
Then hit Shift+i and type the text you want to insert.
Then hit Esc, wait 1 second and the inserted text will appear on every line.
But i don't want to want type the text. I want just to paste it.. (because is a long string..)
Thanks, Mor.
Once you are in insert mode (after I), you can press <C-r>" to insert the content of the default register or <C-r>a for register a to z.
You can also use completion in that context: <C-n> for example.
If the text you want to use is in a register, use <c-r> (CtrlR). So, after you press I, instead of typing, press CtrlR, and the register name you want.
Since the OS clipboard is in the + register, you would do: <c-r>+ (CtrlR++).

Vim: How to insert in visual block mode?

How can you insert when you are in visual block mode (by pressing ctrl-V) in Vim?
Try this
After selecting a block of text, press Shift+i or capital I.
Lowercase i will not work.
Then type the things you want and finally to apply it to all lines, press Esc twice.
If this doesn't work...
Check if you have +visualextra enabled in your version of Vim.
You can do this by typing in :ver and scrolling through the list of features. (You might want to copy and paste it into a buffer and do incremental search because the format is odd.)
Enabling it is outside the scope of this question but I'm sure you can find it somewhere.
press ctrl and v // start select
press shift and i // then type in any text
press esc esc // press esc twice
You might also have a use case where you want to delete a block of text and replace it .
Like this
Hello World
Hello World
You can visual block select before "W" and hit Shift+i - Type "Cool" - Hit ESC and then delete "World" by visual block selection .
Alternatively, the cooler way to do it is to just visual block select "World" in both lines. Type c for change. Now you are in the insert mode. Insert the stuff you want and hit ESC. Both gets reflected with lesser keystrokes.
Hello Cool
Hello Cool
if you want to add new text before or after the selected colum:
press ctrl+v
select columns
press shift+i
write your text
press esc
press "jj"

How to most easily duplicate a piece of text in Vim?

Let's say I have a piece of text within my code which I want duplicated.
What I've been doing so far is to move to the start, press v to enter visual mode, then move to the end, press y to yank the text, move one character back and then p to put it there.
Is there an easier way? Something like:
Select text with v.
Press some sequence of commands and there is - it's duplicated.
If it's the "move one char back" you're trying to avoid, press P rather than p for the "paste" operation.
You can always define custom macros / shortcuts on the fly.
map ! "+yP
will allow you to enter visual with v, mark the text, and use ! to duplicate it once (for extra duplicates, repeat p or P as needed.

How to paste something between html tags in Vim?

Pressing p pastes things bellow the current line, dit deletes things inside html tags. How do I paste something inside html tags?
Nor here
<p>I want to paste something here</p>
Not here
I usually just do vitp which visually selects the inner contents of the tag, then pastes over what is selected.
Works for me.
The result of pressing P and p depends on what you have in the selected register at the time. If you delete or yank one or more entire lines (e.g. with dd, Y or Vd commands), then pressing P will insert the contents of your register on the line above the current line, whereas p will insert on the line below the cursor.
If you delete or yank a section of text less than a line (e.g. with the D, or yw commands), then P will insert the contents of your register directly before the current cursor position, and p will insert directly after the cursor (i.e. on the same line).
If it helps, you could consider the linewise selection as being analogous to block html elements (such as <div>), and characterwise selection as being analogous to inline html elements (such as span).
So to answer your question: it depends. Supposing you have a linewise section of text in the register, you would want to break the target tag onto two lines before doing the paste operation. In your example, rather than doing dit to delete the contents of the tag, do cit to delete the same section and go into insert mode. Hit return once, to insert a new line, then esc to go back into normal mode, then P to insert your linewise register above the line with the closing tag.
If you didn't want to split the tag onto multiple lines, you would instead have to make sure that you yanked a characterwise selection into the register. Then you could run:
"_ditP
"_ deletes the text into the black hole register, ensuring it doesn't overwrite what is in your default register. dit deletes the contents of the tag, and P pastes the contents of your default register before the cursor position.
remove the current content between the tags with the command
cit
that will 'change in tags' and once that content is gone, you can paste with middle click or if you need go back into command mode and use your normal p/etc.
vitp should handle a linewise paste.
You can press "v" for visual, then go to where the cursor is, and press p or P.

Resources