Hot answers tagged

4 votes

POSIX compliant vi implementations

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 ...
user avatar
  • 25.8k
3 votes
Accepted

Leading colons and whitespaces in Ex commands

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 ...
user avatar
  • 2,208
3 votes
Accepted

POSIX compliant vi implementations

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 ...
user avatar
3 votes

What are differences between POSIX vi and minimal vi implementations, if any?

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 ...
user avatar
3 votes
Accepted

Why is `vim -E` always exiting with non-zero exit code when using here-doc?

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 ~...
user avatar
  • 8,585
3 votes

Use ex-command to check whether two lines are identical?

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$/...
user avatar
  • 2,490
2 votes

Increment a number using POSIX features only?

<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, ...
user avatar
  • 32.8k
2 votes

Cause `ex` to automatically exit without saving if a pattern isn't found?

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! ...
user avatar
  • 2,490
2 votes
Accepted

Cause `ex` to automatically exit without saving if a pattern isn't found?

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 ...
user avatar
  • 4,075
2 votes

Cause `ex` to automatically exit without saving if a pattern isn't found?

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 ...
user avatar
  • 6,426
2 votes

Use ex-command to check whether two lines are identical?

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 ...
user avatar
  • 4,075
1 vote
Accepted

What is the correct cursor position when a } (forward paragraph motion) reaches the last line of the buffer?

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 ...
user avatar
  • 12.6k
1 vote

Print current line number to stdout using ex

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
user avatar
  • 2,500
1 vote

What are differences between POSIX vi and minimal vi implementations, if any?

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 ...
user avatar

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