0

I have the following in my .vimrc:

au BufNewFile *.py 0r ~/.vim/skeletons/py.skel | let IndentStyle = "python"

However, when I open a new .py file, there is always a trailing empty line which I would like to remove. I thought it might be due to the final newline in the file py.skel, but I've chomped that off and the behavior persists.

How can I modify the autocommand to avoid this?

1
  • 1
    chain a $delete (or maybe 0delete, I forget which). It's the behavior of read – D. Ben Knoble Feb 8 at 21:52
3

:read inserts text from a given file. When you start with empty file, it already has one (virtual, empty) line.

So if you do :0read then the text is added after 0th line (that is, before the first and only line), and then the former line #1 gets shifted to the end of file.

You can't prevent it, only to remove it. Personally, I'd prefer :read filename | 1delete_ over :0read filename | $delete_, so the cursor finally goes to the first line, not to the last one.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.