What are the dark corners of Vim your mom never told you about?

There are a plethora of questions where people talk about common tricks, notably "Vim+ctags tips and tricks".

However, I don't refer to commonly used shortcuts that someone new to Vim would find cool. I am talking about a seasoned Unix user (be they a developer, administrator, both, etc.), who thinks they know something 99% of us never heard or dreamed about. Something that not only makes their work easier, but also is COOL and hackish . After all, Vim resides in the most dark-corner-rich OS in the world, thus it should have intricacies that only a few privileged know about and want to share with us.


Might not be one that 99% of Vim users don't know about, but it's something I use daily and that any Linux+Vim poweruser must know.

Basic command, yet extremely useful.

:w !sudo tee %

I often forget to sudo before editing a file I don't have write permissions on. When I come to save that file and get a permission error, I just issue that vim command in order to save the file without the need to save it to a temp file and then copy it back again.

You obviously have to be on a system with sudo installed and have sudo rights.


Something I just discovered recently that I thought was very cool:

:earlier 15m

Reverts the document back to how it was 15 minutes ago. Can take various arguments for the amount of time you want to roll back, and is dependent on undolevels. Can be reversed with the opposite command :later


:! [command] :! [command] executes an external command while you're in Vim.

But add a dot after the colon, :.! [command] :.! [command] , and it'll dump the output of the command into your current window. That's : . ! : . !

For example:

:.! ls

I use this a lot for things like adding the current date into a document I'm typing:

:.! date
链接地址: http://www.djcxy.com/p/1374.html

上一篇: Vim最有效的捷径是什么?

下一篇: 你母亲从未告诉过你的Vim的黑暗角落是什么?