Highlighting with [I and ]I

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

Highlighting with [I and ]I

Jeenu V

Hi Vimmers,

Is there any way to display the word under cursor highlighted when
doing [I or ]I? I think that would be a useful feature, if it's not
already there

Thanks
Jeenu


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

François Ingelrest-2

You can try the star, it will highlight the word under the cursor and
will search for the next one. If you just want the highlight feature,
I guess you could write a map to start the search with the star, and
then to go to the previous word immediately.

On 8/10/07, Jeenu <[hidden email]> wrote:
> Hi Vimmers,
>
> Is there any way to display the word under cursor highlighted when
> doing [I or ]I? I think that would be a useful feature, if it's not
> already there
>
> Thanks
> Jeenu

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Jeenu V

Yup, the '*' and '#" does highlight the word. '[I' and ']I' would give
you the summary of the word (usually an identifier) for that (and
included files as well) file, all at one place. Highlighting the
particular word in the summary itself would have been useful, in that
you don't get distracted searching the word in the result.

I was looking something that looks like the output of 'grep --color',
in which the required pattern is highlighted (In our case, the word-
under-cursor)


On Aug 10, 4:59 pm, "François Ingelrest" <[hidden email]> wrote:

> You can try the star, it will highlight the word under the cursor and
> will search for the next one. If you just want the highlight feature,
> I guess you could write a map to start the search with the star, and
> then to go to the previous word immediately.
>
> On 8/10/07, Jeenu <[hidden email]> wrote:
>
> > Hi Vimmers,
>
> > Is there any way to display the word under cursor highlighted when
> > doing [I or ]I? I think that would be a useful feature, if it's not
> > already there
>
> > Thanks
> > Jeenu


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

tommm0
In reply to this post by Jeenu V

Hi,

  there's also a very nice vim script plugin at vim online home.
See: http://www.vim.org/scripts/script.php?script_id=1238
Pressing \m highlights the word under the cursor. And it can
also highlight several words in different colors simultaneously.

Tom


On Aug 10, 9:09 am, Jeenu <[hidden email]> wrote:
> Hi Vimmers,
>
> Is there any way to display the word under cursor highlighted when
> doing [I or ]I? I think that would be a useful feature, if it's not
> already there
>
> Thanks
> Jeenu


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Noah Spurrier
In reply to this post by Jeenu V

On 2007-08-10 13:20-0000, Jeenu wrote:
>I was looking something that looks like the output of 'grep --color',
>in which the required pattern is highlighted (In our case, the word-
>under-cursor)

Is this what you mean?

     :set hlsearch

But my favorite trick is to turn every line that contains the pattern
into a fold. I map this to \z (the backslash key then the z key).

     " This folds every line that does not contain the search pattern.
     " First set the search pattern with / or * or # then
     " type \z (backslash then z).
     map <silent><leader>z :set foldexpr=(getline(v:lnum)=~@/)?\">1\":\"=\" foldlevel=0 foldcolumn=0 foldmethod=expr<CR>

I also remap the SPACE key to toggle the folds.

     " space toggles the fold under the cursor.
     nnoremap <silent><space> :exe 'silent! normal! za'.(foldlevel('.')?'':'l')<CR>

--
  Noah Spurrier | email: [hidden email] | http://www.noah.org/wiki/engineering 
-------------------------------------------------------------------------------

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Jeenu V

Folks, thanks for all the inputs.

I'm afraid what I wanted is different. If you have ever seen the grep
with the "--color" option, you could see all the lines of occurrences,
with the word/pattern highlighted (Highlighted - I mean the rendering
color is something different from the rest of text, either background
or foreground).

When "[I" or "]I" is done, what I get is the same grep output without
the --color option. So, most of the time, I get distracted spotting
the word in the results. Of course I can use a "*" or "#" to follow
the occurences or use a highlighting plugin, but all of them are a
kind of navigation, which might involve lot of movements. But [I that
I seek is something like a shop-at-one-place, with some kind of
highlighting that lets you spot the item instantly.

On Aug 10, 9:23 pm, Noah Spurrier <[hidden email]> wrote:

> On 2007-08-10 13:20-0000, Jeenu wrote:
>
> >I was looking something that looks like the output of 'grep --color',
> >in which the required pattern is highlighted (In our case, the word-
> >under-cursor)
>
> Is this what you mean?
>
>      :set hlsearch
>
> But my favorite trick is to turn every line that contains the pattern
> into a fold. I map this to \z (the backslash key then the z key).
>
>      " This folds every line that does not contain the search pattern.
>      " First set the search pattern with / or * or # then
>      " type \z (backslash then z).
>      map <silent><leader>z :set foldexpr=(getline(v:lnum)=~@/)?\">1\":\"=\" foldlevel=0 foldcolumn=0 foldmethod=expr<CR>
>
> I also remap the SPACE key to toggle the folds.
>
>      " space toggles the fold under the cursor.
>      nnoremap <silent><space> :exe 'silent! normal! za'.(foldlevel('.')?'':'l')<CR>
>
> --
>   Noah Spurrier | email: [hidden email] |http://www.noah.org/wiki/engineering
> -------------------------------------------------------------------------------


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Charles E Campbell Jr
In reply to this post by Jeenu V

Jeenu wrote:

>Hi Vimmers,
>
>Is there any way to display the word under cursor highlighted when
>doing [I or ]I? I think that would be a useful feature, if it's not
>already there
>  
>
IIUC, you want to:   [I <esc> and then see all the words you were [I'ing
for highlighted.
Why not use maps?

nnoremap [I [I<esc>:set hls<cr>*``
nnoremap ]I ]I<esc>:set hls<cr>*``

Custom behavior is what they're all about!

Regards,
Chip Campbell


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

RE: Highlighting with [I and ]I

Larson, David
In reply to this post by Jeenu V

> I'm afraid what I wanted is different. If you have ever seen the grep
> with the "--color" option, you could see all the lines of occurrences,
> with the word/pattern highlighted (Highlighted - I mean the rendering
> color is something different from the rest of text, either background
> or foreground).
>
> When "[I" or "]I" is done, what I get is the same grep output without
> the --color option. So, most of the time, I get distracted spotting
> the word in the results. Of course I can use a "*" or "#" to follow
> the occurences or use a highlighting plugin, but all of them are a
> kind of navigation, which might involve lot of movements. But [I that
> I seek is something like a shop-at-one-place, with some kind of
> highlighting that lets you spot the item instantly.

Hi Jeenu,

Your idea is a good one. I'm pretty sure that there is no way of doing
this automatically, but it is possible to do this in a script. For
instance, you can grab the output of a command using the redir command:

:redir => items
:normal! [I
:redir END

and you can customize the colors that are used for the text that is
echoed to the screen:

:echohl Search
(Search is just an example, use any highlighter color you like)
:echo msg
:echohl none

Using these concepts in a clever way should give you the functionality
that you are looking for.

HTH,
David

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Jeenu V

>
> :redir => items
> :normal! [I
> :redir END

Thanks for this; I'm not aware of this :redir feature at all :D

> and you can customize the colors that are used for the text that is
> echoed to the screen:
>
> :echohl Search
> (Search is just an example, use any highlighter color you like)
> :echo msg
> :echohl none

Yes but, AFAIK, that would highlight the entire message that's been
echo'ed to the screen. What I want is only the searched word to be
highlighted.

I tried to use the :match command to first highlight the word, and
then did [I. To my surprise, the output of [I didn't respect
the :match ! What was outupt is just the same old plain text, without
highlighting :(

And there's one more thing I wanted to know: How to get the "Press
ENTER or type command to continue" prompt on to the screen? Again, if
somehow, I redirected the output of [I to a variable, how shall I make
this prompt appear after my echo (Will this comeup automatically)?

Thanks
Jeenu


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Tony Mechelynck

Jeenu wrote:

>> :redir => items
>> :normal! [I
>> :redir END
>
> Thanks for this; I'm not aware of this :redir feature at all :D
>
>> and you can customize the colors that are used for the text that is
>> echoed to the screen:
>>
>> :echohl Search
>> (Search is just an example, use any highlighter color you like)
>> :echo msg
>> :echohl none
>
> Yes but, AFAIK, that would highlight the entire message that's been
> echo'ed to the screen. What I want is only the searched word to be
> highlighted.
>
> I tried to use the :match command to first highlight the word, and
> then did [I. To my surprise, the output of [I didn't respect
> the :match ! What was outupt is just the same old plain text, without
> highlighting :(
>
> And there's one more thing I wanted to know: How to get the "Press
> ENTER or type command to continue" prompt on to the screen? Again, if
> somehow, I redirected the output of [I to a variable, how shall I make
> this prompt appear after my echo (Will this comeup automatically)?
>
> Thanks
> Jeenu

The hit-enter prompt will appear automatically if there are enough lines to
push up the bottom statusbar (this depends in part on your 'cmdheight' setting).

If there is more than a full page of messages, you will get the "more" prompt
for every page except the last (which has the hit-enter-prompt), unless 'more'
is off.


Best regards,
Tony.
--
        Now, you might ask, "How do I get one of those complete home
tool sets for under $4?"  An excellent question.
        Go to one of those really cheap discount stores where they sell
plastic furniture in colors visible from the planet Neptune and where
they have a food section specializing in cardboard cartons full of
Raisinets and malted milk balls manufactured during the Nixon
administration.  In either the hardware or housewares department,
you'll find an item imported from an obscure Oriental country and
described as "Nine Tools in One", consisting of a little handle with
interchangeable ends representing inscrutable Oriental notions of tools
that Americans might use around the home.  Buy it.
        This is the kind of tool set professionals use.  Not only is it
inexpensive, but it also has a great safety feature not found in the
so-called quality tools sets: The handle will actually break right off
if you accidentally hit yourself or anything else, or expose it to
direct sunlight.
                -- Dave Barry, "The Taming of the Screw"


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Jeenu V


>
> The hit-enter prompt will appear automatically if there are enough lines to
> push up the bottom statusbar (this depends in part on your 'cmdheight' setting).

> If there is more than a full page of messages, you will get the "more" prompt
> for every page except the last (which has the hit-enter-prompt), unless 'more'
> is off.
>

Is there any way to suppress this, let's say, when I try to redirect
the output? What has to be done to make Vim not wait for the user
input?

For example, if I issue

:redir => g:result|normal [I|redir END

and then an :echo g:result, it wouldn't contain anything. If I issue
another :redir END, then and echo g:resut, I can see the output!


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Tony Mechelynck

Jeenu wrote:

>
>> The hit-enter prompt will appear automatically if there are enough lines to
>> push up the bottom statusbar (this depends in part on your 'cmdheight' setting).
>
>> If there is more than a full page of messages, you will get the "more" prompt
>> for every page except the last (which has the hit-enter-prompt), unless 'more'
>> is off.
>>
>
> Is there any way to suppress this, let's say, when I try to redirect
> the output? What has to be done to make Vim not wait for the user
> input?
>
> For example, if I issue
>
> :redir => g:result|normal [I|redir END
>
> and then an :echo g:result, it wouldn't contain anything. If I issue
> another :redir END, then and echo g:resut, I can see the output!

To suppress the more-prompt, use ":set nomore" before the command which will
generate the output.

For the hit-enter-prompt, it's less obvious, but if you are only concerned
about the redirected output, you can suppress the output to screen completely
(and still redirect the messages) using ":silent". Errors won't cause the
command to abort then though.

See
        :help 'more'
        :help :silent



Best regards,
Tony.
--
Rules for driving in New York:
        (1) Anything done while honking your horn is legal.
        (2) You may park anywhere if you turn your four-way flashers
            on.
        (3) A red light means the next six cars may go through the
            intersection.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

RE: Highlighting with [I and ]I

Larson, David
In reply to this post by Jeenu V

> > and you can customize the colors that are used for the text that is
> > echoed to the screen:
> >
> > :echohl Search
> > (Search is just an example, use any highlighter color you like)
> > :echo msg
> > :echohl none
>
> Yes but, AFAIK, that would highlight the entire message that's been
> echo'ed to the screen. What I want is only the searched word to be
> highlighted.

No, I should have been more explicit. You can surround the highlighted
text with echon's (echo without \n):

:echon text_before_highlight
:echohl Search
:echon found_text
:echohl none
:echon text_after_highlight
:echo

This will only highlight the text you are interested in.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Tony Mechelynck

Larson, David wrote:

>>> and you can customize the colors that are used for the text that is
>>> echoed to the screen:
>>>
>>> :echohl Search
>>> (Search is just an example, use any highlighter color you like)
>>> :echo msg
>>> :echohl none
>> Yes but, AFAIK, that would highlight the entire message that's been
>> echo'ed to the screen. What I want is only the searched word to be
>> highlighted.
>
> No, I should have been more explicit. You can surround the highlighted
> text with echon's (echo without \n):
>
> :echon text_before_highlight
> :echohl Search
> :echon found_text
> :echohl none
> :echon text_after_highlight
> :echo
>
> This will only highlight the text you are interested in.

That won't work; what the OP wants is to highlight differently the word in
question wherever it appears in the long output produced by the ]I and [I
normal-mode commands (see ":help [I").


Best regards,
Tony.
--
Biting someone with your natural teeth is "simple assault," while biting
someone with your false teeth is "aggravated assault."
                [real standing law in Louisana, United States of America]

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

RE: Highlighting with [I and ]I

Larson, David
In reply to this post by Jeenu V

> For example, if I issue
>
> :redir => g:result|normal [I|redir END
>
> and then an :echo g:result, it wouldn't contain anything. If I issue
> another :redir END, then and echo g:resut, I can see the output!

That is very suspicious. I do not think you should be getting a more
prompt if the text is redirected. Try separating the three commands into
three lines and see if the problem remains. The "redir END" may be
lumped into the normal command.

redir => g:result
normal! [I
redir END

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

RE: Highlighting with [I and ]I

Larson, David
In reply to this post by Tony Mechelynck

> > No, I should have been more explicit. You can surround the
highlighted

> > text with echon's (echo without \n):
> >
> > :echon text_before_highlight
> > :echohl Search
> > :echon found_text
> > :echohl none
> > :echon text_after_highlight
> > :echo
> >
> > This will only highlight the text you are interested in.
>
> That won't work; what the OP wants is to highlight differently the
word in
> question wherever it appears in the long output produced by the ]I and
[I
> normal-mode commands (see ":help [I").

Yes, it will. Jeenu just has to do some text processing and put the echo
code in a loop. I'm not spelling out every last detail, just giving the
keys that Jeenu needs.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Tony Mechelynck

Larson, David wrote:

>>> No, I should have been more explicit. You can surround the
> highlighted
>>> text with echon's (echo without \n):
>>>
>>> :echon text_before_highlight
>>> :echohl Search
>>> :echon found_text
>>> :echohl none
>>> :echon text_after_highlight
>>> :echo
>>>
>>> This will only highlight the text you are interested in.
>> That won't work; what the OP wants is to highlight differently the
> word in
>> question wherever it appears in the long output produced by the ]I and
> [I
>> normal-mode commands (see ":help [I").
>
> Yes, it will. Jeenu just has to do some text processing and put the echo
> code in a loop. I'm not spelling out every last detail, just giving the
> keys that Jeenu needs.

I'm curious.

Hitting [I on some word will produce a long listing of all lines where that
word appears. *No* *echo* *statements* *involved* , everything is in C code.
How do I make Vim produce that same long listing with the one word highlighted
differently within every line of that long listing?



Best regards,
Tony.
--
Mickey Mouse wears a Spiro Agnew watch.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting with [I and ]I

Jeenu V
In reply to this post by Larson, David
> Yes, it will. Jeenu just has to do some text processing and put the echo
> code in a loop. I'm not spelling out every last detail, just giving the
> keys that Jeenu needs.

And yes, it did work!!!
The following command worked as I expected and wanted:

:echohl None | echon "The Quick " | echohl Keyword | echon "Brown" | echohl None | echo "Fox"
This does highlight the Brown like a "Keyword".

> :redir => g:result|normal [I|redir END

Also, I could make this work:

:redir => g:result | silent execute "normal [I" | redir END
and this gave me the result I wanted.

So I think I got everything in parts; now I shall further work on that - Thanks guys!!

By the way, does any body feel that this is a feature worth adding to Vim?

Thanks
Jeenu


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

RE: Highlighting with [I and ]I

Larson, David
In reply to this post by Tony Mechelynck

> > Yes, it will. Jeenu just has to do some text processing and put the
echo
> > code in a loop. I'm not spelling out every last detail, just giving
the

> > keys that Jeenu needs.
>
> I'm curious.
>
> Hitting [I on some word will produce a long listing of all lines where
> that
> word appears. *No* *echo* *statements* *involved* , everything is in C
> code.
> How do I make Vim produce that same long listing with the one word
> highlighted
> differently within every line of that long listing?

Tony,

You must've missed the first part of thread. I told Jeenu to redirect
the C output into a vim variable and then echo the output with
highlighting.

David

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---