Discussion:
Sed substitution did not go as planned...
Marcus Martinez
2017-02-04 13:14:36 UTC
Permalink
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 vim_use+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
David Fishburn
2017-02-05 19:06:17 UTC
Permalink
On Sat, Feb 4, 2017 at 8:14 AM, Marcus Martinez <
Post by Marcus Martinez
...
: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 vim_use+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tim Chase
2017-02-05 19:09:29 UTC
Permalink
Post by Marcus Martinez
...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 vim_use+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Shawn H Corey
2017-02-05 19:51:42 UTC
Permalink
On Sun, 5 Feb 2017 13:09:29 -0600
Post by Tim Chase
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
: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 vim_use+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Christian Brabandt
2017-02-05 20:41:34 UTC
Permalink
Post by Shawn H Corey
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 vim_use+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Shawn H Corey
2017-02-05 21:30:31 UTC
Permalink
On Sun, 5 Feb 2017 21:41:34 +0100
Post by Christian Brabandt
Post by Shawn H Corey
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 vim_use+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tim Chase
2017-02-05 22:14:41 UTC
Permalink
Post by Shawn H Corey
On Sun, 5 Feb 2017 21:41:34 +0100
Post by Christian Brabandt
Post by Shawn H Corey
: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 vim_use+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tim Chase
2017-02-06 00:55:53 UTC
Permalink
Post by Tim Chase
Post by Shawn H Corey
On Sun, 5 Feb 2017 21:41:34 +0100
Post by Christian Brabandt
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 vim_use+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Shlomi Fish
2017-02-05 21:18:54 UTC
Permalink
Hi Tim, and all,

On Sun, 5 Feb 2017 13:09:29 -0600
Post by Tim Chase
Post by Marcus Martinez
...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.
- 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
/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 vim_use+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Eric Calvayrac
2017-02-08 13:50:02 UTC
Permalink
Post by 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
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 vim_use+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...