Vim Tips Wiki
Advertisement
  • Please discuss proposals for new Featured Tips on the talk page.
  • The home page highlights the current featured tip.
  • Add comments on the current featured tip to the comments section on the current tip page.

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.

Previously featured tips

This is an archive of the Featured tip section on the home page. We won't feature these tips again – however, they remain great tips!

October 2009

Perhaps you are editing several files in different directories, and now you want to open another file in the same directory as your current file. Problem: the file is deep in the directory tree, and navigating to find the file would be frustrating.

Try our command line abbreviation to invoke expand('%:p:h') so you can easily insert the full path of the directory of the current file into the command line. Then you can press Enter to browse the directory, or use Tab for file name completion.

Our featured tip has the details, as well as an alternative to set the working directory to the current file.

September 2009

Have you ever used Caps Lock in insert mode, then switched back to normal mode to issue a few commands, completely forgetting that Caps Lock is still on? If entering <Esc>JJJJUUU nonsense commands sounds familiar, you need to try our featured tip.

By implementing language maps (or by using a keymap), you can take advantage of Vim's ability to translate characters after pressing Ctrl-^ while in insert mode. The "Caps Lock" provided by this technique applies only to entered text, not to normal-mode commands.

August 2009

A mark (aka bookmark) can be used to record your current position, so you can return to it later. You probably know that ma sets mark a, and that later you can type `a to jump to the a location. But what about file marks, and what about special marks?

There are lots of questions to ask about marks, and our featured tip has all the answers.

July 2009

Syntax highlighting helps show the structure of a program, and usually all you need is :syntax on – the rest is automatic.

However, what if you have some C code in a text file, or some SQL code in a C file? With a little work, you can apply different syntax highlighting rules to different regions of a file, so your C code looks like C, your text looks like text, and your SQL code looks like SQL.

Our featured tip has the details. Use it to create syntax regions in plaintext, tweak existing syntax rules, or even as a guide when developing a new syntax plugin!

June 2009

After another editing frenzy, you might wonder exactly where you made changes. Of course (if you have an old copy of the file) you can use vimdiff to see exactly what changes have occurred. Even with no original file, you can see where each change occurred with the :changes command.

Even more useful is the fact that you can return to locations where changes occurred, even those from previous editing sessions.

May 2009

It's time to go back to basics and check how line ranges work. You may know that :s/old/new/g substitutes in the current line, and :%s/old/new/g substitutes in the whole file, but it's worth learning more!

Ranges like .+1,$ (all lines after current line) and '<,'> (last visually selected lines) are very useful.

April 2009

What can you do with all those search hits? You can simply list them with :g/pattern/, or you can make a clickable list with :vimgrep /pattern/ %.

Our featured tip shows these, and has some techniques to copy the search results to the clipboard.

March 2009

You can search by typing / followed by the search pattern, or by pressing * to search for the current word.

With our featured tip, you can also select some text, then press * to search for the next occurrence of the text. The selection can be a few characters, or a few lines. Whitespace in the selection matches any whitespace when searching (searches will find words separated by any combination of spaces, tabs and line breaks).

February 2009

Do you ever do some edits in one place, knowing that you're going to have to repeat those edits in several other places? Naturally Vim allows complex repeats by recording keys into a register. :help complex-repeat

Now you can try the magic of a recursive repeat to automatically apply the commands you have recorded to many lines at a time. By following our technique for recording to a register, and finishing by invoking the register, you can apply a macro to every line in a file with no counts necessary!

January 2009

Sometimes it's useful to highlight several patterns in different colors. For example, you may be studying how three variables are used, and you would like to see each displayed with a different background color.

It's easy to highlight multiple words using our amazing highlighting script. You can press a key to highlight visually-selected text, or the current word, or you can enter a command to highlight any pattern. Searching for the next highlight is also easy.

You can have different sets of highlighting in different windows, or can copy highlighting from one window to another. If you really like your current highlight patterns, you can save them for use in the future.

Previous years

Comments

Advertisement