OK, if you are doing some major hacking with vim as your toy IDE, here are some advanced things:
- Rewrapping text. There are a bunch of tricks here, the most important is to put in
.vimrc
the linesset tw=79 wm=2
which means wrap around line 79. If you need to rewrap then your friend isgq
with a movement. So for instance2gq
means rewrap two lines andgQ
means the same a sgq$
which means format from the current line to the end of the file. So the sequence1
G means go to the top and thegQ
will reformat everything. - Renaming a bunch of files at once. Say you want to rename every prefixed with
econ-
tofoo-
then this is easy with mac and graphical rename in find, but hard everywhere else. Herebrew install mvv
is your friend. It allow regex matching. so for instancemvv 'envo-*' 'foo-#1
means that you take the first string do a match and then the first pattern you replace in the second. Pretty nifty! - Renaming variables. This is a big problem if you are doing a big rename there is supposed to be a
gd
command that works against variables, but my version of vim just beeps at me 🙂 - The
%s
. I have for years done:g/foo/s//bar/gp
but it turns out there is something shorter which is:%s/foo/bar/gp
so you don’t have to repeat the global. nice.