black and white business career close up

Various Vim and Bash tricks

0

OK, if you are doing some major hacking with vim as your toy IDE, here are some advanced things:

  1. Rewrapping text. There are a bunch of tricks here, the most important is to put in .vimrc the lines set tw=79 wm=2 which means wrap around line 79. If you need to rewrap then your friend is gq with a movement. So for instance 2gq means rewrap two lines and gQ means the same a sgq$ which means format from the current line to the end of the file. So the sequence 1G means go to the top and the gQ will reformat everything.
  2. Renaming a bunch of files at once. Say you want to rename every prefixed with econ- to foo- then this is easy with mac and graphical rename in find, but hard everywhere else. Here brew install mvv is your friend. It allow regex matching. so for instance mvv '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!
  3. 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 🙂
  4. 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.

Related Posts

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© All Right Reserved