Skip to content

Instantly share code, notes, and snippets.

@cipherself
Created July 21, 2014 08:31
Show Gist options
  • Save cipherself/4a2c810c86dfd459cd76 to your computer and use it in GitHub Desktop.
Save cipherself/4a2c810c86dfd459cd76 to your computer and use it in GitHub Desktop.
Cheatsheet of my commonly used vim plugins

CtrlP

Basic Usage

  • Run :CtrlP or :CtrlP [starting-directory] to invoke CtrlP in find file mode.
  • Run :CtrlPBuffer or :CtrlPMRU to invoke CtrlP in find buffer or find MRU file mode.
  • Run :CtrlPMixed to search in Files, Buffers and MRU files at the same time.

Check :help ctrlp-commands and :help ctrlp-extensions for other commands.

Once CtrlP is open:
  • Press <F5> to purge the cache for the current directory to get new files, remove deleted files and apply new ignore options.
  • Press <c-f> and <c-b> to cycle between modes.
  • Press <c-d> to switch to filename only search instead of full path.
  • Press <c-r> to switch to regexp mode.
  • Use <c-j>, <c-k> or the arrow keys to navigate the result list.
  • Use <c-t> or <c-v>, <c-x> to open the selected entry in a new tab or in a new split.
  • Use <c-n>, <c-p> to select the next/previous string in the prompt's history.
  • Use <c-y> to create a new file and its parent directories.
  • Use <c-z> to mark/unmark multiple files and <c-o> to open them.

Run :help ctrlp-mappings or submit ? in CtrlP for more mapping help.

  • Submit two or more dots .. to go up the directory tree by one or multiple levels.
  • End the input string with a colon : followed by a command to execute it on the opening file(s):
    Use :25 to jump to line 25.
    Use :diffthis when opening multiple files to run :diffthis on the first 4 files.

Jedi-vim

Leader is \
  • Completion <C-Space>
  • Goto assignments <leader>g (typical goto function)
  • Goto definitions <leader>d (follow identifier as far as possible, includes imports and statements)
  • Show Documentation/Pydoc K (shows a popup with assignments)
  • Renaming <leader>r
  • Usages <leader>n (shows all the usages of a name)
  • Open module, e.g. :Pyimport os (opens the os module)

NERDTree

  • o.......Open files, directories and bookmarks....................NERDTree-o
  • go......Open selected file, but leave cursor in the NERDTree.....NERDTree-go
  • t.......Open selected node/bookmark in a new tab.................NERDTree-t
  • T.......Same as 't' but keep the focus on the current tab........NERDTree-T
  • i.......Open selected file in a split window.....................NERDTree-i
  • gi......Same as i, but leave the cursor on the NERDTree..........NERDTree-gi
  • s.......Open selected file in a new vsplit.......................NERDTree-s
  • gs......Same as s, but leave the cursor on the NERDTree..........NERDTree-gs
  • O.......Recursively open the selected directory..................NERDTree-O
  • x.......Close the current nodes parent...........................NERDTree-x
  • X.......Recursively close all children of the current node.......NERDTree-X
  • e.......Edit the current dir.....................................NERDTree-e
  • <CR>...............same as NERDTree-o.
  • double-click.......same as the NERDTree-o map.
  • middle-click.......same as NERDTree-i for files, same as
  •                `NERDTree-e` for dirs.
    
  • D.......Delete the current bookmark .............................NERDTree-D
  • P.......Jump to the root node....................................NERDTree-P
  • p.......Jump to current nodes parent.............................NERDTree-p
  • K.......Jump up inside directories at the current tree depth.....NERDTree-K
  • J.......Jump down inside directories at the current tree depth...NERDTree-J
  • <C-J>...Jump down to the next sibling of the current directory...NERDTree-C-J
  • <C-K>...Jump up to the previous sibling of the current directory.NERDTree-C-K
  • C.......Change the tree root to the selected dir.................NERDTree-C
  • u.......Move the tree root up one directory......................NERDTree-u
  • U.......Same as 'u' except the old root node is left open........NERDTree-U
  • r.......Recursively refresh the current directory................NERDTree-r
  • R.......Recursively refresh the current root.....................NERDTree-R
  • m.......Display the NERD tree menu...............................NERDTree-m
  • cd......Change the CWD to the dir of the selected node...........NERDTree-cd
  • CD......Change tree root to the CWD..............................NERDTree-CD
  • I.......Toggle whether hidden files displayed....................NERDTree-I
  • f.......Toggle whether the file filters are used.................NERDTree-f
  • F.......Toggle whether files are displayed.......................NERDTree-F
  • B.......Toggle whether the bookmark table is displayed...........NERDTree-B
  • q.......Close the NERDTree window................................NERDTree-q
  • A.......Zoom (maximize/minimize) the NERDTree window.............NERDTree-A
  • ?.......Toggle the display of the quick help.....................NERDTree-?

