Skip to content

Instantly share code, notes, and snippets.

@rapsad
Last active August 29, 2015 14:21
Show Gist options
  • Save rapsad/fa77f6005ab7566a58ae to your computer and use it in GitHub Desktop.
Save rapsad/fa77f6005ab7566a58ae to your computer and use it in GitHub Desktop.
Vim gist
Ctrl+X Ctrl+O (in insert mode) -> Ruby Complemention

New empty file:

:new

Moving between tabs:

gt (or :tabn) to go to next tab
gT (or :tabp or :tabN) to go to previous tab
#gt (or :tabn #) to go to #th tab
:tabr to go to first tab
:tabl to go to last tab
:tabm to move the current tab to the last position
:tabm # to move the current tab to the #th position

Opening new files:

:tabe <filepath>
:new <filepath>
:edit <filepath>

Once CtrlP is open:

Press to purge the cache for the current directory to get new files, remove deleted files and apply new ignore options. Press and to cycle between modes. Press to switch to filename only search instead of full path. Press to switch to regexp mode. Use , or the arrow keys to navigate the result list. Use or , to open the selected entry in a new tab or in a new split. Use , to select the next/previous string in the prompt's history. Use to create a new file and its parent directories.

rails.vim

gf - go to file on specific name

Open Files in Split Windows

If you want to open a file in a split window, just type :RV, instead of :R, and the item you wish to open (model, view, controller, etc.) This opens the file in a vertical split. If you want to a horizontal split, use :RS

Open Files in New Tabs

You can open any Rails file in a new window just use :RT instead of :R.

Calling :2,4Rextract greeter will yield the following results:

# New buffer in vertical split: app/models/concerns/greeter.rb
module Greeter
  extend ActiveSupport::Concern

  def greet
    "Hello World"
  end
end

# Buffer: app/models/foobar.rb
class Foobar
  include Greeter
end

It is also extracting view(s) to partials

Tcomment

As operator (the prefix can be customized via |g:tcommentMapLeaderOp1| and |g:tcommentMapLeaderOp2|):

gc{motion}   :: Toggle comments (for small comments within one line 
                the &filetype_inline style will be used, if 
                defined)
gc<Count>c{motion} :: Toggle comment text with count argument 
                (see |tcomment#Comment()|)
gcc          :: Toggle comment for the current line

Explicit commenting/uncommenting:

g<{motion}   :: Uncomment region
g<c          :: Uncomment the current line
g<b          :: Uncomment the current region as block

g>{motion}   :: Comment region
g>c          :: Comment the current line
g>b          :: Comment the current region as block

In visual mode:

gc           :: Toggle comments
g>           :: Comment selected text

http://vimawesome.com/

Vim supertab

In insert mode you can do '.' for complemention.

Create dictionary:

:!mkdir -p spec/models
:w spec/models/blog_spec.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment