Vim has recently become my editor of choice for code editing, especially for Ruby. I spent half of my time in the Tmux/Vim environment, and the other half is in Xcode.
In this blog post, I am going to share my Rails development workflow, the plugins that I use, and some general useful Vim tips that hopefully, everyone can make use of.
First some key re-mapping
I find the
Capslock key useless, and the
Control key is kind of hard to reach. So I remap my Caplocks to Control, home row key FTW!
One extra side effects, you can’t even be ANGRY with anyone anymore. Less anger, less carpal tunnel syndrome.
Fuzzy file navigation with
The Silver Searcher is a code searching tool just like
ack, just “magnitude faster”. And it takes your
.gitignore into account. Using it as the default grepping engine of Vim make your search and file navigating operations executed a thousand time faster.
Install it using brew
brew install the_silver_searcher
Adding these configurations to your
.vimrc to set
ag as the default grepping tool for
" Make CTRL-P use ag for listing the files. Way faster if executable('ag') let g:ctrlp_user_command = 'ag %s -l --hidden --nocolor -g ""' let g:ctrlp_use_caching = 0 endif
Now you can navigate files using fuzzy searching with the speed of light.
Rails Integration with
vim-rails by the legend
tpope is the go to plugin for Rails development. It provides functionalities like syntax highlighting, resources navigation, refactoring, running rake and rails commands.
A quick demo before digging in:
I mostly use
fuzzy searching for navigating between files, but
vim-rails does provide another nice way to work with the resources.
For instance, to open the
Commit model, you’d do:
and to open its controller
You can also do
migration and some others. It’s also context-aware, so if your cursor is at the
Message#show and you typed
Eview, it will open
Rails Commands Integration
:Server! will run a Rails server in a new window using
Tmux. You can also do all of the Rails’ commands inside vim, for example:
:Rails g model User email password_digest
Rake commands work as well:
:Rake db:create db:migrate
Jump to Definition with
vim-rails extends the “Go To File” behavior by allowing jumping to the corresponding file under the cursor.
Concern and Partial Extraction
:Rextract command for concern and partial extraction. If you’re editing a model, the result will be concern extraction. For example, while editing
User model, you can go into visual mode, highlight the methods and run:
Using line number also works:
The extracted methods will be put in a new file in
app/models/concerns and your model will include this file.
The same goes for partials.
HTML Editting with Emmet
emmet-vim with Vundle by adding this to your
Doing HTML is boring, and Emmet allows me to do ultra-fast HTML typing using CSS-like abbreviation.
emmet language and then
CTRL + Y + , will translate it to the HTML.
This is not the entire configurations/plugins that I use for Vim. My complete dotfiles can be found on my Github repo. I hope you found this article useful and go Vim-on.