LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-05-2011, 10:39 AM   #1
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Rep: Reputation: 16
delete lines in vim


Hi,

I've a big text, and I would like to delete several lines in vim. I was thinking in doing that with marks, but I can't do it.

Below it's an example text and I want to delete from <FROM HERE> to <TO HERE>. How can I do that?

Quote:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ac lectus quis velit semper euismod. Mauris dignissim venenatis faucibus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed vel leo sit amet magna ullamcorper sollicitudin. Nunc nec arcu tortor, ut eleifend nisi. Suspendisse at eros felis. Phasellus neque leo, posuere eget aliquet nec, faucibus malesuada elit. Etiam risus arcu, tincidunt non luctus sit amet, bibendum a tellus. Vestibulum tristique porttitor orci eu pretium. Aliquam sit amet fringilla enim. <FROM HERE>Curabitur adipiscing lectus eget nulla tincidunt auctor. Donec id orci sodales velit volutpat facilisis quis id massa. Morbi ante dui, luctus eu tincidunt aliquam, molestie eu metus. Donec elit enim, tempor eget ultrices ac, vulputate non mi. Suspendisse quis justo dui. Suspendisse suscipit, lectus nec tristique volutpat, diam sem porta nisl, ut sagittis velit<TO HERE> tellus non leo. Donec urna velit, tempor quis sagittis id, eleifend in libero. Aenean feugiat justo a ligula consectetur pharetra. Morbi condimentum enim quis leo convallis ac pellentesque velit tempor. Cras arcu quam, sodales eget lobortis vitae, laoreet ac magna.
 
Old 03-05-2011, 10:55 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,823
Blog Entries: 1

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
You can set marks in the places you want:
Code:
m1
Will set the mark "1" in the current cursor position. Set mark "2" at the end of the text you want to delete.

Then you can jump to mark 1:
Code:
`1
and delete from the current cursor position (ie. mark 1) to mark 2:
Code:
d`2
 
Old 03-05-2011, 11:08 AM   #3
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
sycamorex, thanks for the solution.

I also found another form using the visual mode. I put the visual mode from the start, and go to end of the text and put "dd".
 
Old 03-05-2011, 11:10 AM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,823
Blog Entries: 1

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
Yeah, I think it'd be quicker not to use marks in this situation.

You know you can delete a few lines in one go:

eg. 5dd will delete 5 lines.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to copy some lines in a file and delete these lines after gartura Linux - General 1 07-20-2010 08:55 AM
[SOLVED] Delete all lines containing a string, plus 4 lines below it? RedHelix Linux - Newbie 4 01-27-2010 09:13 AM
Delete Duplicate Lines in a file, leaving only the unique lines left xmrkite Linux - Software 6 01-14-2010 06:18 PM
VIM: How to delete all lines that include special words. cryincold Linux - Software 3 02-09-2008 11:17 PM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration