Fork me on GitHub
#vim
<
2022-08-29
>
Martynas Maciulevičius06:08:28

Does anyone know if it's possible to make it so that I could visit but not add a newline at the end of the file?

tomd08:08:21

Where would you want to go if there weren't a newline at the end of the file? Does gg?\n<CR> do what you want?

Martynas Maciulevičius08:08:07

I can open Spacemacs and save this file:

Martynas Maciulevičius08:08:27

Then open it in vim and see this:

Martynas Maciulevičius08:08:51

So clearly Spacemacs allows to have an empty line in the UI but then doesn't save that line into the file. So I wanted to have this in vim too :thinking_face: Not sure if it's possible

Martynas Maciulevičius08:08:27

It simply throws me off that it's non-consistent and I got used to it in Spacemacs. That's pretty much it.

tomd08:08:51

That's not quite right. Emacs saves the \n just fine. It's just emacs happens to display a final \n as an empty line, and vim doesn't. It's because of how they differ in their interpretation of what \n means by default

tomd08:08:33

For example, this is an issue where the conclusion is "this isn't a bug, it's just different": https://github.com/vim/vim/issues/488

Martynas Maciulevičius08:08:49

For instance this behavior throws me off: let's say we have file like this in both editors:

hello
hello
[cursor]
hello
hello
Then I press dG and delete last two lines. In vim the result is like this:
hello
[cursor]hello
In Spacemacs it's like this:
hello
hello
[cursor]
But when there are more paragraphs then vim behaves like this (after pressing d}):
a
a
[cursor]
b
b

c
c
->
a
a
[cursor]
c
c
So IMO vim is inconsistent with itself because it hides that last newline

tomd08:08:33

Yeah I can see that that seems inconsistent. For your second example, I think it's because } motion is characterwise by default. If you type dV} instead (forcing linewise motion) then it is consistent with G (which is linewise by default). Likwise, you can do dvG to force G to move characterwise.

tomd08:08:51

(that doesn't change the fact that vim & emacs seem to display a final newline differently, but may be useful to you getting the behaviour you want in vim)

Martynas Maciulevičius08:08:46

I don't know how to do it. But at least vim displays the truth. Even thought adds this small weirdness.

👍 2
Proctor12:08:27

you may also want to look at your fixendofline and endofline settings to see if they are on or off