More silly Vim tips! In order to make your search case-insensitive use the \c modifier. In order to have vim display line numbers use :set nu. And speaking of the :set options, you can use :set nu! (with a trailing question-mark) to toggle the option between on and off, :set nu? to query its status, and :set nonu (with a leading "no") to set it off.
Happy vimming!
- Location:Home
- Music:Bond - Wintersun
I have several vim tips in the pipe, so I think I'll start with one. If you're editing commands in the ex-like Command Line Mode of vim (the one that's displayed after you press ":" in Normal Mode), you can use the Ctrl+R family of keybindings to insert registers and other text there. So for example, if you wish to search for a word, you can do yaw in the buffer, and then type :grep -r <CTRL+R>" ..
Since this pattern is so common, the vim developers already thought of it, and you can simply position the cursor on the word and type :grep -r <CTRL+R><CTRL+W> .. Ctrl+R;Ctrl+A searches for WORDS.
Note that Ctrl+R by default executes the pasted expression as a mini vim program. If you want to insert the literal string, use Ctrl+R;Ctrl+R. Better safe than sorry.
- Location:Home
- Mood:
energetic - Music:TPau - China in Your Hand
Third Vim tip in a row on this blog (must be a record for me) and this time a blast from the past. Well, at least something I learned a long time ago, but many people are not aware of.
By using the "f" command and then a character one can move to the next occurence of that character on the same line. So "ts" will move to the next occurence of the letter "s". "t" is the same except it moves to the character before that. "F" and "T" are for moving backwards. You can specify an optional count for jumping to the N'th occurence in the same line.
This for example is useful for quickly selecting tokens. If for example, you have a C-style string delimited by double-quotes, you can position your character to its start using the "f" command and then right (The right arrow key or "l"), and then select up to the end of the string using yt" , or alternatively replace it with something else using ct". Alternatively, one can select the string including the quotes, by positioning the cursor at the opening quote and typing yf".
For more information consult :help f.
- Location:Home
- Mood:
happy - Music:U2 - When Love comes to Town
