3 Little Known But Useful Vim Tips

jovica - Nov 26 '18 - - Dev Community

I'll show you three tips which can be incredibly useful, yet, they are very little known.


Tip #1 - Open/edit/save archives

Running a command like:

$ vim archive.tar.gz

will open the archive.tar.gz, and list the contents of the archive. From there, you can open, edit and save changes in these files, without the need to extract them first.

How cool is that? :)

Supported archives: tar.gz, tgz, zip, jar, etc.

Tip #2 - Edit files remotely

Vim has the ability to edit files remotely, over the network. This feature comes with the netrw plugin. To achieve this, netrw uses the SSH protocol, and manages remote files via the scp command.

Here's how to do it:

vim scp://user@myserver[:port]//path/to/file.txt

Note the double / for the directory on the remote host, which is needed to correctly resolve the absolute path. [:port] is optional.

So with the command above you can open a file located on a remote host for editing.

What actually happens in the background is that Vim uses scp to download the requested file from a remote machine to a local /tmp directory, and then opens it for editing.

When you save your changes to the file, the changes are first applied to a local copy in /tmp directory. After that, the file is uploaded via scp to the remote host.

Tip #3 - Magic

Did you know that you can open the last edited file on the machine with cursor on the latest location?

Just start Vim, hit Ctrl+o+o - and there you go.

Keep hitting o and see what happens ;)


Now, if you wanna discover more Vim tips you've never heard of, take a look at my book Mastering Vim Quickly: From WTF to OMG in no time

. . . . .
Terabox Video Player