Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Vi: Search for word under cursor (or copy word to command line)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mirko K.  
View profile  
 More options Jul 4 2012, 4:18 pm
Newsgroups: comp.editors
From: "Mirko K." <mirkok.li...@googlemail.com>
Date: Wed, 04 Jul 2012 22:18:35 +0200
Local: Wed, Jul 4 2012 4:18 pm
Subject: Vi: Search for word under cursor (or copy word to command line)
Hi!

A friend of mine has to use plain Vi 3.10 on AIX, and he asked me
how to search for the word under the cursor like Vim's % or NVi  and
Elvis' CTRL-A.

I don't have access to AIX, but after reading its online docs, and
try with Levee and Vile, I came to the conclusion, that it is not
possible, mainly because there's no way to yank the current word (or
any other part of the file) to the command line, so you can't
constructing a /current_word command or mapping.

Is that correct, or did I overlook something?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Masinick  
View profile  
 More options Jul 14 2012, 4:50 pm
Newsgroups: comp.editors
From: Brian Masinick <brian.masin...@gmail.com>
Date: Sat, 14 Jul 2012 13:50:09 -0700 (PDT)
Local: Sat, Jul 14 2012 4:50 pm
Subject: Re: Vi: Search for word under cursor (or copy word to command line)

On Wednesday, July 4, 2012 4:18:35 PM UTC-4, Mirko K. wrote:
> Hi!

> A friend of mine has to use plain Vi 3.10 on AIX, and he asked me
> how to search for the word under the cursor like Vim&#39;s % or NVi  and
> Elvis&#39; CTRL-A.

> I don&#39;t have access to AIX, but after reading its online docs, and
> try with Levee and Vile, I came to the conclusion, that it is not
> possible, mainly because there&#39;s no way to yank the current word (or
> any other part of the file) to the command line, so you can&#39;t
> constructing a /current_word command or mapping.

> Is that correct, or did I overlook something?

To the best of my knowledge - but I do defer to others, if they happen to know anything more - the original Vi had forward and backward searches, and stuff like search again, but as far as I can recall, / - forward search; with text, searches for the text you provide; without text, repeats search, ? - reverse search; with text, searches backward for the text you provide; without text, searches backward, n - Repeat previous search, N - Repeat previous search, but it opposite direction.

I found some of the doc for the UNIX Vi editor at http://www.unix-manuals.com/refs/vi-ref/vi-ref.htm - perhaps that, or searches for similar documents, will fill in other missing gaps or questions.  Hope that is helpful.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Harris  
View profile  
 More options Jul 15 2012, 12:04 am
Newsgroups: comp.editors
From: Bob Harris <nospam.News....@remove.Smith-Harris.us>
Date: Sun, 15 Jul 2012 00:04:08 -0400
Local: Sun, Jul 15 2012 12:04 am
Subject: Re: Vi: Search for word under cursor (or copy word to command line)
In article
<799a92c9-5280-423c-8ba6-c206ed1046fd@googlegroups.com>,
 Brian Masinick <brian.masin...@gmail.com> wrote:

"------------------------------------
"
" Cntl/N - Find the word under the cursor.  NOTE: This
"          modifies the file.  This works similar to the Vim
"          '*' command (except Vim does not modify the file
"          in the process and * is a heck of a lot shorter,
"          and you do not need to define a key mapping :-)
"
map ^V^N ebywo^V^[pI/\<^V^[:s/[         ]*$/\\>/^V^M"qddb@q
"                              ^^^^^^^^^
"                              |||||||||
"                             <space><tab>
"
"          Here is a translation of the command:
"
"          ^V^N - This is a real Control/V and a real
"                 Control/N.  The Control/V allows the
"                 definition of Control/N as a mapped key.
"
"                 NOTE:  Entering a real Control/V into the .exrc
"                        generally requires typing Control/V
"                        twice.  Entering Control/N into the
"                        file generally requires typing
"                        Control/V Control/N.  Typing
"                        Control/V before any Control
"                        character you want to enter into
"                        the .exrc is typically how you
"                        enter a control character.
"          e    - go to end of current word (this will fail
"                 if the cursor happens to be on the very
"                 last character of the current word;
"                 generally not a problem).
"          b    - now go to the beginning of the word.  'eb'
"                 makes sure that we are at the beginning of
"                 the word to find.
"          yw   - yank a copy of the word.
"          o    - open a new line below the cursor.  This is
"                 where we are going to build a search
"                 command macro.  It is also where we end up
"                 causing the buffer to be modified even if
"                 we were only viewing the text read only :-(
"          ^V^[ - ^[ is ESC to exit insert mode, the
"                 Control/V is so that it can be entered via
"                 the .exrc file.
"          p    - put the yanked word into the new line.
"          I    - Enter Insert mode in front of the yanked
"                 word in the new line.
"          /\<  - Text to be inserted.  / is the start of a
"                 search command and \< is the notation to
"                 anchor the search to the beginning of
"                 matching words instead of finding string
"                 matches in the middle of larger words.
"          ^V^[ - ^[ is ESC to exit insert mode, the
"                 Control/V is so that it can be entered via
"                 the .exrc file.
"          :s///  Use the ex substitute command to remove
"                 any trailing white space (blanks and tabs)
"                 and then append \> to the end of the
"                 search command.  The \> is the notation to
"                 anchor the search to the end of matching
"                 words instead of finding string matches in
"                 the middle of longer words.
"          ^V^M - is the Carriage Return that executes the
"                 ex substitute command.
"          "qdd - The 'dd' deletes the new line into the
"                 named register 'q'.  So now the new line
"                 we created is no longer in the file and we
"                 now have a search macro that looks like:
"                     /\<search_word\>
"                 stored in the named register 'q'.
"          b    - when we deleted the new line, the cursor
"                 was sitting on the beginning of the next
"                 line.  'b' moves the cursor back to the
"                 line with our word in it, only it is
"                 positioned on the last word on our
"                 starting line.  If you want to change this
"                 to some other position on the line, just
"                 adjust the movement command which is
"                 currently a 'b'.
"          @q   - execute the macro stored in the named
"                 register 'q'.  This will be the search
"                 command looking for the word that was
"                 under the cursor when Control/N was
"                 issued.
"
"       What could be easier :-)  OK, I had tried to write
"       one of these on my own, but I finally found this in
"       a posting on the comp.editors news group.  The good
"       news is that I can actually understand it.
"
"------------------------------------

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eli the Bearded  
View profile  
 More options Jul 15 2012, 12:56 am
Newsgroups: comp.editors
From: Eli the Bearded <*...@eli.users.panix.com>
Date: Sun, 15 Jul 2012 04:56:58 +0000 (UTC)
Local: Sun, Jul 15 2012 12:56 am
Subject: Re: Vi: Search for word under cursor (or copy word to command line)
In comp.editors, Mirko K. <mirkok.li...@googlemail.com> wrote:

> A friend of mine has to use plain Vi 3.10 on AIX, and he asked me
> how to search for the word under the cursor like Vim's % or NVi  and
> Elvis' CTRL-A.

% jumps to matching (paren), {brace}, or [bracket], not search for
words. I think you mean # or *, which both do that in Vim (# is
a backwards search, while * is forwards).

> I don't have access to AIX, but after reading its online docs, and
> try with Levee and Vile, I came to the conclusion, that it is not
> possible, mainly because there's no way to yank the current word (or
> any other part of the file) to the command line, so you can't
> constructing a /current_word command or mapping.

