The Vim text editor has a set of selection commands for selecting various parts of the text while being inside them. Some of them are very useful - here are some examples:
- To indent the inside of a block (after a copy and paste for example) use >i} or <i}. It beats writing >% and then doing <<%<<
- To change a string use ci".
- To delete a block use da}.
- To copy a paragraph use yap.
Etc. Oh and try typing :he holy-grail in Vim (this tip courtesy of LeoNerd from Freenode who found it).
- Location:Home
- Mood:accomplished
- Music:Yehud Poliker - Jacob's Ladder
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
In Vim lowercase marks are specific to each file, while uppercase marks are global. Thus, one can type mA, mB, mC etc. to set such a mark in a certain position in a fileand then use `A or 'A to jump to it even from a different file. This is useful to keep several bookmarks in several files and jump from one to another.
Since one can use ` and ' as a motion command, I'm not sure how a jump to an uppercase mark from a different file is useful as an argument to a motion-accepting command such as y or d. However uppercase marks are still useful for what I demonstrated.
- Location:Home
- Mood:accomplished
- Music:Solid Harmonie - I Want you to Want me
