7 Habits of Being Effective
When I saw first 10 minutes of 7 Habits For Effective Text Editing 2.0, by Brian Moolenaar, I immediately realized it was the best way to spent 10 minutes in the last month. It struck me I was not aware of so basic features of vim! Sure I know a lot about it, but I didn’t know fundamental commands!
The rest of the talk was not as good so I recommend to see at least the beginning of it. Maybe you will like the rest as well. But if you don’t have time, here is what I found there:
Something we do the most often. This is why it is worth to get
more than familiar on this topic. Good start is to read vim’s documentation
on the subject:
The basic search skill is to be aware of
:set hlsearch and be able to
use it with a star command
*. The star and its derivatives (
allow to find the word you have near the cursor.
It works out of the box! Once you write a complex method name, vim is aware of it and next time vim may help you with autocompleting it. Just start typing a few letters of the workd you have written before, then press CTRL-N and vim does autocomplete - if you are lucky. If you are not - press the shortcut a couple of times until you hit the proper name.
As many others when I am stuck I reach for stackoverflow to find answers. And I usually do. Below are my findings.
Q: I want to see numbers of characters I have highlighted. My VIM does not do it out of the box.
A: But people say it already has such the capability and it is as simple as highlighting a block with v and typing g CTRL-g. It works great.
Vim by default searches for a text which spans multiple lines.
\s matches a white characters (space, tab). Adding an underscore
expands the match to include newline. The underscore adds a newline to any
I found interesting
/abc$ match only at the beginning
and the end for a line correspondingly. But
^$ loose it special meaning
anywhere else. In the pattern
/abc^def$xwy they are just ordinary characters.
However following patterns keep their special meaning anywhere:
\_^ matches begin of the line (zero width)
\_$ matches end of the line (zero width)
Zero width is little tricky with the above. For example:
/abcd\_$efghfinds nothing because the search is looking for
abcdis also at the end of the line (cannot be).
- A working example is
abcdat the end-of-line followed by any whitespace or newlines then
abcdfollowed by any whitespace or newlines then
efghwhich begins the line.
Replacing multiple lines by a few or a single one.
Read first an article on searching across multiple lines.