Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove text from all lines between two columns?

Tags:

vim

I would like to remove the content for all lines between two columns. How do I do this?

For example, I want this:

abcdefg
hijklmn
opqrstu

To become this if I remove text between columns 3 through 5:

abfg
himn
optu
like image 526
read Read Avatar asked May 17 '12 18:05

read Read


People also ask

How do I remove a string in Excel?

=LEFT(B3,LEN(B3)-1) The LEFT function returns the first characters, counting from the left end of the text string. The number of characters is given by the LEN function. LEN(B3)-1 means we remove 1 character from the value in B3 which is T6642. The resulting string minus the last character is T664.

How do I get rid of text after a character in Excel?

Remove Text After a Character Using Find and Replace If you want to quickly remove all the text after a specific text string (or before a text string), you can do that using Find and Replace and wild card characters.


2 Answers

Position your cursor in d, then press Ctrl-V, l, G and d.

  • Ctrl-v enters visual block mode;
  • l expands the visual selection one character to the right;
  • G expands the selection to the last line;
  • d deletes the selection.
like image 122
gonsalu Avatar answered Oct 05 '22 12:10

gonsalu


Your question is very similar to this one.

To delete the columns 3 through 5 for all lines in the file:

:%normal 3|d6|

In order to delete an specific line interval (80 to 90), use this:

:80,90normal 3|d6|

If you're not familiar with the normal command nor with the | "motion" there goes a quick explanation:

  1. The normal command execute the following commands in the normal mode;
  2. The | "motion" moves the cursor to a specified column, so 3| moves the cursor to the 3rd column;
  3. Then i deletes everything (d) until the 5th column (6|).
like image 28
Magnun Leno Avatar answered Oct 05 '22 12:10

Magnun Leno