Highlighting of specific columns

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

Highlighting of specific columns

Andy Cedilnik
Hello,

I am developing large C++ code and I would like to have all lines be
shorter than 79 characters. I have a script that verifies that, but I
would like to have something that checks that while I code. So, I was
wondering if there is any way in VIM to highlight all characters pass
the 79th character?

Also, while on the subject, is there any way to add to standard C++
highlighting, to highlight all spaces at the end of the line?

Thank you.

        Andy
Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

John (Eljay) Love-Jensen
Hi Andy,

> Also, while on the subject, is there any way to add to standard C++
> highlighting, to highlight all spaces at the end of the line?

I use:

:set listchars=tab:>-,trail:$



You can change the highlighting of these via:

:highlight SpecialKey



You can turn it on/off via (such as when you want to cut-n-paste from your
Vim console app into an email message):

:set list
:set nolist

HTH,
--Eljay

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

iler.ml
In reply to this post by Andy Cedilnik
On 3/9/06, Andy Cedilnik <[hidden email]> wrote:
> So, I was
> wondering if there is any way in VIM to highlight all characters past

:match Error /\%79v.*/

For more info:
:he :match
:he /\%v

Yakov
Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

Eric Leenman-2
Or you can do it as an autocmd:

autocmd BufEnter * hi rightMargin guibg=beige | match rightMargin /\%>80c.\+

Rgds,
Eric


>From: "Yakov Lerner" <[hidden email]>
>To: "Andy Cedilnik" <[hidden email]>
>CC: [hidden email]
>Subject: Re: Highlighting of specific columns
>Date: Thu, 9 Mar 2006 14:22:31 +0000
>
>On 3/9/06, Andy Cedilnik <[hidden email]> wrote:
> > So, I was
> > wondering if there is any way in VIM to highlight all characters past
>
>:match Error /\%79v.*/
>
>For more info:
>:he :match
>:he /\%v
>
>Yakov

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

Andy Cedilnik
In reply to this post by iler.ml
Hi Yakov,

Nice. Works great.

Here is the expression for both of them:

:match Error /\(\%79v.*\|\s\s*\)$/

       Andy

Yakov Lerner wrote:

>On 3/9/06, Andy Cedilnik <[hidden email]> wrote:
>  
>
>>So, I was
>>wondering if there is any way in VIM to highlight all characters past
>>    
>>
>
>:match Error /\%79v.*/
>
>For more info:
>:he :match
>:he /\%v
>
>Yakov
>  
>


--
Andy Cedilnik
Kitware Inc.

Reply | Threaded
Open this post in threaded view
|

RE: Highlighting of specific columns

Zdenek Sekera
In reply to this post by Andy Cedilnik
> -----Original Message-----
> From: Andy Cedilnik [mailto:[hidden email]]
> Sent: 09 March 2006 15:15
> To: [hidden email]
> Subject: Highlighting of specific columns
>
> Hello,
>
> I am developing large C++ code and I would like to have all lines be
> shorter than 79 characters. I have a script that verifies that, but I
> would like to have something that checks that while I code. So, I was
> wondering if there is any way in VIM to highlight all characters pass
> the 79th character?
>
> Also, while on the subject, is there any way to add to standard C++
> highlighting, to highlight all spaces at the end of the line?

What I do is simply to have my (g)vim as wide as I want to
(79, 80 chars, whatever) and depending if wrap is on/off
I can see immediately what I need.
Not very high tech, I admit.

---Zdenek
Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

Gerald Lai-2
In reply to this post by Andy Cedilnik
On Thu, 9 Mar 2006, Andy Cedilnik wrote:

> Hi Yakov,
>
> Nice. Works great.
>
> Here is the expression for both of them:
>
> :match Error /\(\%79v.*\|\s\s*\)$/

I would recommend \%c instead (see ":help /\%c"). \%v doesn't highlight
well when lines are wrapped (set wrap) or contains single-characters
that take more than 1 screen column to display.

Simplifying the above:

   :match Error /\%>78c\|\s\+$/

It is 78 instead of 79 so that character 79 is also highlighted.
Personally, I would highlight character 80 and beyond because that's
where Vim justifies and splits the lines; character 79 still remains
where it was after justification.

Since Vim justifies according to textwidth, we can make highlighting
dynamic according to how we set 'textwidth'. Here's a mapping that would
do so:

   nnoremap <silent><F5> :let @/='\s\+$\|\%><C-r>=&tw?&tw:79<CR>c'<CR>/<CR><C-o>

These are just some suggestions.
--
Gerald
Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

Gary Johnson
On 2006-03-09, Gerald Lai <[hidden email]> wrote:

> On Thu, 9 Mar 2006, Andy Cedilnik wrote:
>
> > Hi Yakov,
> >
> > Nice. Works great.
> >
> > Here is the expression for both of them:
> >
> > :match Error /\(\%79v.*\|\s\s*\)$/
>
> I would recommend \%c instead (see ":help /\%c"). \%v doesn't highlight
> well when lines are wrapped (set wrap) or contains single-characters
> that take more than 1 screen column to display.

\%c is fine as long as you don't use tabs, but if you do, you pretty
much have to use \%v.  I use this:

    exec 'match RightMargin /^\s\+$\|\%>' . &textwidth . 'v.\+/'

in an autocommand and have not had any problems with highlighting
even wrapped lines.

Gary

--
Gary Johnson                 | Agilent Technologies
[hidden email]     | Wireless Division
                             | Spokane, Washington, USA
Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

Gerald Lai-2
On Thu, 9 Mar 2006, Gary Johnson wrote:

> On 2006-03-09, Gerald Lai <[hidden email]> wrote:
>> On Thu, 9 Mar 2006, Andy Cedilnik wrote:
>>
>>> Hi Yakov,
>>>
>>> Nice. Works great.
>>>
>>> Here is the expression for both of them:
>>>
>>> :match Error /\(\%79v.*\|\s\s*\)$/
>>
>> I would recommend \%c instead (see ":help /\%c"). \%v doesn't highlight
>> well when lines are wrapped (set wrap) or contains single-characters
>> that take more than 1 screen column to display.
>
> \%c is fine as long as you don't use tabs, but if you do, you pretty
> much have to use \%v.  I use this:
>
>    exec 'match RightMargin /^\s\+$\|\%>' . &textwidth . 'v.\+/'
>
> in an autocommand and have not had any problems with highlighting
> even wrapped lines.

My mistake. I stand corrected. Looking at ":help gq", it says:

       If the 'textwidth' option is 0, the formatted line
       length is the screen width (with a maximum width of
       79).

Apparently, justification is done by screen characters, not actual byte
characters. Hence, \%v is what we want. Sorry for the confusion.
--
Gerald
Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

Kyku-2
In reply to this post by iler.ml
Yakov Lerner wrote:

> On 3/9/06, Andy Cedilnik <[hidden email]> wrote:
>  
>> So, I was
>> wondering if there is any way in VIM to highlight all characters past
>>    
>
> :match Error /\%79v.*/
>
> For more info:
> :he :match
> :he /\%v
>
> Yakov
>
>
>  
Hi
I tried 78ia<esc>
could you please tell me how not to highlight the newline?

Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

Benji Fisher
On Fri, Mar 10, 2006 at 11:53:08AM +0100, Kyku wrote:

> Yakov Lerner wrote:
> >On 3/9/06, Andy Cedilnik <[hidden email]> wrote:
> >  
> >>So, I was
> >>wondering if there is any way in VIM to highlight all characters past
> >>    
> >
> >:match Error /\%79v.*/
> >
> >For more info:
> >:he :match
> >:he /\%v
> >
> >Yakov
> >  
> Hi
> I tried 78ia<esc>
> could you please tell me how not to highlight the newline?

     I find that the newline is highlighted in vim 6.4 but not in vim
7.0 (alpha).  So I think this is a bug that has been fixed in the
version being developed.

HTH --Benji Fisher
Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

Kyku-2
Benji Fisher wrote:

> On Fri, Mar 10, 2006 at 11:53:08AM +0100, Kyku wrote:
>  
>> Yakov Lerner wrote:
>>    
>>> On 3/9/06, Andy Cedilnik <[hidden email]> wrote:
>>>  
>>>      
>>>> So, I was
>>>> wondering if there is any way in VIM to highlight all characters past
>>>>            
>>> :match Error /\%79v.*/
>>>
>>> For more info:
>>> :he :match
>>> :he /\%v
>>>
>>> Yakov
>>>  
>>>      
>> Hi
>> I tried 78ia<esc>
>> could you please tell me how not to highlight the newline?
>>    
>
>      I find that the newline is highlighted in vim 6.4 but not in vim
> 7.0 (alpha).  So I think this is a bug that has been fixed in the
> version being developed.
>
> HTH                    --Benji Fisher
>
>
>  
Hi, thanks for your response, but are you sure? I'm running a snapshot
from March 08 and it is broken, too.

:version
VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 8, compiled Mar 9 2006 08:45:58)
Skompilowany przez kyku@silverthread
Normalna wersja z GTK2 GUI. Opcje w?a;czone (+) lub nie (-):
-arabic +autocmd +balloon_eval +browse +builtin_terms +byte_offset
+cindent +clientserver
+clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments +cryptv
-cscope +cursorshape
+dialog_con_gui +diff +digraphs +dnd -ebcdic -emacs_tags +eval +ex_extra
+extra_search -farsi
+file_in_path +find_in_path +folding -footer +fork() +gettext
-hangul_input +iconv +insert_expand
+jumplist -keymap -langmap +libcall +linebreak +lispindent +listcmds
+localmap +menu +mksession
+modify_fname +mouse +mouseshape -mouse_dec +mouse_gpm -mouse_jsbterm
-mouse_netterm +mouse_xterm
+multi_byte +multi_lang -mzscheme +netbeans_intg -osfiletype +path_extra
-perl +postscript +printer
-profile -python +quickfix -rightleft -ruby +scrollbind +signs
+smartindent -sniff +statusline
-sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white -tcl
+terminfo +termresponse
+textobjects +title +toolbar +user_commands +vertsplit +virtualedit
+visual +visualextra +viminfo
+vreplace +wildignore +wildmenu +windows +writebackup +X11 -xfontset
+xim +xsmp_interact
+xterm_clipboard -xterm_save
vimrc systemu: "$VIM/vimrc"
vimrc uz.ytkownika: "$HOME/.vimrc"
exrc uz.ytkownika: "$HOME/.exrc"
gvimrc systemu: "$VIM/gvimrc"
gvimrc uz.ytkownika: "$HOME/.gvimrc"
systemowy plik menu: "$VIMRUNTIME/menu.vim"
odwet dla $VIM-a: "/usr/local/stow/vim7//share/vim"
Kompilacja: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK
-I/usr/include/gtk-2.0 -I/usr/lib/gtk
-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo
-I/usr/include/pango-1.0 -I/usr/include/gli
b-2.0 -I/usr/lib/glib-2.0/include -g -O2
Konsolidacja: gcc -L/usr/local/lib -o vim -lgtk-x11-2.0 -lgdk-x11-2.0
-latk-1.0 -lgdk_pixbuf-2.0
-lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0
-lglib-2.0 -lXt -lncurses -l
acl -lgpm


Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

Benji Fisher
In reply to this post by Benji Fisher
On Fri, Mar 10, 2006 at 06:13:25PM +0100, Kyku wrote:

