Skip to content

Instantly share code, notes, and snippets.

@andreashappe
Created March 13, 2012 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreashappe/2025672 to your computer and use it in GitHub Desktop.
Save andreashappe/2025672 to your computer and use it in GitHub Desktop.
Coding Rails apps with VIM

VIM and Ruby on Rails

Just use this with GVim or MacVim.

Installed plugins

NERDtree File-browser sidebar/drawer
rails.vim add lots of rail’s specific helpers
dbext.vim allow direct database interaction from within vim
syntastic.vim do automatic syntax checking on file-save
vcs integrate with version management systems like git, svn
snipMate text mate like snippet system, also see snippets for some example snippets
delimitMate autocomplete braces
conque_term integrate interactive terminals into vim
Oh my ZSH! ain’t a vim plugin, but a good shell is an important first step

Helpful shortcuts

  • Don’t forget the visual mode (v)
  • Don’t forget the Visual Block mode strg+v to delete blocks of code
Command Description
:Rextract move selected view code into a partial and include the partial at this place
:Rgenerate call the different generators, this can be very slow!
:R, :A jump to related files
gf goto file that contains the definition of the symbol under the cursor
:ConqueTerm rails c Create a new vim buffer with an interactive rails console in it

DB-Interaction stuffs

Command Description
:DBDescribeTable “tablename” describes table
:DBSelectFromTable “tablename” formated “select * from table”

Default .vimrv configuration file

set digraph	        " support for languages that I acutally cannot input on my keyboard
    set nocompatible        " I don't care about vi-backwards compatiblity
    
    color scheme slate      " I use this colorscheme on mac, maybe I should add one
  	  			                " separation to use another one on linux (also I should
  		  		                " the used fonts somewhere)
    
    set expandtab			      " who likes tabs anyways?
    set tabstop=2			      " two spaces for a tab
    set cindent             " automatically indent new lines

    " search stuff
    set hlsearch			      " highlight all found search results
    set ignorecase			    " searches should be case-insensitive
    set smartcase			      " except when the search contains upper characters

    " GUI options
    set guioptions-=T		    " Don't need no toolbar
    set scrolloff=5			    " always show at least 5 after the scroll line

    " miniBufExplorer related stuff
    let g:miniBufExplMapWindowNavArrows = 1     " Allow usage of strg+arrows for split navigation
    let g:miniBufExplMapWindowNavVim = 1
    let g:miniBufExplMapCTabSwitchBufs = 1
    let g:miniBufExplUseSingleClick = 1         " React on single click within buffer explorer

    " font stuff
    set guifont=Monaco:h12

    " ruby debug
    let g:ruby_debugger_progname = 'mvim'


    autocmd FileType cucumber compiler cucumber | setl makeprg=cucumber\ \"%:p\"
    autocmd FileType ruby
       \ if expand('%') =~# '_test\.rb$' |
       \   compiler rubyunit | setl makeprg=testrb\ \"%:p\" |
       \ elseif expand('%') =~# '_spec\.rb$' |
       \   compiler rspec | setl makeprg=rspec\ \"%:p\" |
       \ else |
       \   compiler ruby | setl makeprg=ruby\ -wc\ \"%:p\" |
       \ endif
    autocmd User Bundler
       \ if &makeprg !~ 'bundle' | setl makeprg^=bundle\ exec\  | endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment