🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

10 total messages Started by Janis Papanagnou Wed, 07 Oct 2026 16:49
Vim - set differing syntaxes in split view of the same source file?
#1
Author: Janis Papanagnou
Date: Wed, 07 Oct 2026 16:49
18 lines
1927 bytes
Occasionally I've in script programs embedded code of other script
languages, say, awk code embedded in shell code. (But we could also
imagine other embeddings, like assembly in "C", CSS or JS in HTML,
inline-data in shell, or some such.)

I just tried to ':split' the screen and define on the fly another
syntax by ':set syntax=...', but that setting affects both parts of
the split-screen.

I wonder whether such a feature - to override the file specific
syntax setting in split-views - would be worthwhile to have.[*]
(This is just a poll on opinions, yet an academic question.)

Janis

[*] Yet I achieve the desired behavior by having a separate but
specific vim syntax-code in $HOME/.vim/after/syntax/sh/awkembed.vim
Re: Vim - set differing syntaxes in split view of the same source file?
#2
Author: Kenny McCormack
Date: Wed, 07 Oct 2026 18:42
34 lines
2452 bytes
In article <11a5t6k$2fkbe$3@dont-email.me>,
Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
...
>I wonder whether such a feature - to override the file specific
>syntax setting in split-views - would be worthwhile to have.[*]
>(This is just a poll on opinions, yet an academic question.)

I think not.  I assume that the syntax highlighting variables are local to
the buffer.  This is basically a feature - it's how buffers work.

I have sometimes been in the situation of wanting to open the same file
twice but force VIM to treat them as separate buffers.  I have not tried
very hard, but it would be worth testing making a link (either hard or
soft) and opening that in a separate window (and hoping it gets a new
buffer assigned to it).

>Janis
>
>[*] Yet I achieve the desired behavior by having a separate but
>specific vim syntax-code in $HOME/.vim/after/syntax/sh/awkembed.vim

I assume that I am not telling you anything you don't already know, but,
yes, the standard solution to this is to use awkembed so that the embedded
AWK is highlighted as AWK.

The problem with that is that it doesn't scale.  You have to deal with it
for each combination that you encounter.

-- 
People seem to think that Youtube (and Facebook and Twitter and so on) is
(are) some sort of resource created for the public good.  Why they delude
themselves into believing this is beyond my ability to comprehend.

Usenet will always be here.  Longer than people remember what port 80 was for.
Re: Vim - set differing syntaxes in split view of the same source file?
#3
Author: Janis Papanagnou
Date: Thu, 08 Oct 2026 06:13
52 lines
3598 bytes
On 2026-10-07 20:42, Kenny McCormack wrote:
> In article <11a5t6k$2fkbe$3@dont-email.me>,
> Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
> ...
>> I wonder whether such a feature - to override the file specific
>> syntax setting in split-views - would be worthwhile to have.[*]
>> (This is just a poll on opinions, yet an academic question.)
> 
> I think not.  I assume that the syntax highlighting variables are local to
> the buffer.  This is basically a feature - it's how buffers work.

Yeah.

> 
> I have sometimes been in the situation of wanting to open the same file
> twice but force VIM to treat them as separate buffers.  I have not tried
> very hard, but it would be worth testing making a link (either hard or
> soft) and opening that in a separate window (and hoping it gets a new
> buffer assigned to it).

Oh, it's less about finding a workaround; or at least to have one
that is easy to achieve on the fly. - The cute thing with ':split'
would be the tight coupling, no external kludge. - It would have
to be some sort of inherited behavior; as you say, the buffers may
have the attributes local, and the split-window could inherit that
as default but could overwrite it on a second level. - So far my
thoughts.

>> [*] Yet I achieve the desired behavior by having a separate but
>> specific vim syntax-code in $HOME/.vim/after/syntax/sh/awkembed.vim
> 
> I assume that I am not telling you anything you don't already know, but,
> yes, the standard solution to this is to use awkembed so that the embedded
> AWK is highlighted as AWK.
> 
> The problem with that is that it doesn't scale.  You have to deal with it
> for each combination that you encounter.

Yes, exactly. - You'd also need to know vim's syntax-scripting. But
using the already existing syntax files - and just "combine" them,
or rather activate them - would need no individual vim-programming,
it would be just there.

I had learned to live with the current behavior, but Vim has so cool
and orthogonal features - even after decades it did still surprise
me a at times! - and if it had such a feature it would alleviate the
"suffering" a bit. (But no big deal.)

I thought I just ask for a second opinion. - Thanks!

Janis
Re: Vim - set differing syntaxes in split view of the same source file?
#7
Author: Eric Pozharski
Date: Thu, 08 Oct 2026 10:52
24 lines
2196 bytes
with <11a7c9o$2fkbe$4@dont-email.me> Janis Papanagnou wrote:
> On 2026-10-07 20:42, Kenny McCormack wrote:
>> In article <11a5t6k$2fkbe$3@dont-email.me>, Janis Papanagnou
>> <janis_papanagnou+ng@hotmail.com> wrote: ...

