CTLR_W and syntax on

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

CTLR_W and syntax on

jose isaias cabrera-2

Greetings!

If I open a file with syntax hi on, and I open two more windows (CTLR_W n)
and then, I read two more files of the same syntax, the syntax highlight of
the two new windows are not on.

How can I get this to work?

thanks,

jic

Reply | Threaded
Open this post in threaded view
|

Re: CTLR_W and syntax on

Tim Chase-2
> If I open a file with syntax hi on, and I open two more
> windows (CTLR_W n) and then, I read two more files of the same
> syntax, the syntax highlight of the two new windows are not
> on.

Through what process to you "read two more files"?  A virgin
buffer (such as you get with "CTRL_W n") does not have any
associated syntax, so if you use

        :r filename.ext

to read the file "filename.ext", it will read those contents, but
will not have an associated syntax.  You *can* force it manually
by doing

        :set syntax=mysyntax

where "mysyntax" is the apropriate syntax type for your file
type.  The same goes if you paste from elsewhere (whether system
clipboard or vim registers) into the untyped buffer.

If, however, you use

        :e filename.ext

it should detect the filetype the same way it did for you
previously.  This works too if you used the ":r" method above,
you can then write your file and then edit it again with

        :w somefile.ext
        :e %

Using the ":r" method of reading the file simply inserts the
contents of some arbitrary file in your current file, much like
pasting.  Such an action shouldn't change your buffer's syntax.

Just a few thoughts on the matter,

-tim






Reply | Threaded
Open this post in threaded view
|

Re: CTLR_W and syntax on

A.J.Mechelynck
In reply to this post by jose isaias cabrera-2
----- Original Message -----
From: "jose isaias cabrera" <[hidden email]>
To: "Vim" <[hidden email]>
Sent: Monday, August 08, 2005 9:23 PM
Subject: CTLR_W and syntax on


>
> Greetings!
>
> If I open a file with syntax hi on, and I open two more windows (CTLR_W n)
> and then, I read two more files of the same syntax, the syntax highlight
> of the two new windows are not on.
>
> How can I get this to work?
>
> thanks,
>
> jic

Check the following in the new window (and write down the answers):

    :filetype
    :echo exists("syntax_on")
    :syn sync
    :echo expand("%")
    :set filetype?
    :set syntax?

For syntax highlighting to work, you should have
    filetype detection: ON
    exists("syntax_on") == 1
    syn sync -- long enough for the current syntax to be properly detected
    'filetype' and 'syntax' appropriate for the current file name

If you start typing a new file into a [No File] buffer, it won't be
highlighted because Vim doesn't know which syntax to apply. One you give the
file a name, for instance by using
        :saveas filename
the filetype- and syntax-detection autocommands will be run and, if
possible, the text will become coloured. (For some files, for instance
*.vim, *.htm, etc., the file name is enough to define the syntax; for
others, e.g. Unix shell scripts which may have no extension, Vim will have
to check the file contents.)

HTH,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: CTLR_W and syntax on

jose isaias cabrera-2
On 21:53 Mon 08 Aug     , Tony Mechelynck wrote:

> ----- Original Message -----
> From: "jose isaias cabrera" <[hidden email]>
> To: "Vim" <[hidden email]>
> Sent: Monday, August 08, 2005 9:23 PM
> Subject: CTLR_W and syntax on
>
>
> >
> >Greetings!
> >
> >If I open a file with syntax hi on, and I open two more windows (CTLR_W n)
> >and then, I read two more files of the same syntax, the syntax highlight
> >of the two new windows are not on.
> >
> >How can I get this to work?
> >
> >thanks,
> >
> >jic
>
> Check the following in the new window (and write down the answers):
>
>    :filetype
>    :echo exists("syntax_on")
>    :syn sync
this is the problem... sync is not on...

however,

e file.vim

works perfectly. ;-)  I'll use that.

thanks.

>    :echo expand("%")
>    :set filetype?
>    :set syntax?
>
> For syntax highlighting to work, you should have
>    filetype detection: ON
>    exists("syntax_on") == 1
>    syn sync -- long enough for the current syntax to be properly detected
>    'filetype' and 'syntax' appropriate for the current file name
>
> If you start typing a new file into a [No File] buffer, it won't be
> highlighted because Vim doesn't know which syntax to apply. One you give
> the file a name, for instance by using
>        :saveas filename
> the filetype- and syntax-detection autocommands will be run and, if
> possible, the text will become coloured. (For some files, for instance
> *.vim, *.htm, etc., the file name is enough to define the syntax; for
> others, e.g. Unix shell scripts which may have no extension, Vim will have
> to check the file contents.)
>
> HTH,
> Tony.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: CTLR_W and syntax on

