How YOU can work with vim

I recently saw a great podcast on reddit titled  “How I work:  Rails with Vim” (http://blip.tv/file/1372096).  It showed how the author had made shortcuts to use vim more effectively.  Specifically, how to do a find from the current directory, get a list of files, and jump to any of those files.  TextMate fans will recognize this as a project file list with the ability to jump to that file.  Also the demo had a vim plugin that would do some replacements.

While it’s neat to see what he had done, the screen cast didn’t say _how_ he had done it.  It was almost like he had this cool funcitonality, which I was excitited to start using, but there were no instructions on how _I_ could use it.

So, I spent a little time figuring it out.  Here’s what I came up with:

VIM-

This is an alias to get a list of files in the current directory and below, and load that into vim.  Here’s my version

alias vim-=”find . -name .svn -prune -o -type f -print |vim -R -”
This finds all files (not directories “-type f”) under the current directory and prunes the .svn directories.  It then reads this list into vim from standard out.  It reads the file list as read-only “-R” so that you don’t have to worry about saving it or doing q! to get out of the editor

NOTE:  The find command may take some time with large code bases.

Next, change your vimrc file so that control T opens a new window with the file under the cursor
map <Ctrl-T> :new <cfile><Enter>
Apparently, <cfile> is the file name under the cursor.  You can use vnew instead of new to get a vertical window to the right.
Also, you can put this line in the vimrc to make the window open below the current window instead of above.
set splitbelow

Grill

The author also had a script that does a grep that is recursive, case insensitive, and lists the matching file names and puts that into a vim editor.  Here is my version.

I don’t know enough about aliases in bash to take arguments, so I just wrote a script.  My ~/bin directory is in my path, so I created a script called grill with this line
grep -ril $1 . |grep -v “.svn”  |vim -R -

Now “grill user” will open a vim window with a list of files that have the word user in them, and control-T will jump into that file.

Replacements

The last feature of this demo was the ability to input a shortcut and get several more keystrokes.  For this I use AutoHotKey in windows.  It is a great little utility that allows you to type “/ult/” and a tab, and it erases /utl/ and inserts /user/local/tools/tomcat*/apache*/, or whatever else you want.  It’s great for naviaging long paths or abbreviating frequent logins.  Now J@H maps to joe@hotmail.com<tab> password <enter> and it pops up on the screen as if you had done it yourself.  It’s very impressive in demos, and it works in any window, not just vim.

6 Responses to “How YOU can work with vim”

  1. Cliff says:

    Here is the screen cast creators github repo with all his config files just for reference.

    http://github.com/jpalardy/etc_config/tree/master

  2. CounterTT-480…

    гляньте, какой сайт с софтом http://softing.do.am/ , много полезного…

  3. aram118-964 says:

    aram118-964…

    Очень хороший сайт по путешествям в Африке http://africtravel.info/, найдете там много полезного видео

  4. Frankie says:

    Hello! Please e-mail me your contacts. I have a question jack@infansport.ru” rel=”nofollow”>……

    Thank you!…

  5. KURT says:

    Pillspot.org. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices(up to 40% off average US price).PillSpot.org. Herbal-supplements@buy.online” rel=”nofollow”>.< /a …

    Categories: Antidiabetic.Blood Pressure/Heart.Pain Relief.Anti-allergic/Asthma.Womens Health.Stomach.Mens Health.Anxiety/Sleep Aid.Skin Care.Antibiotics.Stop SmokingWeight Loss.Antiviral.General Health.Eye Care.Cholesterol.Mental Health/Epilepsy.V…

  6. JULIAN says:

    PillSpot.org. Canadian Health&Care.Special Internet Prices.No prescription online pharmacy.Pillspot.org. Vitamins@buy.online” rel=”nofollow”>.…

    Categories: Antidepressants.Stomach.Mens Health.Womens Health.Antiviral.Weight Loss.Stop SmokingAnti-allergic/Asthma.Pain Relief.Mental HealthEye Care.Antidiabetic.Skin Care.Blood Pressure/Heart.Vitamins/Herbal Supplements.Antibiotics.Anxiety/Slee…

Leave a Reply