>>> I wonder whether such a feature - to override the file specific
>>> syntax setting in split-views - would be worthwhile to have.[*]
>>> (This is just a poll on opinions, yet an academic question.)
>> I think not.  I assume that the syntax highlighting variables are
>> local to the buffer.  This is basically a feature - it's how buffers
>> work.
*SKIP* [ 27 lines   3 levels deep]
> I thought I just ask for a second opinion. - Thanks!

(disclaimer) I've not developed intuition about files-buffers-windows
yet (and my fight with :hi hasn't even started), but looks like

	:h :ownsyntax

is what you're after.  Would it work is beyond my understanding.

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
Re: Vim - set differing syntaxes in split view of the same source file?
#4
Author: Kenny McCormack
Date: Thu, 08 Oct 2026 13:26
46 lines
3086 bytes
In article <11a7c9o$2fkbe$4@dont-email.me>,
Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
...
>> I have sometimes been in the situation of wanting to open the same file
>> twice but force VIM to treat them as separate buffers.  I have not tried
>> very hard, but it would be worth testing making a link (either hard or
>> soft) and opening that in a separate window (and hoping it gets a new
>> buffer assigned to it).

FWIW, I did some testing and could not find a way to make VIM create a new
buffer for the same file.  I tried linking (both soft and hard), even tried
"mount --bind".  There's probably other things I could try, but it seems
pretty determined not to let you do it.

Of course, then it occurred to me that the easy way is just to open a new
tab/window/whatever and :r the file.  Then you'll have the contents of the
file, but it won't be associated with the original file.

>>> [*] Yet I achieve the desired behavior by having a separate but
>>> specific vim syntax-code in $HOME/.vim/after/syntax/sh/awkembed.vim

BTW, I may be mis-understanding the overall goal here.

I mean, I understand how you would want the AWK part of a shell script
highlighted as if it were AWK, but would you really want the entire shell
script highlighted that way?  I doubt that would look very good.

>Yes, exactly. - You'd also need to know vim's syntax-scripting. But
>using the already existing syntax files - and just "combine" them,
>or rather activate them - would need no individual vim-programming,
>it would be just there.

There *is* a tool out there, that I learned about once on the VIM mailing
list, that is sort of a "generic AWKembed" - i.e., it is supposed to handle
any combination of languages.  But I looked at it and tried to figure it
out - how to actually use it - and couldn't quite get it.  It just looked
too complicated and I gave up.

>I thought I just ask for a second opinion. - Thanks!

BAU!

-- 
Indeed, most .NET developers couldn't pass CS101 at a third-rate
community college.
		- F. Russell -
Re: Vim - set differing syntaxes in split view of the same source file?
#5
Author: Janis Papanagnou
Date: Thu, 08 Oct 2026 15:13
63 lines
4645 bytes
On 2026-10-08 15:26, Kenny McCormack wrote:
[...]
> BTW, I may be mis-understanding the overall goal here.

Those embedded data are typically located "in one place", or more
importantly, in a sequential linear area. Given that I'd have that
split-window opened [here] primarily for the purpose of having a
appropriately highlighted source I can work on, such feature would
do perfectly fine for the purpose. I'd just need to switch (^W^W)
doing the editing in the respective (correctly highlighted) areas
of the same file. (But of course a pin-pointed syntax, preferable
without kludges, in a single window would be preferable.)

> I mean, I understand how you would want the AWK part of a shell script
> highlighted as if it were AWK, but would you really want the entire shell
> script highlighted that way?  I doubt that would look very good.

Right, that wouldn't look good. But the situation is that depending
on the setting either the shell or the awk wouldn't look good. We
can of course on-the-fly just ":set syntax=..." when working in the
respective area - and if we'd define some keys to make that complex
setting/typing bearable that may be a possible, or even a sensible,
workaround. For Shell/Awk I already have that specific script, but
for other such hybrid cases that macro-based syntaxes-switch might
actually be an option (and my thought about the feature obsolete).

PS: It might be necessary to emphasize that I typically don't have
just Awk-oneliners spread across the Shell code rather more complex
Awk functionality, so that's typically a block I can focus on. The
same situation with the other examples; embedded blocks of data, or
JS code that resides at the top of the HTML file in one block. - It
might be necessary to mention that we can of course often separate
the Awk or the JS or whatever embedded code in an own file and just
include that file; "problem" gone. But sometimes a monolithic file
is desired.

> 
>> Yes, exactly. - You'd also need to know vim's syntax-scripting. But
>> using the already existing syntax files - and just "combine" them,
>> or rather activate them - would need no individual vim-programming,
>> it would be just there.
> 
> There *is* a tool out there, that I learned about once on the VIM mailing
> list, that is sort of a "generic AWKembed" - i.e., it is supposed to handle
> any combination of languages.  But I looked at it and tried to figure it
> out - how to actually use it - and couldn't quite get it.  It just looked
> too complicated and I gave up.

Well, that's not surprising; the Net is full of solutions that are
more complex than necessary (or buggy, or cover just special cases,
or don't fit). That's, it seems, why people - me for sure - often
decide to write own solutions. (Of course there's also pearls of
software existing, and to be found.)

PPS: I recall another thought about that requirement I had posted
some time ago; to be able to define a sort of "modelines" anywhere
in the text, like "pragmas". That way I could not only change the
syntax highlighting in a block of text but also change indentation
for that area; the HTML/JS application case had made me ponder about
that back then.

Janis
Re: Vim - set differing syntaxes in split view of the same source file?
#6
Author: Janis Papanagnou
Date: Thu, 08 Oct 2026 18:07
22 lines
2093 bytes
On 2026-10-08 12:52, Eric Pozharski wrote:
> 
> (disclaimer) I've not developed intuition about files-buffers-windows
> yet (and my fight with :hi hasn't even started), but looks like
> 
> 	:h :ownsyntax
> 
> is what you're after.  Would it work is beyond my understanding.

I just read your interesting hint; as described that's exactly
what I had been after. And quick test shows that it works! :-)

As I had written in my previous post:
"even after decades it [Vim] did still surprise me a at times!"

Once again it seems it's in case of Vim not that you cannot do
something specific but that you just have to find where it is.

Thanks!

Janis
Re: Vim - set differing syntaxes in split view of the same source file?
#8
Author: Eric Pozharski
Date: Fri, 09 Oct 2026 12:08
20 lines
2030 bytes
with <11a8m47$2fkbe$6@dont-email.me> Janis Papanagnou wrote:
> On 2026-10-08 12:52, Eric Pozharski wrote:

*SKIP* [  2 lines   2 levels deep]
>> 	:h :ownsyntax
>> is what you're after.  Would it work is beyond my understanding.
> I just read your interesting hint; as described that's exactly what I
> had been after. And quick test shows that it works! :-)

And 15min after posting I've realized that I've set up The
Disappointment Roller-Coaster.  I'm sorry :(

p.s.  Yes, I've checked my grudge (vim script with embedded perl).  At
least I won't have to fight here-docs anymore (and loose).

*CUT* [  4 lines   1 level deep]

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
Re: Vim - set differing syntaxes in split view of the same source file?
#9
Author: Janis Papanagnou
Date: Fri, 09 Oct 2026 18:07
24 lines
2423 bytes
On 2026-10-09 14:08, Eric Pozharski wrote:
> with <11a8m47$2fkbe$6@dont-email.me> Janis Papanagnou wrote:
>> On 2026-10-08 12:52, Eric Pozharski wrote:
> 
> *SKIP* [  2 lines   2 levels deep]
>>> 	:h :ownsyntax
>>> is what you're after.  Would it work is beyond my understanding.
>> I just read your interesting hint; as described that's exactly what I
>> had been after. And quick test shows that it works! :-)
> 
> And 15min after posting I've realized that I've set up The
> Disappointment Roller-Coaster.  I'm sorry :(