jose isaias cabrera-2
In reply to this post by Tim Chase-2

Thanks Tim.  e file.vim works.  I'll use that instead of r file.vim.

jic

On 14:57 Mon 08 Aug     , Tim Chase wrote:

> >If I open a file with syntax hi on, and I open two more
> >windows (CTLR_W n) and then, I read two more files of the same
> >syntax, the syntax highlight of the two new windows are not
> >on.
>
> Through what process to you "read two more files"?  A virgin
> buffer (such as you get with "CTRL_W n") does not have any
> associated syntax, so if you use
>
> :r filename.ext
>
> to read the file "filename.ext", it will read those contents, but
> will not have an associated syntax.  You *can* force it manually
> by doing
>
> :set syntax=mysyntax
>
> where "mysyntax" is the apropriate syntax type for your file
> type.  The same goes if you paste from elsewhere (whether system
> clipboard or vim registers) into the untyped buffer.
>
> If, however, you use
>
> :e filename.ext
>
> it should detect the filetype the same way it did for you
> previously.  This works too if you used the ":r" method above,
> you can then write your file and then edit it again with
>
> :w somefile.ext
> :e %
>
> Using the ":r" method of reading the file simply inserts the
> contents of some arbitrary file in your current file, much like
> pasting.  Such an action shouldn't change your buffer's syntax.
>
> Just a few thoughts on the matter,
>
> -tim
>
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: CTLR_W and syntax on

A.J.Mechelynck
----- Original Message -----
From: "jose isaias cabrera" <[hidden email]>
To: "Tim Chase" <[hidden email]>
Cc: "Vim" <[hidden email]>
Sent: Monday, August 08, 2005 10:22 PM
Subject: Re: CTLR_W and syntax on


>
> Thanks Tim.  e file.vim works.  I'll use that instead of r file.vim.
>
> jic
>

Instead of ^Wn followed by ":e file.vim" you can also do ":new file.vim"
which will edit the file into a newly opened window (and set the filetype &
syntax as per ":e").

Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: CTLR_W and syntax on

Tim Chase-2
> Instead of ^Wn followed by ":e file.vim" you can also do ":new
> file.vim" which will edit the file into a newly opened window
> (and set the filetype & syntax as per ":e").


Or you can use

        :sp file.vim

Or if you want to split it vertically, you can use

        :vs file.vim

For those lazy like me, that's one less keystroke each time you
do it, compared to ":vne[w]" or ":new"

Additionally, if that file name is under the cursor in your
current buffer, you can use "CTRL_W f" to split the file named
under the cursor into a new window.

-tim




Reply | Threaded
Open this post in threaded view
|

Re: CTLR_W and syntax on

jose isaias cabrera-2

thanks again, both of you!

By the way, you guys are scary with all the vim knowledge. :-)  Not that
there is anything wrong with that. ;-)

I'll use

:sp file.vim

to save that extra keystroke. :-)

again, thanks.

jic

On 16:01 Mon 08 Aug     , Tim Chase wrote:

> >Instead of ^Wn followed by ":e file.vim" you can also do ":new
> >file.vim" which will edit the file into a newly opened window
> >(and set the filetype & syntax as per ":e").
>
>
> Or you can use
>
> :sp file.vim
>
> Or if you want to split it vertically, you can use
>
> :vs file.vim
>
> For those lazy like me, that's one less keystroke each time you
> do it, compared to ":vne[w]" or ":new"
>
> Additionally, if that file name is under the cursor in your
> current buffer, you can use "CTRL_W f" to split the file named
> under the cursor into a new window.
>
> -tim
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: CTLR_W and syntax on

A.J.Mechelynck
----- Original Message -----
From: "jose isaias cabrera" <[hidden email]>
To: "Tim Chase" <[hidden email]>
Cc: "Tony Mechelynck" <[hidden email]>; "Vim" <[hidden email]>
Sent: Monday, August 08, 2005 11:08 PM
Subject: Re: CTLR_W and syntax on


>
> thanks again, both of you!
>
> By the way, you guys are scary with all the vim knowledge. :-)  Not that
> there is anything wrong with that. ;-)
[...]

I'm not speaking for Tim, but in the relatively short time I've been using
Vim (how much? a year I guess) I've learnt a lot, mostly by reading the
mailing list, reading the help, following the links in the help files, and
using two great tools to find one's needle in that vast haystack, namely
":helpgrep" (q.v.) and help tag completion (with the latter, I use ":set
wildmenu wildmode=full" so ":help blabla<Tab>" gives me a menu of possible
help subjects matching the pattern blabla).

You'll see: I bet that a year from now you'll be a lot handier with Vim than
you are now.


Best regards,
Tony.