In article
<799a92c9-5280-423c-8ba6-c206ed1046fd@googlegroups.com>,
Brian Masinick <brian.masin
...@gmail.com> wrote:
> 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'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?
> 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.
"------------------------------------
"
" 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.
"
"------------------------------------