Tern

In JavaScript files, the package will hook into [omni completion][omni] to handle autocompletion, and provide the following commands:

  • TernDef: Jump to the definition of the thing under the cursor.

  • TernDoc: Look up the documentation of something.

  • TernType: Find the type of the thing under the cursor.

  • TernRefs: Show all references to the variable or property under the cursor.

  • TernRename: Rename the variable under the cursor.

Surround

It's easiest to explain with examples. Press cs"' inside

"Hello world!"

to change it to

'Hello world!'

Now press cs'<q> to change it to

<q>Hello world!</q>

To go full circle, press cst" to get

"Hello world!"

To remove the delimiters entirely, press ds".

Hello world!

Now with the cursor on "Hello", press ysiw] (iw is a text object).

[Hello] world!

Let's make that braces and add some space (use } instead of { for no space): cs]{

{ Hello } world!

Now wrap the entire line in parentheses with yssb or yss).

({ Hello } world!)

Revert to the original text: ds{ds)

Hello world!

Emphasize hello: ysiw<em>

<em>Hello</em> world!

Finally, let's try out visual mode. Press a capital V (for linewise visual mode) followed by S<p class="important">.

<p class="important">
  <em>Hello</em> world!
</p>

emmet

  • Type (_ is the cursor position):

    html:5_

    Then type <c-y>, (Ctrly,), and you should see:

    <!DOCTYPE HTML>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    _
    </body>
    </html>
  • Expand an Abbreviation

    Type the abbreviation as div>p#foo$*3>a and type <c-y>,.

    <div>
        <p id="foo1">
            <a href=""></a>
        </p>
        <p id="foo2">
            <a href=""></a>
        </p>
        <p id="foo3">
            <a href=""></a>
        </p>
    </div>
  • Wrap with an Abbreviation

    Write as below:

    test1
    test2
    test3
    

    Then do visual select(line wise) and type <c-y>,. Once you get to the Tag: prompt, type ul>li*.

    <ul>
        <li>test1</li>
        <li>test2</li>
        <li>test3</li>
    </ul>

    If you type a tag, such as blockquote, then you'll see the following:

    <blockquote>
        test1
        test2
        test3
    </blockquote>
  • Balance a Tag Inward

    type <c-y>d in insert mode.

  • Balance a Tag Outward

    type <c-y>D in insert mode.

  • Go to the Next Edit Point

    type <c-y>n in insert mode.

  • Go to the Previous Edit Point

    type <c-y>N in insert mode.

  • Update an <img> Size

    Move cursor to the img tag.

    <img src="foo.png" />

    Type <c-y>i on img tag

    <img src="foo.png" width="32" height="48" />
  • Merge Lines

    select the lines, which include <li>

    <ul>
      <li class="list1"></li>
      <li class="list2"></li>
      <li class="list3"></li>
    </ul>

    and then type <c-y>m

    <ul>
      <li class="list1"></li><li class="list2"></li><li class="list3"></li>
    </ul>
  • Remove a Tag

    Move cursor in block

    <div class="foo">
      <a>cursor is here</a>
    </div>

    Type <c-y>k in insert mode.

    <div class="foo">
    
    </div>

    And type <c-y>k in there again.

  • Split/Join Tag

    Move the cursor inside block

    <div class="foo">
      cursor is here
    </div>

    Type <c-y>j in insert mode.

    <div class="foo"/>

    And then type <c-y>j in there again.

    <div class="foo">
    </div>
  • Toggle Comment

    Move cursor inside the block

    <div>
      hello world
    </div>

    Type <c-y>/ in insert mode.

    <!-- <div>
      hello world
    </div> -->

    Type <c-y>/ in there again.

    <div>
      hello world
    </div>
  • Make an anchor from a URL

    Move cursor to URL

    http://www.google.com/

    Type <c-y>a

    <a href="http://www.google.com/">Google</a>

  • Make some quoted text from a URL

    Move cursor to the URL

    http://github.com/

    Type <c-y>A

    <blockquote class="quote">
      <a href="http://github.com/">Secure source code hosting and collaborative development - GitHub</a><br />
      <p>How does it work? Get up and running in seconds by forking a project, pushing an existing repository...</p>
      <cite>http://github.com/</cite>
    </blockquote>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment