Quantcast

Sed substitution did not go as planned...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Sed substitution did not go as planned...

Marcus Martinez
Hello,

I am using Vim version 7.4.160 on AIX.

I opened my text file...
vim foo.txt

...and modified the first ten lines using Sed substitution...
:1,10 s/^/--/

After running this command the beginning of lines 1 through 10 do have the "--" correctly placed. However, the first character of each line in the file is now highlighted (as shown in the attached image). The pattern now recurs for any text file I open with vim.

Why does this happen? How can I "undo" this new pattern so that vim does not highlight the first character of each line?

Thanks,
Marcus Martinez

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

frost.PNG (12K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sed substitution did not go as planned...

David Fishburn-2

On Sat, Feb 4, 2017 at 8:14 AM, Marcus Martinez <[hidden email]> wrote:
...
 
:1,10 s/^/--/

After running this command the beginning of lines 1 through 10 do have the "--" correctly placed. However, the first character of each line in the file is now highlighted (as shown in the attached image). The pattern now recurs for any text file I open with vim.

If you run :nohlsearch does that leading yellow column go?

It is showing you the last search, since ^ matches the beginning of every line, that is why it is there.

:h hlsearch

HTH,
David 

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sed substitution did not go as planned...

Tim Chase
In reply to this post by Marcus Martinez
On 2017-02-04 05:14, Marcus Martinez wrote:

> ...and modified the first ten lines using Sed substitution...
> :1,10 s/^/--/
>
> After running this command the beginning of lines 1 through 10 do
> have the "--" correctly placed. However, the first character of
> each line in the file is now highlighted (as shown in the attached
> image). The pattern now recurs for any text file I open with vim.
>
> Why does this happen? How can I "undo" this new pattern so that vim
> does not highlight the first character of each line?

Why?  You have 'hls' set, so it highlights the last thing you
searched for.  In this case, /^/ which is the beginning of the line.

How can you undo it?  A couple different ways:

- if you like the search highlighting but just want to hide it for
  these search results, use ":noh" to turn it off until the next time
  you do a search

- alternatively, you can search for junk that isn't in your file:

  /lkasjdfdlkjgadslkgjads

- if the highlighting annoys you all the time, you use

  :set nohls

  to turn it off completely.


I generally fly with 'nohls' set and only turn it on when I actually
want that functionality.  I also remap control+L (usually just a
simple :redraw of the screen) to also do a :noh in the process:

  :nnoremap <c-L> :noh<cr><c-L>

which feels intuitive to me.  YMMV.

You can read more at

  :help 'hls'
  :help :noh

-tim





--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sed substitution did not go as planned...

Shawn H Corey
On Sun, 5 Feb 2017 13:09:29 -0600
Tim Chase <[hidden email]> wrote:

> I generally fly with 'nohls' set and only turn it on when I actually
> want that functionality.  I also remap control+L (usually just a
> simple :redraw of the screen) to also do a :noh in the process:
>
>   :nnoremap <c-L> :noh<cr><c-L>
>
> which feels intuitive to me.  YMMV.

I remap the Esc.

    :nnoremap <Esc> :nohlsearch<CR><Esc>

In normal mode, Esc does nothing but ring the bell, so this feels
intuitive to me. :)


--
Don't stop where the ink does.

        Shawn H Corey

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sed substitution did not go as planned...

Christian Brabandt
On So, 05 Feb 2017, Shawn H Corey wrote:

> I remap the Esc.
>
>     :nnoremap <Esc> :nohlsearch<CR><Esc>
>
> In normal mode, Esc does nothing but ring the bell, so this feels
> intuitive to me. :)

That is known to confuse the Vim parser. I would not recommend to map
esc.

http://vi.stackexchange.com/q/2614/71

Best,
Christian
--
Es gibt viele Mittel gegen die Liebe, aber keins ist unfehlbar.
                -- François Duc de La Rochefoucauld

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sed substitution did not go as planned...

Shlomi Fish-2
In reply to this post by Tim Chase
Hi Tim, and all,

On Sun, 5 Feb 2017 13:09:29 -0600
Tim Chase <[hidden email]> wrote:

> On 2017-02-04 05:14, Marcus Martinez wrote:
> > ...and modified the first ten lines using Sed substitution...
> > :1,10 s/^/--/
> >
> > After running this command the beginning of lines 1 through 10 do
> > have the "--" correctly placed. However, the first character of
> > each line in the file is now highlighted (as shown in the attached
> > image). The pattern now recurs for any text file I open with vim.
> >
> > Why does this happen? How can I "undo" this new pattern so that vim
> > does not highlight the first character of each line?  
>
> Why?  You have 'hls' set, so it highlights the last thing you
> searched for.  In this case, /^/ which is the beginning of the line.
>
> How can you undo it?  A couple different ways:
>
> - if you like the search highlighting but just want to hide it for
>   these search results, use ":noh" to turn it off until the next time
>   you do a search
>
> - alternatively, you can search for junk that isn't in your file:
>
>   /lkasjdfdlkjgadslkgjads
>

One can also nullify the search-pattern register:

        :let @/=''

That way, vim will not highlight anything.

Regards,

        Shlomi Fish

--
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
List of Portability Libraries - http://shlom.in/port-libs

Chuck Norris once solved 100 million deals of Freecell in a minute. By hand.
    — http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sed substitution did not go as planned...

Shawn H Corey
In reply to this post by Christian Brabandt
On Sun, 5 Feb 2017 21:41:34 +0100
Christian Brabandt <[hidden email]> wrote:

> On So, 05 Feb 2017, Shawn H Corey wrote:
>
> > I remap the Esc.
> >
> >     :nnoremap <Esc> :nohlsearch<CR><Esc>
> >
> > In normal mode, Esc does nothing but ring the bell, so this feels
> > intuitive to me. :)
>
> That is known to confuse the Vim parser. I would not recommend to map
> esc.
>
> http://vi.stackexchange.com/q/2614/71
>
> Best,
> Christian

You're kidding right? The escape used to communicate should be separate
from the Escape key mapping.


--
Don't stop where the ink does.

        Shawn H Corey

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sed substitution did not go as planned...

Tim Chase
On 2017-02-05 16:30, Shawn H Corey wrote:

> On Sun, 5 Feb 2017 21:41:34 +0100
> Christian Brabandt <[hidden email]> wrote:
> > On So, 05 Feb 2017, Shawn H Corey wrote:
> > >     :nnoremap <Esc> :nohlsearch<CR><Esc>
> > >
> > > In normal mode, Esc does nothing but ring the bell, so this
> > > feels intuitive to me. :)
> >
> > That is known to confuse the Vim parser. I would not recommend to
> > map esc.
> >
> > http://vi.stackexchange.com/q/2614/71
>
> You're kidding right? The escape used to communicate should be
> separate from the Escape key mapping.

As is mentioned in that thread, it may be possible within gvim, but in
terminal vim, the escape key already has a meta-level meaning as a
prefix for certain extended-key sequences (such as arrows, function
keys, alt+{key}, and the six-pack).

-tim




--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sed substitution did not go as planned...

Tim Chase
On 2017-02-05 18:09, Shawn H Corey wrote:

> On Sun, 5 Feb 2017 16:14:41 -0600 Tim Chase wrote:
>> On 2017-02-05 16:30, Shawn H Corey wrote:
>>> On Sun, 5 Feb 2017 21:41:34 +0100
>>> Christian Brabandt <[hidden email]> wrote:
>>>> That is known to confuse the Vim parser. I would not
>>>> recommend to map esc.
>>>>
>>>> http://vi.stackexchange.com/q/2614/71
>>>
>>> You're kidding right? The escape used to communicate should be
>>> separate from the Escape key mapping.
>>
>> As is mentioned in that thread, it may be possible within gvim,
>> but in terminal vim, the escape key already has a meta-level
>> meaning as a prefix for certain extended-key sequences (such as
>> arrows, function keys, alt+{key}, and the six-pack).
>
> THe key mapping should be internal to ViM and shouldn't interfere
> with xterm communication.

Right, but

1) vim sends escape sequences to ask the terminal for its
capabilities, and the terminal responds with escape-prefixed answers,
potentially triggering <esc> mappings unintendedly.

2) using the aforementioned extended-key sequences within your
terminal causes the terminal to send escape-prefixed commands to vim.
Vim usually uses the 'timeoutlen'/'ttimeoutlen' options to discern
them from a stand-alone <esc> key, but it can cause issues depending
on the connection speed.

This is how terminals have worked for decades, and it's highly
unlikely to change any time in the near future.  Using gvim bypasses
the terminal, allowing the <esc> to be more reliable there.

-tim



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sed substitution did not go as planned...

Eric Calvayrac
In reply to this post by Marcus Martinez
Le dimanche 5 février 2017 19:24:17 UTC+1, Marcus Martinez a écrit :

> Hello,
>
> I am using Vim version 7.4.160 on AIX.
>
> I opened my text file...
> vim foo.txt
>
> ...and modified the first ten lines using Sed substitution...
> :1,10 s/^/--/
>
> After running this command the beginning of lines 1 through 10 do have the "--" correctly placed. However, the first character of each line in the file is now highlighted (as shown in the attached image). The pattern now recurs for any text file I open with vim.
>
> Why does this happen? How can I "undo" this new pattern so that vim does not highlight the first character of each line?
>
> Thanks,
> Marcus Martinez
Hi,
Since version 7.4.083, it is also possible to use keeppatterns.

:keeppatterns 1,10 s/^/--/

Using it, you will not change your search history.

Eric

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...