> Benji Fisher wrote:
> >On Fri, Mar 10, 2006 at 11:53:08AM +0100, Kyku wrote:
> >  
> >>Yakov Lerner wrote:
> >>    
> >>>On 3/9/06, Andy Cedilnik <[hidden email]> wrote:
> >>>
> >>>      
> >>>>So, I was
> >>>>wondering if there is any way in VIM to highlight all characters past
> >>>>  
> >>>>        
> >>>:match Error /\%79v.*/
> >>>
> >>>For more info:
> >>>:he :match
> >>>:he /\%v
> >>>
> >>>Yakov
> >>>
> >>>      
> >>Hi
> >>I tried 78ia<esc>
> >>could you please tell me how not to highlight the newline?
> >>    
> >
> >     I find that the newline is highlighted in vim 6.4 but not in vim
> >7.0 (alpha).  So I think this is a bug that has been fixed in the
> >version being developed.
> >
> >HTH --Benji Fisher
> >
> >
> >  
> Hi, thanks for your response, but are you sure? I'm running a snapshot
> from March 08 and it is broken, too.
>
> :version
> VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 8, compiled Mar 9 2006 08:45:58)

     Your version is four days more recent than mine.

     If the line is exactly 78 (screen) characters long, then /\%79v.*/
matches at the end of the line, like /$/, since \%79v is a zero-length
pattern.  In this situation, vim always highlights something, so it uses
the position after the last character on the line.

     The bug in vim 6,4 is that it also highlights that position in case
the line is longer than 78 (screen) characters.

     Perhaps you would be happier replacing .* with .\+ as in

:match Error /\%79v.\+/

HTH --Benji Fisher
Reply | Threaded
Open this post in threaded view
|

Re: Highlighting of specific columns

Kyku-2
Benji Fisher wrote:

> On Fri, Mar 10, 2006 at 06:13:25PM +0100, Kyku wrote:
>  
>> Benji Fisher wrote:
>>    
>>> On Fri, Mar 10, 2006 at 11:53:08AM +0100, Kyku wrote:
>>>  
>>>      
>>>> Yakov Lerner wrote:
>>>>    
>>>>        
>>>>> On 3/9/06, Andy Cedilnik <[hidden email]> wrote:
>>>>>
>>>>>      
>>>>>          
>>>>>> So, I was
>>>>>> wondering if there is any way in VIM to highlight all characters past
>>>>>>  
>>>>>>        
>>>>>>            
>>>>> :match Error /\%79v.*/
>>>>>
>>>>> For more info:
>>>>> :he :match
>>>>> :he /\%v
>>>>>
>>>>> Yakov
>>>>>
>>>>>      
>>>>>          
>>>> Hi
>>>> I tried 78ia<esc>
>>>> could you please tell me how not to highlight the newline?
>>>>    
>>>>        
>>>     I find that the newline is highlighted in vim 6.4 but not in vim
>>> 7.0 (alpha).  So I think this is a bug that has been fixed in the
>>> version being developed.
>>>
>>> HTH --Benji Fisher
>>>
>>>
>>>  
>>>      
>> Hi, thanks for your response, but are you sure? I'm running a snapshot
>> from March 08 and it is broken, too.
>>
>> :version
>> VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 8, compiled Mar 9 2006 08:45:58)
>>    
>
>      Your version is four days more recent than mine.
>
>      If the line is exactly 78 (screen) characters long, then /\%79v.*/
> matches at the end of the line, like /$/, since \%79v is a zero-length
> pattern.  In this situation, vim always highlights something, so it uses
> the position after the last character on the line.
>
>      The bug in vim 6,4 is that it also highlights that position in case
> the line is longer than 78 (screen) characters.
>
>      Perhaps you would be happier replacing .* with .\+ as in
>
> :match Error /\%79v.\+/
>
> HTH --Benji Fisher
>
>
>  
Ok, this did the trick. Thank you very much.