Vim Tips Wiki
Register
Advertisement

Please discuss proposals for new Featured Tips on the talk page. Comments on the current featured tip can be added below (be bold!), or can be added to the comments section at the end.


Now THAT's a Good Tip!

While most of the tips on this wiki are very helpful, every now and then, you'll stumble on a tip that shines above all the rest. Such a tip is a tip that changes the way you do a basic task, a tip that you try immediately and then use all the time, a tip that makes Vim integrate SO much better with your setup, or a tip that you just wish somebody gave to you when you started using Vim. We here on the Vim Tips Wiki recognize this, and therefore will -- about once a month -- feature a new tip that we feel is among the best of the best. So keep an eye on this page for life-altering (or at least mildly interesting) tips to add to your repertoire.

VimTip1285

This month's feature

The featured tip this time around is tip 1285 Replace a builtin command using cabbrev.

This tip was first nominated by fritzophrenic. Thanks for finding this great tip!

What's it about?

Creating an abbreviation is easy, but in Vim there's always more to learn! Check out this tip for how to make sure that command abbreviations are only expanded for : commands (not searches), and only for the first word in the command.

The tip also shows how to effectively replace a built-in command with a user-defined command.

See tip 1285 Replace a builtin command using cabbrev for details.

Previously featured tips

This is an archive of the Featured tip section on the Main Page (started in February 2008). We won't feature these tips again – however, they remain great tips!

April 2008

Many text editors launch new files in tabs, rather than showing a separate window for each file. Here's how to make Vim behave that way under Microsoft Windows.

At command prompt, use ftype to define the open command to run gvim with the --remote-tab-silent option. Use assoc to define which file extensions will be associated with the ftype open command. You can specify the --servername option so files with one type open in one instance of Vim, while files of another type open in another. See tip 1440 Launch files in new tabs under Windows for details.

March 2008

We know how to use /pattern to search the current file for the regular expression pattern.

You can also use a command like :vimgrep pattern *.txt to search all .txt files in the current directory for pattern, or :vimgrep pattern **/*.txt to search in the current directory and all its subdirectories. Using forward slashes for the file path works on Unix-based and Windows systems.

Would you like to press a key to search for the current word in all files in and under the current directory? See tip 1543 Find in files within Vim for details.

February 2008

Visual selection is useful for operating on a selected area: v for characters, V for lines, Ctrl-V (Ctrl-Q on Windows) for a block. You can extend the selection with normal commands such as j to move down, or w to move by a word, or / to search. Marks are automatically defined that specify the start and end of the visual selection.

It's easy to search and replace within a visual selection – just type the normal :s/old/new/g command while in visual mode.

You can also search the area that was visually selected – press Esc to exit visual mode, and start the search with /\%V rather than /. See tip 438 Search and replace in a visual selection for details.

Comments

I hadn't thought about putting summaries in the "Previously featured tips" section, but it's probably a good idea for now. However, once we've gotten a big enough list, I think we need to just provide links to most of them. I'd say a good goal would be to have a summary for the first 2 archived tips, and just a link to the rest.


Let's wait and see what it looks like when (if??) we get another couple of months done. Frankly, I'm rather pleased with what I wrote for February and March, and I have a feeling that it would be quite useful for a reader to peruse a list of the descriptions. If it keeps going, there could be a subpage with an archive of each year if there is too much on this page. --JohnBeckett 10:42, 25 March 2008 (UTC)



Advertisement