Is there a more efficient way to replace text in vim using the visual command?

  • Thread starter Thread starter DrDu
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around the efficiency of replacing text in Vim using the visual command, particularly when transferring text between different files. Participants explore methods for improving the process of yanking and pasting text, as well as the limitations of the visual command.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses dissatisfaction with the visual command for replacing text, noting the inability to specify a region explicitly and the issue of the yank buffer being overwritten.
  • Another participant inquires about the method of opening files, suggesting that opening files from within the yank file might yield different results.
  • A participant mentions using different windows for file management, indicating a preference for that method.
  • There is a suggestion to open documents within the same Vim instance to facilitate pasting, although one participant notes challenges with pasting from external sources.
  • One participant proposes using the :e command instead of :open for easier navigation and file management.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method for replacing text in Vim, as multiple approaches and challenges are discussed without resolution.

Contextual Notes

Participants mention limitations related to the operating system and the challenges of pasting from external sources, which may affect the proposed solutions.

Who May Find This Useful

This discussion may be useful for Vim users looking for efficient text replacement methods, particularly those who frequently work with multiple files or external text sources.

DrDu
Science Advisor
Messages
6,423
Reaction score
1,004
I have a recurrent vim problem:
Often, I want to replace part of a file (call it B) with text from some other file (A).
So in A I select the lines in question and yank them.

Now in B i use the visual command to select the region I want to replace.
I am not happy with it for two reasons:
1. I would prefer to specify the region explicitly, something like: 1,20v
however this seems not to be possible with the visual command.
2. the visual command replaces the text in the yank buffer with the text deleted upon paste.
If I want to repeat the operation in another file C, I have to yank the text in file A again.

There must be some more elegant way, however I didn't find it.
 
Physics news on Phys.org
When you open B and C, are you opening them from within A like:

:open (B)
:open (C)

?
 
No, usually, I use different windows.
 
Try openng each of the paste files from your yank file. It might depend on your OS (I used slackware last time I was messing with this) but that seemes ti work for me.
 
Ok, thank you, I will give this a try. However, I often copy from outside, i.e. form the clipboard, e.g. from a pdf, so this won't work always.
 
If you are able to paste into one vim instance from outside, you might be able to open documents within that vim instance and continue to paste (I always have annoying issues trying to paste from outside, so I don't know). Can always yank it right after you paste it in the first file, too. Often, getting it to actually paste into the first term is where I always have issues (slackware 14.0).
 
I just realized a slightly easier way to do this. Instead of :open, use :e it allows you to auto-complete with TAB as you dig into directories.
 

Similar threads

  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
1
Views
4K
  • · Replies 29 ·
Replies
29
Views
7K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 14 ·
Replies
14
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K