Bwahhahah. If AIX has real vi, it can be done, albeit with a complex
macro. In the following line the <ESC> is supposed to be a real
escape. You can type it in vi with <ctrl-v><escape>.

" emulate * search as it exists in vim
" uses register w
:map * b"wyeo/\<\><ESC>F<"wp"wdd@w

The first 'b' is there to jump to the beginning of the word. You may
or may not like having it there. Breaking it down:

        b       jump to start of word
        "w use register w
        ye      yank to end of word
        o       start new line
        /\<\>     put blank search command in (\< and \> for word boundaries)
        <ESC>     stop insert
        F<   jump backwards to the <
        "w use register w
        p       put the word we yanked
        "w use register w
        dd      delete the line
        @w      run the command in register w

Elijah
------
emulating # left as an exercise for the reader


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eli the Bearded  
View profile  
 More options Jul 15 2012, 1:00 am
Newsgroups: comp.editors
From: Eli the Bearded <*...@eli.users.panix.com>
Date: Sun, 15 Jul 2012 05:00:35 +0000 (UTC)
Local: Sun, Jul 15 2012 1:00 am
Subject: Re: Vi: Search for word under cursor (or copy word to command line)
In comp.editors, Bob Harris  <nospam.News....@remove.Smith-Harris.us> wrote:

> map ^V^N ebywo^V^[pI/\<^V^[:s/[         ]*$/\\>/^V^M"qddb@q

Wow, that's ugly. :^) Mine, posted elsewhere in this thread is
shorter.

:map * b"wyeo/\<\><ESC>F<"wp"wdd@w

Read the explanation in the post I wrote it for.

Elijah
------
you shouldn't need three escaped control characters


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mirko K.  
View profile  
 More options Aug 8 2012, 7:19 pm
Newsgroups: comp.editors
From: "Mirko K." <mirkok.li...@googlemail.com>
Date: Thu, 09 Aug 2012 01:19:41 +0200
Local: Wed, Aug 8 2012 7:19 pm
Subject: Re: Vi: Search for word under cursor (or copy word to command line)
Sorry for the late reply, waited for response from my friend which
didn't came.

On 15.07.2012 06:56, Eli the Bearded wrote:

> In comp.editors, Mirko K. <mirkok.li...@googlemail.com> wrote:
>> A friend of mine has to use plain Vi 3.10 on AIX, and he asked me
>> how to search for the word under the cursor like Vim's % or NVi  and
>> Elvis' CTRL-A.

> % jumps to matching (paren), {brace}, or [bracket], not search for
> words. I think you mean # or *, which both do that in Vim (# is
> a backwards search, while * is forwards).

Correct, not sure how I could mistype * with % (some Parsecs away on
a German keyboard) ;-)

>> I don't have access to AIX, but after reading its online docs, and
>> try with Levee and Vile, I came to the conclusion, that it is not
>> possible, mainly because there's no way to yank the current word (or
>> any other part of the file) to the command line, so you can't
>> constructing a /current_word command or mapping.

> Bwahhahah. If AIX has real vi, it can be done, albeit with a complex
> macro.

Thanks for your efforts (also to Bob Harris and others), but
changing the file isn't really an option. I played with similar ways
(but didn't got it to work), but said friend works with make and
version control systems, accidentally writing such a (not really
changed) file can probably cause problems.

I keep with my original suggestion to somehow get NVi/Vim on that
machine.

Thanks anyway for your solutions, learned something about registers. :-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
toothpik  
View profile  
 More options Aug 14 2012, 2:55 pm
Newsgroups: comp.editors
From: toothpik <nos...@spamhaters.com>
Date: Tue, 14 Aug 2012 13:55:45 -0500
Local: Tues, Aug 14 2012 2:55 pm
Subject: Re: Vi: Search for word under cursor (or copy word to command line)

can't you add an

    e!

to restore it and preserve the timestamp?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »