DEV Community

Scott Watermasysk
Scott Watermasysk

Posted on • Originally published at scottw.com on

2 1

CtrlP Shortcuts for Rails

I liked how @garybernhardt had specific rails shortcuts in vim for his Selecta script. As a fan of CtrlP + Ag, I did not want to switch, so I came up with the following which works well.

map <leader>gv :CtrlP app/views<cr>
map <leader>ga :CtrlP app/assets<cr>
map <leader>gc :CtrlP app/controllers<cr>
map <leader>gw :CtrlP app/workers<cr>
map <leader>gm :CtrlP app/models<cr>
map <leader>gl :CtrlP lib<cr>
map <leader>gs :CtrlP spec<cr>

The pattern should be obvious. One mistake I initially made was using:

map <leader>gl :CtrlP<cr>lib/

This ends up just entering lib/ for you in the search and does not explicitly limit the search to the lib directory. This is noticeably slower since each keystroke is a wasted search. Also, with a small directory name like lib, it is easy to have invalid fuzzy matches. The CtrlP + directory and then enter keeps the search focused on the specified directory only.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (2)

Collapse
 
juanvqz profile image
Juan Vasquez

Hi! Thanks for write.

I use vim-rails.

You should try them.

Regards!

Collapse
 
scottw profile image
Scott Watermasysk

I already use it. I just find the ctrlp to be more natural, especially since it can be used outside of Rails.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay