ChrisMar035 Adventures in Web Programming

25Jun/100

Trick out your Vim

Today, I'm going to add some plugins and scripts to make better use of Vim. I have not started this project and I will be updating this post throughout the day with my finds and experiences.

I generally use Vim to code web applications. My site at work run on PHP and at home I'm working with Ruby on Rails. So, I'll be looking for something to specifically help with that, but who knows what I'll find.

.vimrc

.vimrc is a file in your home directory. It contains a script which runs each time you start Vim. You can setup your configurations, preferences and plugins in here. The .vimrc is the starting point for fine tuning your Vim to exactly how you want it. If you are a beginner, I would recommend finding some more advanced users' .vimrc's and, at least, check them out, if not start using them for yourself. I started with Todd Werth's .vimrc file. He keeps his in a separate folder and uses a symlink to put them in his home folder. I strongly recommend this as well. You can automatically sync your .vimrc (or any other files) across computers with Dropbox. See how in my post on how to Use Dropbox to keep your preferences across Computers.

Here are some useful lines to start you out:

" Set tabs to 2 sapces
set softtabstop=2
set shiftwidth=2
set tabstop=2
set expandtab

" Move your backup and .swp files out of the directory of the file (Helpful to keep from adding them to a repo)
set backup
set backupdir=~/backup
set dir=~/swap

" Highlight the current line
set cursorline

" Keyboard shortcuts (Mappings)
imap kj " Use kj to exit Insert Mode (instead of Escape)
imap hh => " Hit hh to insert a "rocket" in insert mode

" Wildmenu - show a tab completion matches list
set wildmenu
set wildmode=list:longest,full

Again, search the google machine and checkout github for more samples and if you find anything cool, let me know in the comments.

Plugins

Autoclose

This first plugin automatically closes quotes, parenthesis, brackets, etc. for you. If you type a single quote, another single quote is added after the cursor. You can type an end paren to move the cursor after the autoclosed characters. This is helpful after nested autocloses. For instance, in PHP, I often find myself passing array values to a function:
run_trail($locmotives['lionel|'])
This pipe in the above example is the cursor position after the last l in lionel. I can simply hit ) and the cursor will jump out of the single quote, square bracket AND end paren. Simple.

Autoclose is developed by Karl Guertin and can be found at http://www.vim.org/scripts/script.php?script_id=1849

See ya Soon!

Posted by Chris M

Filed under: HowTo Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

 

Trackbacks are disabled.