vim

Martynas Maciulevičius 2022-08-29T06:41:28.259479Z

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?

tomd 2022-08-29T08:01:21.171189Z

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čius 2022-08-29T08:07:07.128579Z

I can open Spacemacs and save this file:

Martynas Maciulevičius 2022-08-29T08:07:27.583359Z

Then open it in vim and see this:

Martynas Maciulevičius 2022-08-29T08:07:51.222849Z

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 🤔 Not sure if it's possible

Martynas Maciulevičius 2022-08-29T08:09:27.785689Z

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

tomd 2022-08-29T08:09:51.419959Z

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

tomd 2022-08-29T08:10:33.993279Z

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čius 2022-08-29T08:11:49.453839Z

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

tomd 2022-08-29T08:27:33.672719Z

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.

tomd 2022-08-29T08:28:51.928699Z

(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čius 2022-08-29T08:34:46.314769Z

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

👍 1
2022-08-29T12:46:27.975799Z

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