DEV Community


Posted on

3 Little Known But Useful Vim Tips

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

Top comments (10)

primercuervo profile image
Nicolas Cuervo

I always enjoy some good vim tips!

I blame my memory because I already knew about the 'ctrl+o' one, but otherwise I wouldn't have this feeling of rediscovery.

I've followed the twitter account from MasteringVim for a long while and it's fantastic. Thanks a lot for your work!

jovica profile image

Thanks for the kind words Nicolas! :)

For the others, it's this account:

toyo_tomi profile image
Ctrl + i / Ctrl + o
Enter fullscreen mode Exit fullscreen mode

forward / backward

Give us more @jovica !

janacm profile image
janac meena

Was not expecting the title to be accurate!

maestromac profile image
Mac Siri

Interesting tips!

andytower_rus profile image
Andrey Alferov

I knew 1 and 2 tips, but tip #3 is surprising me.

alvarocaceresmu profile image
Álvaro Cáceres Muñoz

Amazing! Thanks for sharing

ondrejs profile image

Cool tips, thanks!

sksundram profile image
Shailesh Kumar

The third tip is dope!

gabgab2003 profile image

I knew the zip, I could have guessed the scp. But holy Lord the ctrl-o is a godsend