Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-28-2009, 07:27 PM   #1
Registered: Sep 2009
Posts: 36

Rep: Reputation: 16
VI question on copy paste

How do you find the last occurence of a character/string in a line? I ask because I was trying to edit this line:

So I want to copy only from the first '/' up to the last '/' before 'bdump'. Right now I only do 'y$' then I just edit the last word. Is this possible? Thanks.
Old 10-28-2009, 07:44 PM   #2
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,395

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
Well, a basic search fwd is '/' key (ie /<pattern>), but searching for a '/' require a '\' esc ie


will find first occurrence of '/', measured from the current cursor position(!). The search backwards key is '?'. Note that vi search remembers the last pattern used, so you don't have to repeat the pattern.
'n' repeats the search for next occurrence, in the direction last specified.

However, sounds like you're looking for a search/copy/reuse ? Personally, I'm nearly always in an xterm, so I use the mouse copy/paste, it's easier.
Can you show an example of what you are trying to do?
Old 10-28-2009, 07:51 PM   #3
Registered: Sep 2009
Posts: 36

Original Poster
Rep: Reputation: 16
Basically sometimes I have several key=value configs, where the value has some repeating strings like on this one the path before the final directory. So I have some


I just thought there might be something like 'y<up to last occurence of this character on this line>' command =) Although I could also just copy first the path to the folder without the 'last folder'.

Tested the combination of 'y' and 'm', which I mean: marking your starting position, go to last position ( plus one character ) then 'y' then go back to starting position ( marked position ) . Lot of keyinputs to me =(

Last edited by mortonmorton; 10-28-2009 at 08:03 PM.


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
Copy and paste posix_memalign Linux - Software 14 07-05-2009 12:06 PM
A simple question on copy and paste satimis Fedora 4 06-02-2006 06:13 AM
a windows question..copy&paste.. desperate.. doublefailure General 3 08-15-2004 05:49 PM
xpdf - copy and paste question satimis Linux - Software 4 05-09-2004 10:47 AM
how to copy and paste acd copy cd paschim Linux - General 2 04-05-2004 09:25 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:09 AM.

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