Show Menu
Cheatography

1st Mar 2023 part 4 Cheat Sheet (DRAFT) by

Working Progressssssssssss

This is a draft cheat sheet. It is a work in progress and is not finished yet.

gf or C-w (* indicates cursor position)

Pos*t.f­irst
app/mo­del­s/p­ost.rb
has_many :c*omments
app/mo­del­s/c­omm­ent.rb
link_to 'Home', :contr­oller => 'bl*og'
app/co­ntr­oll­ers­/bl­og_­con­tro­ller.rb
<%= render 'sh*ar­ed/­sid­ebar' %>
app/vi­ews­/sh­are­d/_­sid­eba­r.h­tml.erb
<%= styles­hee­t_l­ink_tag 'appl*­ica­tion' %>
app/as­set­s/s­tyl­esh­eet­s/a­ppl­ica­tio­n.css
class BlogCo­ntr­oller < Applic­a*t­ion­Con­troller
app/co­ntr­oll­ers­/ap­pli­cat­ion­_co­ntr­oll­er.rb
class Applic­ati­onC­ont­roller < Action­Con­t*r­oll­er:­:Base
.../ac­tio­n_c­ont­rol­ler­/ba­se.rb
fixtures :pos*ts
test/f­ixt­ure­s/p­ost­s.yml
layout :pri*nt
app/vi­ews­/la­you­ts/­pri­nt.h­tm­l.erb
<%= link_to "­New­", new_co­mme­*nt­_path %>
app/co­ntr­oll­ers­/co­mme­nts­_co­ntr­oll­er.rb (jumps to def new)
In the last example, the controller and action for the named route are determined by evaluating routes.rb as Ruby and doing some intros­­pe­c­tion. This means code from the applic­­ation is executed. Keep this in mind when navigating unfamiliar applic­­at­ions.
 

Plugins

(GH: any-ju­mp.vim)
:help any-ju­mp.vim
Normal mode: Jump to definition under cursor
nnoremap <le­ade­r>j :AnyJu­mp<­CR>
Visual mode: jump to selected text in visual mode
xnoremap <le­ade­r>j :AnyJu­mpV­isu­al<­CR>
From Modal view preview the definition/reference
p
 
(GH: vim-test)
:help test
Normal mode: In a test file runs all tests in the current file
nmap <si­len­t> <le­ade­r>t :TestF­ile­<CR>
Normal mode: Runs the whole test suite
nmap <si­len­t> <le­ade­r>T :TestS­uit­e<C­R>
 
(GH: vim-bu­ndle)
Normal mode:
nmap <si­len­t> <le­ade­r>b :Bundl­e<C­R>
Normal mode: will open the gem source code in a new tab
:Bundle open actionview
Normal mode: pen the source code in a split window instead of a new tab
:rightbelow Bundle open actionview
 
(GH: splitj­oin.vim)
:help splitjoin
Normal mode: to split a one-liner into multiple lines
gS
Normal mode: (with the cursor on the first line of a block) to join a block into a single­­-line statement.
gJ