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
set tw=79 wm=2which means wrap around line 79. If you need to rewrap then your friend is
gqwith a movement. So for instance
2gqmeans rewrap two lines and
gQmeans the same a s
gq$which means format from the current line to the end of the file. So the sequence
1G means go to the top and the
gQwill reformat everything.
- Renaming a bunch of files at once. Say you want to rename every prefixed with
foo-then this is easy with mac and graphical rename in find, but hard everywhere else. Here
brew install mvvis your friend. It allow regex matching. so for instance
mvv 'envo-*' 'foo-#1means 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
gdcommand that works against variables, but my version of vim just beeps at me 🙂
%s. I have for years done
:g/foo/s//bar/gpbut it turns out there is something shorter which is
:%s/foo/bar/gpso you don’t have to repeat the global. nice.