I don't understand what you wrote here. (This "Roller-Coaster".)
And there's nothing to be sorry about. (At least with the hint
you gave.) - If you care to explain to a non-native speaker what
I am missing here... - thanks.

Janis

> p.s.  Yes, I've checked my grudge (vim script with embedded perl).  At
> least I won't have to fight here-docs anymore (and loose).

Re: Vim - set differing syntaxes in split view of the same source file?
#10
Author: Eric Pozharski
Date: Sun, 11 Oct 2026 05:11
27 lines
2438 bytes
with <11abahn$cjm0$3@dont-email.me> Janis Papanagnou wrote:
> On 2026-10-09 14:08, Eric Pozharski wrote:
>> with <11a8m47$2fkbe$6@dont-email.me> Janis Papanagnou wrote:
>>> On 2026-10-08 12:52, Eric Pozharski wrote:

*SKIP* [  5 lines   4 levels deep]
>> And 15min after posting I've realized that I've set up The
>> Disappointment Roller-Coaster.  I'm sorry :(
> I don't understand what you wrote here. (This "Roller-Coaster".) And
> there's nothing to be sorry about. (At least with the hint you gave.)
> - If you care to explain to a non-native speaker what I am missing
> here... - thanks.

(correction) The Roller-Coaster of Disappointment sounds better.
Anyway...

This was attempt on meme making.  However, since it's not transparent I
declare this attempt to be a failure.

As of 'Roller Coaster' I may refer you to nearest establishment of
wikipedia (<https://en.wikipedia.org/wiki/Roller_coaster>).

*CUT* [  2 lines   2 levels deep]

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads