Vim tips & tricks

From the Vim FAQ

Note: On Debian etc. with the vim-doc package installed, the FAQ can be found at /usr/share/doc/vim/FAQ.gz.

8.10. How do I delete a buffer without closing the window in which the buffer is displayed?

You can use the following command to open the next buffer and delete the current buffer.

:bnext | bdelete #

21.4. How do I insert the current date/time stamp into the file?

You can use the strftime() function to insert the current data/time stamp in a file. For example, you can use the following abbreviation:

iabbrev dts <C-R>=strftime("%y/%m/%d %H:%M")<CR>

With this abbreviation, when you type dts in insert mode, it will be expanded to the date/time stamp.

To delete the final newline in a file

Open it in binary mode, unset ‘endofline’, then save the file. This can be done from the command line in one go:

vim -b -c 'set noeol | wq' $file