Hot answers tagged

4

Vim has a special mode for POSIX compliance, which you can enable by setting the $VIM_POSIX environment variable to a non-empty value. See :help posix, which explains it: In 2005 the POSIX test suite was run to check the compatibility of Vim. Most of the test was executed properly. There are the few things where Vim is not POSIX compliant, even when ...


3

Yes, the leading colons and blanks are ignored. It is documented in the Command Line Parsing section of the POSIX specification of Ex. Command-line parsing shall be done in the following steps. For each step, characters already evaluated shall be ignored; that is, the phrase "leading character" refers to the next character that has not yet been ...


3

There are a couple of vi clones besides the traditional ex-vi, that claim to be compatible to traditional vi. However I am not sure, if all meet complete POSIX specs and in the past, there were at least some contradictions between traditional vi and POSIX specs (think of multibyte text, regex flavors, undo and such). You could have a look at busybox vi, ...


3

is Vim minimal (i.e. the default vi on Cygwin) basically a POSIX compliant implementation of vi? No. The vi in Cygwin's vim-minimal package still has features not defined by POSIX. I've verified the availability of visual mode and windowing support, for example. What other common 'minimal' vi's exist? BSD's nvi is pretty minimal, though it has some ...


3

This is a interesting question and I'm not sure I fully understand what is going on. So here are my findings based on my Vim setup. My setup contains some plugins (mainly self written) installed in ~/.vim/pack/.../start. These plugins all require Vim to run in nocompatible mode (see :help 'compatible'). I looked at two different scenarios: run vim -E ...


3

Vim In Vim you can match any character including newline with \_.. You can use this to construct a pattern that matches a whole line, any amount of stuff, and then that same line: /\(^.*$\)\_.*\n\1$/ Now you want to delete all lines in a file that match the first, not including the first. The substitution to delete the last line that matches the first is: ...


2

<C-a> and <C-x> being normal mode commands, they are not really expected to work in ex which doesn't have normal mode. Furthermore, those commands are not defined in the POSIX standard, either for vi or for ex. As for a portable solution, you should probably write an awk script that would contain something like the following: '{gsub( "number: \...


2

You could store whether to exit or not in a register, then execute it: " store q! in register x s/$/^Mq!/ | d x " " if pattern exists, store " in register x g/pattern/ s/$/^M"/ | d x " " execute :q! if pattern wasn't found, :" if it was @x " w %.bup " " ... more edits ... " wq You probably don't want to use ex for any complicated control flow though. Maybe ...


2

Since posting this question I've learned the trick of wrapping automated ex edits in pipelines, with printf used to send the actual commands. This has the advantage that ex will not hang on error conditions. The way I would do this now for a portable script would be: Make a copy (backup) of the file. Do the edits using printf to pipe commands to ex. ...


2

Maybe you could make the substitution and check if the buffer is modified by looking at the value of the option 'modified'. If it is modified, undo, make a backup, redo and exit. Otherwise, if the buffer is not modified, simply quit. It could give something like: vim -c '%s/pattern/replace/ge | exe &mod ? "undo | w %.bup | redo | x" : "q"' file But as ...


2

It would appear that the only POSIX way to do this is to use an external filter, such as sed. For example, to delete the 17th line of your file only if it is exactly identical to the 5th line, and otherwise leave it unchanged, you can do the following: :1,17!sed '5h;17{G;/^\(.*\)\n\1$/d;s/\n.*$//;}' (You could run sed on the entire buffer here, or you ...


1

POSIX has this to say on the matter (emphasis added by me): https://pubs.opengroup.org/onlinepubs/9699919799/ Return to Previous (Context or Section) The [[, ]], (, ), {, and } commands are all affected by "section boundaries", but in some historical implementations not all of the commands recognize the same section boundaries. This is a bug, not ...


1

You need to enable line numbering by calling :set nu $ printf '%s\n' 'set nu' '%s/Quux/Foo/g' %p 'q!' | ex file.txt 1 Foo Bar 2 Foo Foo Bar Bar 4 Bar Bar Bar 5 Foo Foo


1

What other common 'minimal' vi's exist? There is also xvi.sf.net mantained at github.com/martinwguy/xvi which is a different implementation based on STEVIE. It's the smallest full-featured vi clone but has not been checked for POSIX compliant. Bug reports of variations from the standard would be welcome.


Only top voted, non community-wiki answers of a minimum length are eligible