Sometimes I want to edit a certain visual block of text across multiple lines.
For example, I would take a text that looks like this:
name comment phone email
And make it look like this
vendor_name vendor_comment vendor_phone vendor_email
Currently the way I would do it now is...
" vendor_"
without the quote. Notice the extra space we had to put back.I don't need to indent if there is at least one column of whitespace before the words. I wouldn't need the whitespace if I didn't have to clear the visual block with c.
But if I have to clear, then is there a way to do what I performed above without creating the needed whitespace with indentation?
Also why does editing multiple lines at once only work by exiting out of insert mode with Esc over Ctrlc?
Here is a more complicated example:
name = models.CharField( max_length = 135 ) comment = models.TextField( blank = True ) phone = models.CharField( max_length = 135, blank = True ) email = models.EmailField( blank = True )
to
name = models.whatever.CharField( max_length = 135 ) comment = models.whatever.TextField( blank = True ) phone = models.whatever.CharField( max_length = 135, blank = True ) email = models.whatever.EmailField( blank = True )
In this example I would perform the vertical visual block over the .
, and then reinsert it back during insert mode, i.e., type .whatever.
. Hopefully now you can see the drawback to this method. I am limited to only selecting a column of text that are all the same in a vertical position.
To insert some text repeatedly in Vim, say you want to insert '-' for 30 times. Thats it, you can use this to repeat any text in simple steps.
You can edit multiple lines simultaneously by inserting text inside a multi-line selection in Vim : Use Ctrl+V to enter visual block mode Move down with jj to select the columns of text in the lines you want to comment. Then hit Shift+I and type the text you want to insert.
n
in name
.I
(capital i).vendor_
. Note: It will only update the screen in the first line - until Esc is pressed (6.), at which point all lines will be updated.An uppercase I
must be used rather than a lowercase i
, because the lowercase i
is interpreted as the start of a text object, which is rather useful on its own, e.g. for selecting inside a tag block (it
):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With