RE: Vim 7 feature question

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

RE: Vim 7 feature question

Suresh Govindachar`


  In a post to vim-dev, Alexei Alexandrov asked about a "feature to
  show a vertical line in some column position (78 or 80, for
  example)".  I think there was a thread about how to use
  syntax-highlighting to get this effect.

  --Suresh



Reply | Threaded
Open this post in threaded view
|

Re: Vim 7 feature question

Alexei Alexandrov
Hi Suresh Govindachar, you wrote:

>
>   In a post to vim-dev, Alexei Alexandrov asked about a "feature to
>   show a vertical line in some column position (78 or 80, for
>   example)".  I think there was a thread about how to use
>   syntax-highlighting to get this effect.
>
>   --Suresh

Yes, I've seen that. Using syntax highlighting seems to be a kludge that breaks the language highlighting sometimes. IMO, this is not an option.

--
Alexei Alexandrov
Reply | Threaded
Open this post in threaded view
|

RE: Vim 7 feature question

Keith W. Roberts
 

> -----Original Message-----
> From: news [mailto:[hidden email]] On Behalf Of Alexei Alexandrov
> Sent: Sunday, September 11, 2005 2:29 AM
> To: [hidden email]
> Subject: Re: Vim 7 feature question
>
> Hi Suresh Govindachar, you wrote:
>
> >
> >   In a post to vim-dev, Alexei Alexandrov asked about a "feature to
> >   show a vertical line in some column position (78 or 80, for
> >   example)".  I think there was a thread about how to use
> >   syntax-highlighting to get this effect.
> >
> >   --Suresh
>
> Yes, I've seen that. Using syntax highlighting seems to be a
> kludge that breaks the language highlighting sometimes. IMO,
> this is not an option.
>
> --
> Alexei Alexandrov

If done correctly, it shouldn't "break" any syntax hilighting; it will,
however, obscure it.  But that's a case of not being able to have your cake
and eat it, too.

Try using the :match command for that feature instead of :syn match; you can
create a map or two to easily switch it on and off.  And, of course, it
depends on what you really want that vertical line for ... if it's as a
guide for when you are approaching your desired line length (where you want
to end most lines), well I would think that setting 'lines' correctly in
horizontal splits would suffice.  If not, or if you use vertical splits,
then like I said, there's :match.

If all else fails, you might copy the syntax file and modify it along these
lines (untested):
- duplicate the langIdentifier entry as, say, xIdentifier ('lang' is the
language prefix)
- add \%>78v or the like before the rest of the pattern in xIdentifier
- include it everywhere langIdentifier is included (and exclude it ...)
- give it a different hilight group, and change color, font or whatever for
that group
- plop your new syntax file into .../after/syntax/ to activate it instead of
the std one

Now when you are typing, if the word crosses the magic boundary, it'll be
hilighted differently, using your new hilight group.

Hmmm... from :help \%v (et al), the match is not updated during input (at
least in vim 6.2.287).  So you might need to do something like an inoremap
<space> to something that will force hilighting to be updated.  Maybe
updating the statusline?  I'm not sure.

-Keith


Reply | Threaded
Open this post in threaded view
|

RE: Vim 7 feature question

David Fishburn
 

> -----Original Message-----
> From: Keith W. Roberts [mailto:[hidden email]]
> Sent: Tuesday, September 13, 2005 2:35 PM
> To: 'Alexei Alexandrov'; [hidden email]
> Subject: RE: Vim 7 feature question
>
>  
>
> > -----Original Message-----
> > From: news [mailto:[hidden email]] On Behalf Of Alexei
> Alexandrov
> > Sent: Sunday, September 11, 2005 2:29 AM
> > To: [hidden email]
> > Subject: Re: Vim 7 feature question
> >
> > Hi Suresh Govindachar, you wrote:
> >
> > >
> > >   In a post to vim-dev, Alexei Alexandrov asked about a
> "feature to
> > >   show a vertical line in some column position (78 or 80, for
> > >   example)".  I think there was a thread about how to use
> > >   syntax-highlighting to get this effect.
> > >
> > >   --Suresh
> >
> > Yes, I've seen that. Using syntax highlighting seems to be a kludge
> > that breaks the language highlighting sometimes. IMO, this
> is not an
> > option.
> >
> > --
> > Alexei Alexandrov
>
> If done correctly, it shouldn't "break" any syntax
> hilighting; it will, however, obscure it.  But that's a case
> of not being able to have your cake and eat it, too.
>
> Try using the :match command for that feature instead of :syn
> match; you can create a map or two to easily switch it on and
> off.  And, of course, it depends on what you really want that
> vertical line for ... if it's as a guide for when you are
> approaching your desired line length (where you want to end
> most lines), well I would think that setting 'lines'
> correctly in horizontal splits would suffice.  If not, or if
> you use vertical splits, then like I said, there's :match.
>
> If all else fails, you might copy the syntax file and modify
> it along these lines (untested):
> - duplicate the langIdentifier entry as, say, xIdentifier
> ('lang' is the language prefix)
> - add \%>78v or the like before the rest of the pattern in xIdentifier
> - include it everywhere langIdentifier is included (and
> exclude it ...)
> - give it a different hilight group, and change color, font
> or whatever for that group
> - plop your new syntax file into .../after/syntax/ to
> activate it instead of the std one
>
> Now when you are typing, if the word crosses the magic
> boundary, it'll be hilighted differently, using your new
> hilight group.
>
> Hmmm... from :help \%v (et al), the match is not updated
> during input (at least in vim 6.2.287).  So you might need to
> do something like an inoremap <space> to something that will
> force hilighting to be updated.  Maybe updating the
> statusline?  I'm not sure.


I have been using this in my vimrc for a long time ( I believe Benji
recommended it):

    let rightMargin = 'au FileType * syn clear rightMargin | ' .
                \ 'syn match rightMargin /\%80' .
                \ 'v[^<>(){}/\"'."'".']/ containedin=ALL'
    execute rightMargin
    hi rightMargin ctermbg=Gray guibg=Gray

Notice I have excluded these characters:
<>[]{}()"'

I have done due to Alexei's issue.  If a " falls on the 80th column, it gets
highlighted (good), but at the same time Vim no longer closes the syntax
highlighting for this "string" (bad).  So highlighting is messed up for the
remainder of the document.

Sometimes I do not want this block so I also created a command to remove it:
    command! RightMarginClear syn clear rightMargin

So I can just type:
:Rig<TAB>
and Vim will complete the command and remove the blocks when I no longer
want/need them.

Keith, I found no way around this issue, so I modified the match string to
exclude those characters that caused the most grief.

--
Do you use Vim to edit SQL?
<Plug>
Check the description of these plugins:
dbext.vim - Provides database access to 10 databases (Oracle, Sybase, SQL
Server, MySQL,...) (http://www.vim.org/scripts/script.php?script_id=356)
SQLUtilities - Formatting SQL, generate - columns lists, procedures for
databases (http://www.vim.org/scripts/script.php?script_id=492)
sql.vim - SQL indent file for Sybase ASA and Oracle
(http://www.vim.org/scripts/script.php?script_id=495)
Intellisense for Vim : SQL, C++, CSharp, Java, JSP, XML, HTML
(http://www.vim.org/scripts/script.php?script_id=747)
</Plug>


Reply | Threaded
Open this post in threaded view
|

Re: Vim 7 feature question

Gareth Oakes-2
This seems kind-of related to another feature I'm interested in.  I
believe it's already on the "wish list" for v7, but it's the option to
allow the cursor's visual line to be highlighted (I believe Ultraedit
has something similar).

This feature would act like a separate "layer" on top of syntax
highlighting, and would override it by highlighting the current (window)
line in
a special colour, presumably from column 1 to some other column.  It
sounds like the vertical "bar" feature mentioned in this thread could
use a similar layering strategy for implementation.  Although I'm
uncertain as to what policy should be applied if both features are
eventually implemented and end up coexisting.

Cheers,
-G

David Fishburn wrote:
 > I have been using this in my vimrc for a long time ( I believe Benji
 > recommended it):
 >
 >     let rightMargin = 'au FileType * syn clear rightMargin | ' .
 >                 \ 'syn match rightMargin /\%80' .
 >                 \ 'v[^<>(){}/\"'."'".']/ containedin=ALL'
 >     execute rightMargin
 >     hi rightMargin ctermbg=Gray guibg=Gray
 >
 > Notice I have excluded these characters:
 > <>[]{}()"'
 >
 > I have done due to Alexei's issue.  If a " falls on the 80th column,
it gets
 > highlighted (good), but at the same time Vim no longer closes the syntax
 > highlighting for this "string" (bad).  So highlighting is messed up
for the
 > remainder of the document.
 >
 > Sometimes I do not want this block so I also created a command to
remove it:
 >     command! RightMarginClear syn clear rightMargin
 >
 > So I can just type:
 > :Rig<TAB>
 > and Vim will complete the command and remove the blocks when I no longer
 > want/need them.
 >
 > Keith, I found no way around this issue, so I modified the match
string to
 > exclude those characters that caused the most grief.