TurnKey Linux Virtual Appliance Library

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.

You can get future posts delivered by email or good old-fashioned RSS.
TurnKey also has a presence on Google+, Twitter and Facebook.

Comments

Jeremy's picture

(Almost) makes me want to start using Vim!

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.

Have to say I've been in the

Have to say I've been in the same boat as you. While I've exclusively used nano for everything to writing code and editing config files, I've recently tried out Vi/Vim to see what the fuss is all about. Using resources like vim-tutor and a couple of books, you quickly come to realise that there's much more built into the editor than what you think.

It's just a process of using the editor to the point where you feel comfortable with the commands.

It's an Investment

Learning Vim is an investment of time. It is one of the few pieces of software that is not designed for novice computer users. It does not hold your hand. Although compared to other versions of vi, it provides a wealth of assistance.

It is a tool that cannot be completely learned. And that is a good thing, because that also means it will not limit you later when you know it well.

I suggest you spend a short time daily practicing in Vim, beginning with the included tutorial, then moving on to the built-in user manual. It reads like a book, because it is based on one.

You will gain benefits with persistence. It is like the rewards of learning how to ride a bicycle or drive a car as compared to walking. It takes time, but it is worth it.

:wq

Liraz Siri's picture

Vim is much more powerful than Nano

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's picture

I'd be interested to hear more

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

I use vim-full

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

Vim-tiny

The difference is that the default version is a stripped-down one that contains limited features.

:wq

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)