0

I want to Vim to behave like nvi when opening a in an empty buffer.

This is an empty buffer:

----------------------------------------
~
~
~
~
----------------------------------------

After typing oHello, world!<esc> I want to get this result (which is how it behaves in the original Vi):

----------------------------------------
Hello, world!
~
~
~
----------------------------------------

In Vim i get this result instead (notice extra blank line):

----------------------------------------

Hello, world!
~
~
----------------------------------------

Is there any way I can get Vim to behave like nvi when opening new lines in an empty buffer?

I think the nvi behavior is much more useful when I want to type something like 8oEight long lines...<esc> in an empty buffer. Then I don't have to remove the extra blank line that Vim always creates when doing that.

  • 6
    The o in Vi (050325) behaves just like the o in Vim (7.4.2196) and in doing so adheres to the behavior specified in the POSIX standard. You should investigate why your vi doesn't work correctly instead of forcing your Vim to behave incorrectly. – romainl Sep 14 '16 at 21:07
  • 7
    Why not use i instead of o? I agree with @romainl, the "original vi" behaviour of o seems very strange. What vi are you using where you see this behaviour? – Martin Tournoij Sep 14 '16 at 21:59
  • 1
    You can always use 8 O Eight long lines...<esc> instead (using capital o) – VanLaser Sep 14 '16 at 22:36
  • 1
    nvi behaves the same. there does not seem to be a 'cpo' setting to change that behaviour. However you could simply map it like this possibly: :nnoremap <expr> o line('$')==1 && empty(getline(1))?'i':'o' – Christian Brabandt Sep 15 '16 at 6:37
  • 1
    @Carpetsmoker The "strangeness" is the result of an (invisible, except for variants that show a ~ at the top of the screen in this case) distinction between an empty file and a file consisting of a single blank line. – Random832 Sep 15 '16 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.