Blog Tags: 

Vim file exploration tips

Find filename patterns

Using Vim's built-in file explorer, it's possible to find specific filenames by pattern. For example:

# :Ex is short for :Explore

# search all subdirectories
:Ex */Makefile
:Ex */*.c

# search recursively
:Ex **/Makefile
:Ex **/*.c
:Ex **/*tpl*

This will take you straight to the first match. If you want the next match after that:

<Shift-DownArrow>

And back:

<Shift-UpArrow>

Bookmarking locations in the filesystem

When I use sshfs to mount a development VM's filesystem I sometimes find it tedious to type in the same long sub-directory paths over and over again. I've been setting up symbolic links to make my life somewhat easier but that gets tedious quickly too.

So I searched Vim's documentation a bit and it turns out that Vim's file explorer allows you to bookmark locations in the filesystem like this:

{cnt}mb # make bookmark
{cnt}gb # goto bookmark
q # list bookmarks

For example:

1mb # set the first bookmark
1gb # go to the first bookmark

Quite handy.

Comments

Jeremy Davis's picture

I did try Vim when I first started testing out Linux but it seemed so counter-intuative to me that it was a pain. I remember reading that it is actually better (for some reason why which I don't recall anymore but seemed to make some sense) but that was irrelevant to me at the time.

So at the end of the day familarity won over and I've been a happy nano user ever since. I find nano to be pretty much a Linux commandline version of MS Notepad!

After reading this post (and a couple of other bits here and there) I'm thinking I probably should have another look at Vim sometime soon. Part of my problem is though that although I use Linux exclusively at home, at work I use a combo of Linux and Win. It sometimes feels like anything new or too different causes (at least short term) productivity losses.

Liraz Siri's picture

Your experience with Vim is typical. Most users who try it have only experienced modeless editors before. A modeless editor typically means an editor which is always in edit/insert mode. Vim on the other hand, has modes, which you switch between to get stuff done. It can be a bit alien at first, and there is a learning curve to negotiate but once you get past it many people experience vast improvements to their text editing productivity. In practice this allows you to perform complex text operations much faster than you would in a modeless editior without having to use the mouse. This might not seem like much of a big deal if you don't do a lot of text editing, but if you do (e.g., writer/programmer) it might just be worth the extra initial effort. These I try do as much of my text editing as possible inside Vim. On Linux, there's software you can use to invoke it inside your browser, in your mail client, etc. When I switched from Emacs to Vim a few years ago I wrote about my experience to Alon and I'm thinking about publishing some of that on the blog (after some editing).
Jeremy Davis's picture

It all sounds very interesting and I'd love to hear more about it. I'll definately have to have a bit more of a look and play with Vim and see if I can get my head around it.

Chris Musty's picture

The default vi program has some strange behaviour on Ubuntu and Debian from my experience; to fix this, I install vim-full. I have never figured out the difference. Would anyone know?

Chris Musty

Director

Specialised Technologies

Pages

Add new comment