On Fri, Oct 23, 2026 at 11:43:23PM +0000, dvalin via vim_use wrote: > Vim is so much handier than Vi was last century. The folding options are > great, and the spellchecker installation assist was a neat surprise, last > time. Digraphs, ctags, encryption, ... well... I use simpler vi clones from time to time and there are much more simpler things I immediatly miss: * the text objects (ci", dap, ...) * contextual mappings * buffer and file navigations (c-w-*, gF, ...) but also: vim missed some very cool features from the old tools like https://doc.cat-v.org/bell_labs/structural_regexps/se.pdf Actually, the mix of vim very magic regexps and SRE could be amazing regards -- Marc Chantreux -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/atydWOMYPfLeWQr6%40prometheus.
Saturday, October 24, 2026
Re: Atomic Substitution (a vi way?)
On Sat, Oct 24, 2026 at 05:28:33AM +0300, Riza Dindir wrote: > Maybe this is not answering the question. But I wanted to share... > I do think that vi's feature of using filters, and external tools to pipe > text in and out is wonderful. I do think that this feature is not used as > much... I do use that feature instead of writing viml functions. That is > the feature that made me stick with vi/vim. Indeed! that's why it's so hard to exit from vim: there is no good reason for it :) I really like combos like grep -RFn something<esc>!sh<cr> then use GF > I do use vim for syntax coloring mostly, and the folding. But I am using > vim as it is vi, and use viml when I can not do things with the filter > commands (the ! command). The filter commands are also handy with > read/write commands like r !<filter>. indeed. It would be even more joyable if vim would have a better completion of < from command line :r!dpkg -L <cf regards -- Marc Chantreux -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/atya6dTdbxQPMaNy%40prometheus.
Re: Atomic Substitution (viml solution inspired by the vi way)
On Fri, Oct 23, 2026 at 03:22:51PM -0500, Tim Chase wrote: > > %! tee X | grep -qv '[12]' && cat X || sed s/2/3/ X > > > > tee X | grep -qv '[12]' # checking unacceptable lines while writing X > > && cat X # cat X if there are any > > || sed s/2/3/ X # if none, do the substitution > This isn't bad and I regularly do things like you describe when I'm in > vi(1) or nvi or ed(1) where I lack the full power of vim expressions. > But does then require that you then clean up the X temp-file when you're > done. I actually use a personnal convention here: ~/.[XYZ] are stores for volatile content. I never delete them as * they can be used by another script/mapping in few seconds anyway * sometimes it took me seconds (minutes?) to realize I went wrong, in this case, ~/.[XYZ] can provide informations to understand what was wrong or data that can be a good start give me a second chance. but you made a point. let's provide other examples for future reads: <<\% tee X | grep -qv '[12]' && cat X || sed s/2/3/ X ; rm X <<\% perl -wE '@l= map {chomp; $_}<>; say for (@l == grep /[12]/, @l) ? (map s/2/3/r, @l) : @l' <<\% raku -e '.say for ((my @l=lines).all ~~ /<[ 1 2 ]>/ ?? @l.map: {S/2/3/} !! @l )' <<\% awk '/[12]/{n++} {l[NR]=$0} END{ if (NR!=n) s="cat"; for (i=1; i<=NR; ++i) print l[i]|c }' s='sed s/2/3/' Notes: * the raku version is probably golfable. it puzzles me * I would be delighted by an array programming solution like J or something :) while writing those exemples, I realize we can write a viml solution based on the same idea: if ! len(filter(getline("'a","'b"),'v:val !~ "[12]"' )) | 'a,'bs/2/3/ | endif old school evals is shorter in this case but lambdas are easier to maintain: echo filter(getline("'a","'b") , 'v:val !~ "[12]"' ) echo filter(getline("'a","'b") , { _,v -> v !~ "[12]" } ) vim9cmd echo filter(getline("'a", "'b"), (_, v) => v !~ "[12]" ) It would be even better if vim could use commands as part of expressions and coerce lists in boolean (even python have it!) and num contexts [] => 0 => false ["haha","cool"] => 2 => true + ["haha","cool"] => 2 because an ultimate solution could have been :let filter(getline("'a","'b"),'v:val !~ "[12]"' )) ?? 'a,'bs/2/3/ regards. -- Marc Chantreux -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/atyXJxRAf7-lstPe%40prometheus.
Friday, October 23, 2026
AW: AW: Atomic Substitution.
Tim, but your 4-line example can be solved exactly by the command I previously suggested; for your case it would be just :g/one a/s/a/b/ Mind that it gets only slightly more difficult if the substitution pattern would also be part of the "global" pattern, as if your lines would have one e one e one one e then it would be necessary to better characterize the substitution pattern; in this case, for example, by adding the space to the pattern and replacement. :g/one e/s/ e/ b/ There's yet more complicated patterns thinkable. Solutions can likely be found with such elementary ex-commands without the need to resort to vim-scripting. Janis ________________________________________ Von: vim_use@googlegroups.com <vim_use@googlegroups.com> im Auftrag von Tim Chase <vim@tim.thechases.com> Gesendet: Freitag, 23. Oktober 2026 16:51 An: vim_use@googlegroups.com Betreff: Re: AW: Atomic Substitution. On 2026-10-23 13:46, Janis Papanagnou wrote: >> I woud like to first make ether a range selection or a grep on ines >> and after that substitute them but only if the substitution can take >> place on all itemm. Is that possible? > > Your description is not quite clear to me. - It sounds as if you want > something like I *think* the intent is that the OP only wants to do the replacement if *all* the lines match the problem, so if you had something like one a one a one one a and they want something like :g/one/s/a/b/ but only if *all* the /one/ matches have a substitute that will take place. In my example above, the 3rd one doesn't have an "a" that would be substituted, so it sounds like the OP would like the whole batch to fail. One would likely have to check the count of substitution-lines before and the number of substitution-lines after, and see if they match. Maybe something like this wrapped in a function: let a=0 let b=0 g/pattern1/let a+=1 g/pattern1/g/pattern2/let b+=1 if (a == b) | g/pattern1/s/pattern2/replacement/g | endif For the OP's "range of lines" version, the pattern1 would be just /^/ and the 3 ":g" commands would need the relevant range before them '<,'>g/pattern1/let a+=1 '<,'>g/pattern1/g/pattern2/let b+=1 if (a == b) | '<,'>g/pattern1/s/pattern2/replacement/g | endif I might be misunderstanding, but at least that's how I parse the "only if the substitution can take place on all" :-) -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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/att0fQbUZpyh6kIH%40thechases.com. -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/PAXPR05MB8908533F9BDD37696C3F7DD8F3642%40PAXPR05MB8908.eurprd05.prod.outlook.com.
Re: Atomic Substitution.
On 2026-10-23 16:55, Vim Users wrote: > But I have overseen one thing. Lets see I have a block like this: > > 1 > 1 > 2 > 1 > 1 > 1 > 1 > > And I want to substitute all 1 to 3 but only if all lines can be substituted. > > So this should be refuted while > > 1 > 1 > 1 > 1 > 1 > 1 > 1 > > should be substituted. Maybe something like let refrain=0 | exec 'v/pattern/let refrain+=1' | if (refrain == 0) | %s//replacement/g | endif This assumes we shouldn't refrain from doing the substitution, but if any lines in the file don't match, it will set 'refrain' to a non-zero value. The 'if' block then checks the value to see if it should refrain from doing the substution, and only proceed with the substitution if all the lines matched the /pattern/ in question. Making it work for arbitrary ranges or grep-subsets of lines gets a little trickier, but doable. -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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/att6Zo3U865p7NW-%40thechases.com.
Re: Atomic Substitution.
But I have overseen one thing. Lets see I have a block like this: 1 1 2 1 1 1 1 And I want to substitute all 1 to 3 but only if all lines can be substituted. So this should be refuted while 1 1 1 1 1 1 1 should be substituted. On 2026-10-23 13:46:11, Janis Papanagnou wrote: > Your description is not quite clear to me. - It sounds as if you want something like > > :g/pattern/s/pattern/replacement/g > > or > > :g/grep-pattern/s/other-pattern/replacement/g > > i.e. use of the "global" command 'g' to select all existing matching lines, > and only on those do another replacement on the second pattern expression. > > For example to replace the word "world" by "vim" only in lines where > "hello world" is seen (but not, e.g., in lines where "world wide web" is written) > > :g/hello world/s/world/vim/g > > If that's not what you want, please clarify. > > Janis > > ________________________________________ > Von: 'Frank Schwidom' via vim_use <vim_use@googlegroups.com> > Gesendet: Freitag, 23. Oktober 2026 15:33 > An: vim_use@googlegroups.com > Betreff: Atomic Substitution. > > Hi. > > I woud like to first make ether a range selection or a grep on ines and after that substitute them but only if the substitution can take place on all itemm. Is that possible? > > Thanks in Advance. > > -- > -- > 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+unsubscribe@googlegroups.com. > To view this discussion visit https://groups.google.com/d/msgid/vim_use/attiQu6zokeSUzll%40debian64. > > -- > -- > 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+unsubscribe@googlegroups.com. > To view this discussion visit https://groups.google.com/d/msgid/vim_use/PAXPR05MB890835EB32D675404728FFDEF3642%40PAXPR05MB8908.eurprd05.prod.outlook.com. > -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/att1TWog2NG6DgMo%40debian64.
Re: AW: Atomic Substitution.
On 2026-10-23 13:46, Janis Papanagnou wrote: >> I woud like to first make ether a range selection or a grep on ines >> and after that substitute them but only if the substitution can take >> place on all itemm. Is that possible? > > Your description is not quite clear to me. - It sounds as if you want > something like I *think* the intent is that the OP only wants to do the replacement if *all* the lines match the problem, so if you had something like one a one a one one a and they want something like :g/one/s/a/b/ but only if *all* the /one/ matches have a substitute that will take place. In my example above, the 3rd one doesn't have an "a" that would be substituted, so it sounds like the OP would like the whole batch to fail. One would likely have to check the count of substitution-lines before and the number of substitution-lines after, and see if they match. Maybe something like this wrapped in a function: let a=0 let b=0 g/pattern1/let a+=1 g/pattern1/g/pattern2/let b+=1 if (a == b) | g/pattern1/s/pattern2/replacement/g | endif For the OP's "range of lines" version, the pattern1 would be just /^/ and the 3 ":g" commands would need the relevant range before them '<,'>g/pattern1/let a+=1 '<,'>g/pattern1/g/pattern2/let b+=1 if (a == b) | '<,'>g/pattern1/s/pattern2/replacement/g | endif I might be misunderstanding, but at least that's how I parse the "only if the substitution can take place on all" :-) -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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/att0fQbUZpyh6kIH%40thechases.com.
Re: Atomic Substitution.
I see, it already seems to work, thanks. On 2026-10-23 13:46:11, Janis Papanagnou wrote: > Your description is not quite clear to me. - It sounds as if you want something like > > :g/pattern/s/pattern/replacement/g > > or > > :g/grep-pattern/s/other-pattern/replacement/g > > i.e. use of the "global" command 'g' to select all existing matching lines, > and only on those do another replacement on the second pattern expression. > > For example to replace the word "world" by "vim" only in lines where > "hello world" is seen (but not, e.g., in lines where "world wide web" is written) > > :g/hello world/s/world/vim/g > > If that's not what you want, please clarify. > > Janis > > ________________________________________ > Von: 'Frank Schwidom' via vim_use <vim_use@googlegroups.com> > Gesendet: Freitag, 23. Oktober 2026 15:33 > An: vim_use@googlegroups.com > Betreff: Atomic Substitution. > > Hi. > > I woud like to first make ether a range selection or a grep on ines and after that substitute them but only if the substitution can take place on all itemm. Is that possible? > > Thanks in Advance. > > -- > -- > 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+unsubscribe@googlegroups.com. > To view this discussion visit https://groups.google.com/d/msgid/vim_use/attiQu6zokeSUzll%40debian64. > > -- > -- > 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+unsubscribe@googlegroups.com. > To view this discussion visit https://groups.google.com/d/msgid/vim_use/PAXPR05MB890835EB32D675404728FFDEF3642%40PAXPR05MB8908.eurprd05.prod.outlook.com. > -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/att0HG0tOJXe6AEV%40debian64.
AW: Atomic Substitution.
Your description is not quite clear to me. - It sounds as if you want something like :g/pattern/s/pattern/replacement/g or :g/grep-pattern/s/other-pattern/replacement/g i.e. use of the "global" command 'g' to select all existing matching lines, and only on those do another replacement on the second pattern expression. For example to replace the word "world" by "vim" only in lines where "hello world" is seen (but not, e.g., in lines where "world wide web" is written) :g/hello world/s/world/vim/g If that's not what you want, please clarify. Janis ________________________________________ Von: 'Frank Schwidom' via vim_use <vim_use@googlegroups.com> Gesendet: Freitag, 23. Oktober 2026 15:33 An: vim_use@googlegroups.com Betreff: Atomic Substitution. Hi. I woud like to first make ether a range selection or a grep on ines and after that substitute them but only if the substitution can take place on all itemm. Is that possible? Thanks in Advance. -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/attiQu6zokeSUzll%40debian64. -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/PAXPR05MB890835EB32D675404728FFDEF3642%40PAXPR05MB8908.eurprd05.prod.outlook.com.
Atomic Substitution.
Hi. I woud like to first make ether a range selection or a grep on ines and after that substitute them but only if the substitution can take place on all itemm. Is that possible? Thanks in Advance. -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/attiQu6zokeSUzll%40debian64.
Thursday, October 22, 2026
Re: Context-Sensitive Python Syntax Highlighting
On Mon, Mar 17, 2014 at 09:24:02PM -0500, Eric Pruitt wrote: > I'm attempting to create a syntax file for Python loaded from > $VIM/after/syntax/python.vim that generates rules to highlight "else" > based on context; python allows "else" to be used for "while" and "for" > loops as well as in "try" blocks after "except" entries. I've gotten > fairly close to achieving the behaviour I want, but I'm stuck now and > have not been able to figure out how to resolve some remaining issues. I eventually resolved this thanks to LLMs. I'm attaching the generated file. I've been using it for a number of days now, and I haven't run into it any problems so far. Any changes I make to it in the future will likely be [available in the repo I use for my configuration files](https://github.com/ericpruitt/emus/blob/master/configuration/vim/after/syntax/python.vim). 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/atrXS-FpKjYDj9UK%40sinister.lan.codevat.com.
" Description: Context-sensitive highlighting for `else` clauses. " " else after for/while -> same colour as the loop keyword (pythonRepeat) " else after try/except -> same colour as `except` (pythonException) " any other else (if/else) -> untouched (pythonConditional) " " Install as ~/.vim/after/syntax/python.vim " " AI Disclosure: " - Authorship: AI-generated " - Models: claude-sonnet-5-5 (Anthropic) " - Scope: Entire file written by the AI to replace an earlier hand-written " attempt, working from the human's goal, test cases and performance feedback, " and checked automatically against Python's own parser on real files. " - References: https://groups.google.com/g/vim_use/c/BJ4jfiEWR7Q/m/ao69FxAuyqQJ " " How it works " ------------ " A block starts at a `for`/`while` (or `except`) and ends " * at an `else` with exactly the same indentation as the header, or " * at the first line that is dedented below the header, or that has the " same indentation but is not the matching `else` (for try: nor `except`). " The `else` that ends a block is highlighted like the keyword that opened it. " Every other `else` is not part of any block, so the base syntax file " highlights it as before. " " The header's indentation is captured with \z( \) when the region starts and " compared with \z1 in the end pattern, so any indentation width (spaces or " tabs) and any nesting depth works, with just a handful of rules. " " Performance notes " ----------------- " Vim evaluates these patterns on every line while it scrolls, so they are kept " cheap: the start patterns are anchored with ^ (rejected at once everywhere but " the start of a line), there is no look-behind of unbounded length, and the " start patterns ask for Vim's backtracking regexp engine with \%#=1 (Vim 7.4 or " later), which is about twice as fast as the default NFA engine for such short " anchored patterns. (The end patterns use the default engine; it is faster for " them.) " First character of a line that counts as code. Blank lines (also those with a " stray CR or form feed), comments (which may sit at any column) and closing " brackets (Black puts the `)` of a multi-line `for x in f(...)` header at the " indentation of the `for`) never end a block. let s:code = '[^ \t\r\x0c#)\]}]' " End patterns. Each is "plain end" or "the matching else". " " Indented header (\z1 is the header's indentation): " not deeper than the header: \%(\z1[ \t]\)\@! " not the matching else: \%(\z1else\>\)\@! " The plain end is zero width and sits at column 0, so it never swallows the " first word of the next line (`def`, `class`... keep their own highlighting). " The `else` itself is matched by the END pattern (an end pattern beats the " built-in `else` keyword) and highlighted via matchgroup. let s:loopEnd = '\%(^\ze\%(\z1[ \t]\)\@!\%(\z1else\>\)\@![ \t]*' . s:code . '\)' \ . '\|\%(^\z1\zselse\>\)' let s:tryEnd = '\%(^\ze\%(\z1[ \t]\)\@!\%(\z1\%(else\|except\)\>\)\@![ \t]*' . s:code . '\)' \ . '\|\%(^\z1\zselse\>\)' " Header at column 0: there is no indentation to compare with. let s:loopEnd0 = '\%(^\ze\%(else\>\)\@!' . s:code . '\)\|\%(^\zselse\>\)' let s:tryEnd0 = '\%(^\ze\%(\%(else\|except\)\>\)\@!' . s:code . '\)\|\%(^\zselse\>\)' " Indented headers. The start is ^-anchored and begins at column 0, ahead of the " keyword, so the keyword does not interfere. The [ \t]\@! after the captured " indentation makes the (greedy) match fail at once instead of retrying with " less indentation. " " contains=TOP means "every ordinary top-level group", so there is no list of " excluded groups to maintain. There is deliberately no `keepend`: with it, " low-indented text inside a triple-quoted string would close the block (and " the string) in the middle of the string. execute 'syn region pythonLoopBlock' \ . ' start="\%#=1^\z([ \t]\+\)[ \t]\@!\%(async\s\+\)\=\%(for\|while\)\>"' \ . ' matchgroup=pythonLoopElse end="' . s:loopEnd . '"' \ . ' transparent contains=TOP' execute 'syn region pythonTryBlock' \ . ' start="\%#=1^\z([ \t]\+\)except\>"' \ . ' matchgroup=pythonTryElse end="' . s:tryEnd . '"' \ . ' transparent contains=TOP' " Headers at column 0. The keyword is at column 0 as well, and a keyword beats a " match or region that starts in the same column, so a start there would never " fire. Instead the keyword itself hands over (nextgroup) to a zero-width region " that starts right after it. These keywords are added to the existing groups, " so their colour and group name are unchanged, and Vim only looks at the start " patterns after one of these three words. " " `for` is 3 letters, so a `for` that ends in column 4 began in column 1; " likewise `while` (5 letters, column 6) and `except` (6 letters, column 7). The " short look-behind makes sure the line really starts with the keyword: Vim also " tries these patterns inside `.attribute` matches, where the column alone is " not enough. syn keyword pythonRepeat for nextgroup=pythonLoopBlock0For syn keyword pythonRepeat while nextgroup=pythonLoopBlock0While syn keyword pythonException except nextgroup=pythonTryBlock0 execute 'syn region pythonLoopBlock0For contained start="\%#=1\%4c\%(^for\)\@3<="' \ . ' matchgroup=pythonLoopElse end="' . s:loopEnd0 . '"' \ . ' transparent contains=TOP' execute 'syn region pythonLoopBlock0While contained start="\%#=1\%6c\%(^while\)\@5<="' \ . ' matchgroup=pythonLoopElse end="' . s:loopEnd0 . '"' \ . ' transparent contains=TOP' execute 'syn region pythonTryBlock0 contained start="\%#=1\%7c\%(^except\)\@6<="' \ . ' matchgroup=pythonTryElse end="' . s:tryEnd0 . '"' \ . ' transparent contains=TOP' " The colours: an `else` that closes a block looks exactly like the keyword that " opened it, whatever the colour scheme does with those groups. The first two " lines are fallbacks, only used if the base syntax file did not already define " the groups. hi def link pythonRepeat Repeat hi def link pythonException Exception hi def link pythonLoopElse pythonRepeat hi def link pythonTryElse pythonException unlet s:code s:loopEnd s:tryEnd s:loopEnd0 s:tryEnd0
Friday, October 16, 2026
Your Google Account is being deleted
|
|||||
Friday, October 2, 2026
Re: unexpected result using autocmd
On 10/02/2026 2:54 AM, Maxim Kim wrote: > https://github.com/vim/vim/issues/21427 > > The help topic for 'modified' specifically mention some events that do not > set it, although missing the Filetype event. Yes, I saw this as well. Perhaps it should be part of the bug-fix.> > On Friday, October 2, 2026 at 4:31:21 PM UTC+10 Maxim Kim wrote: > >> This looks like a bug, worth creating an issue in vim's github. >> >> echo getbufinfo(bufnr()) says that `changed: 0` however `changedtick` is >> greater than 0 >> >> As for >> >>> It's purpose is to automatically insert lines in files that have a >> specified filetype or to provide that service for other files >> >> check :h skeleton >> >> But it would have the same issue as with Filetype >> >> On Friday, October 2, 2026 at 12:41:59 PM UTC+10 Mike wrote: >> >>> Hi all, >>> >>> I'm seeing unexpected behavior when using an autocmd defined in a >>> plugin. A simplified version of the plugin is the following: >>> >>> function! InsertText() >>> echomsg "modified option is " .. &modified >>> call append(line("$"), "section title") >>> echomsg "modified option is " .. &modified >>> endfunction >>> >>> autocmd FileType fortran call InsertText() >>> command -nargs=0 ForNoFT call InsertText() >>> >>> It's purpose is to automatically insert lines in files that have a >>> specified filetype or to provide that service for other files. In the >>> above example, I've used "fortran" but I think any vim-recognized >>> filetype will do. >>> >>> To show the problem, edit a Fortran file, e.g. run "vim test.f90". You >>> will see the text "section title" in the buffer. However, even though >>> the 'modified' option is set, I am allowed to quit vim (:q). Also, ^G >>> does not show modified. This behavior occurs whether the file >>> "test.f90" is new or has content. >>> >>> A user-command has been defined in the plugin, intended for files >>> without a filetype. When you run "vim test.unknown" and then run the >>> user-command "ForNoFT", quit will fail as expected and ^G will show >>> modified. >>> >>> Interestingly, if 'modified' is explicitly set in the function, then vim >>> will not quit because it sees test.f90 as modified. >>> >>> My question is why the difference? >>> I'm running vim 9.2.1036 with normal features on Windows 10. >>> >>> Thanks for any help. >>> -mike >>> >>> >>> >>> > -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/119objp%24he5%242%40ciao.gmane.io.
Re: unexpected result using autocmd
Maxim, On 10/02/2026 2:31 AM, Maxim Kim wrote: > This looks like a bug, worth creating an issue in vim's github. Okay, I will do so.> > echo getbufinfo(bufnr()) says that `changed: 0` however `changedtick` is > greater than 0 > > As for > >> It's purpose is to automatically insert lines in files that have a > specified filetype or to provide that service for other files > > check :h skeleton Thanks for the tip. I've never seen this example in help even though it pre-dates Vim 7.0. Learn something new every day.> > But it would have the same issue as with Filetype > > On Friday, October 2, 2026 at 12:41:59 PM UTC+10 Mike wrote: > >> Hi all, >> >> I'm seeing unexpected behavior when using an autocmd defined in a >> plugin. A simplified version of the plugin is the following: >> >> function! InsertText() >> echomsg "modified option is " .. &modified >> call append(line("$"), "section title") >> echomsg "modified option is " .. &modified >> endfunction >> >> autocmd FileType fortran call InsertText() >> command -nargs=0 ForNoFT call InsertText() >> >> It's purpose is to automatically insert lines in files that have a >> specified filetype or to provide that service for other files. In the >> above example, I've used "fortran" but I think any vim-recognized >> filetype will do. >> >> To show the problem, edit a Fortran file, e.g. run "vim test.f90". You >> will see the text "section title" in the buffer. However, even though >> the 'modified' option is set, I am allowed to quit vim (:q). Also, ^G >> does not show modified. This behavior occurs whether the file >> "test.f90" is new or has content. >> >> A user-command has been defined in the plugin, intended for files >> without a filetype. When you run "vim test.unknown" and then run the >> user-command "ForNoFT", quit will fail as expected and ^G will show >> modified. >> >> Interestingly, if 'modified' is explicitly set in the function, then vim >> will not quit because it sees test.f90 as modified. >> >> My question is why the difference? >> I'm running vim 9.2.1036 with normal features on Windows 10. >> >> Thanks for any help. >> -mike >> >> >> >> > -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/119obhg%24he5%241%40ciao.gmane.io.
Thursday, October 1, 2026
Re: unexpected result using autocmd
This looks like a bug, worth creating an issue in vim's github.
echo getbufinfo(bufnr()) says that `changed: 0` however `changedtick` is greater than 0
As for> It's purpose is to automatically insert lines in files that have a
specified filetype or to provide that service for other files
check :h skeleton
But it would have the same issue as with Filetype
On Friday, October 2, 2026 at 12:41:59 PM UTC+10 Mike wrote:
Hi all,
I'm seeing unexpected behavior when using an autocmd defined in a
plugin. A simplified version of the plugin is the following:
function! InsertText()
echomsg "modified option is " .. &modified
call append(line("$"), "section title")
echomsg "modified option is " .. &modified
endfunction
autocmd FileType fortran call InsertText()
command -nargs=0 ForNoFT call InsertText()
It's purpose is to automatically insert lines in files that have a
specified filetype or to provide that service for other files. In the
above example, I've used "fortran" but I think any vim-recognized
filetype will do.
To show the problem, edit a Fortran file, e.g. run "vim test.f90". You
will see the text "section title" in the buffer. However, even though
the 'modified' option is set, I am allowed to quit vim (:q). Also, ^G
does not show modified. This behavior occurs whether the file
"test.f90" is new or has content.
A user-command has been defined in the plugin, intended for files
without a filetype. When you run "vim test.unknown" and then run the
user-command "ForNoFT", quit will fail as expected and ^G will show
modified.
Interestingly, if 'modified' is explicitly set in the function, then vim
will not quit because it sees test.f90 as modified.
My question is why the difference?
I'm running vim 9.2.1036 with normal features on Windows 10.
Thanks for any help.
-mike
--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/85a1e44b-f2dd-438e-82e4-d1c6b88bc7f7n%40googlegroups.com.
Re: unexpected result using autocmd
Hi all,
I'm seeing unexpected behavior when using an autocmd defined in a
plugin. A simplified version of the plugin is the following:
function! InsertText()
echomsg "modified option is " .. &modified
call append(line("$"), "section title")
echomsg "modified option is " .. &modified
endfunction
autocmd FileType fortran call InsertText()
command -nargs=0 ForNoFT call InsertText()
It's purpose is to automatically insert lines in files that have a
specified filetype or to provide that service for other files. In the
above example, I've used "fortran" but I think any vim-recognized
filetype will do.
To show the problem, edit a Fortran file, e.g. run "vim test.f90". You
will see the text "section title" in the buffer. However, even though
the 'modified' option is set, I am allowed to quit vim (:q). Also, ^G
does not show modified. This behavior occurs whether the file
"test.f90" is new or has content.
A user-command has been defined in the plugin, intended for files
without a filetype. When you run "vim test.unknown" and then run the
user-command "ForNoFT", quit will fail as expected and ^G will show
modified.
Interestingly, if 'modified' is explicitly set in the function, then vim
will not quit because it sees test.f90 as modified.
My question is why the difference?
I'm running vim 9.2.1036 with normal features on Windows 10.
Thanks for any help.
-mike
--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/de73247d-1ee9-4ad8-9991-1f7ca8dca8a4n%40googlegroups.com.
unexpected result using autocmd
Hi all, I'm seeing unexpected behavior when using an autocmd defined in a plugin. A simplified version of the plugin is the following: function! InsertText() echomsg "modified option is " .. &modified call append(line("$"), "section title") echomsg "modified option is " .. &modified endfunction autocmd FileType fortran call InsertText() command -nargs=0 ForNoFT call InsertText() It's purpose is to automatically insert lines in files that have a specified filetype or to provide that service for other files. In the above example, I've used "fortran" but I think any vim-recognized filetype will do. To show the problem, edit a Fortran file, e.g. run "vim test.f90". You will see the text "section title" in the buffer. However, even though the 'modified' option is set, I am allowed to quit vim (:q). Also, ^G does not show modified. This behavior occurs whether the file "test.f90" is new or has content. A user-command has been defined in the plugin, intended for files without a filetype. When you run "vim test.unknown" and then run the user-command "ForNoFT", quit will fail as expected and ^G will show modified. Interestingly, if 'modified' is explicitly set in the function, then vim will not quit because it sees test.f90 as modified. My question is why the difference? I'm running vim 9.2.1036 with normal features on Windows 10. Thanks for any help. -mike -- -- 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+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/119n5kq%241mt%241%40ciao.gmane.io.