Skip to content

Instantly share code, notes, and snippets.

@icleversoft
Last active November 6, 2015 07:06
Show Gist options
  • Save icleversoft/debdaef131362bc0eb99 to your computer and use it in GitHub Desktop.
Save icleversoft/debdaef131362bc0eb99 to your computer and use it in GitHub Desktop.
My vimrc file
set background=dark
colorscheme railscasts " base16-railscasts railscasts
set relativenumber " show relative line numbers

General configuration

, is used as mapleader backslash is used as localleader

  • ,e mapped to :e **/. essentially you do ,efoo<tab> to get a list of all files starting with foo
  • ,s - toggle invisible characters display
  • ,n - next quicklist result (like :Ggrep etc)
  • ,N - previous quicklist result (like :Ggrep etc)
  • Ctrl-E - switch between 2 last buffers (its just a :b#<cr> :)
  • Ctrl-N to cancel current search highlighing
  • ,f global Ggrep for word under the cursor or for selection
  • +, - - easily inc/decrement integers
  • ,W - remove trailing spaces
  • Ctrl-h/j/k/l - simplified split panes navigation
  • ,d - :diffupdate
  • ,dp - :diffput
  • ,dg - :diffget
  • %% - in control mode, i.e. after you typed : it will expand to the directory name of the currently opened file.

Backups

Backups and swapfiles are disabled. I really hate them both.

You can re-enable backups by adding the following to your ~/.local.vim:

set backup

and swapfiles by

set swapfile

backup dir is set to ~/.backup/

The directory is created if it doesn't exist.

Persistent Undo

Persistent undos are enabled by default.

You can disable by adding the following to your ~/.local.vim:

set noundo

Macros

I included a couple of macros that I frequently use in macros.vim which is loaded from after.vim:

  • @q (re)format paragraph forward
  • @s enclose selection with double *. e.g. **foo**.

You really should start writing your own macros. The life will never be the same ;).

I recommend editing your macros in a vim buffer.

To load a macro into a register you can 'yank' it.

For example if you have a line with a macro and cursor is at the beginning of it "ay$ will load the macro into register a, so that you will be able to execute it with @a.

"Interesting" Plugins:

  • nerdtree (top)

    hax0r vim script to give you a tree explorer

    • Ctrl-P - open directory browser (Note: this is now handled by nerdtree-tabs (see below))
    • ,p - to find and highlight the currently open file in the tree
  • nerdtree-tabs (top)

    NERDTree and tabs together in Vim, painlessly

    • Ctrl-P - open directory browser
  • nerdcommenter (top)

    Vim plugin for intensely orgasmic commenting

    • ,/ - toggle comment
    • ,cc - add commenting
    • ,cu - Uncomment
    • check docs for more
  • Command-T (top)

    TextMate Command-T like file finder for vim

    Note: This plugin is currently DISABLED. See CtrlP plugin that is used instead

    • ,, - CommandT - find file
    • ,. - CommandTFlush - refresh the file list and then find a file
    • while at the finder prompt:
      • Ctrl-Enter - open file in a new split
      • Ctrl-s - open file in a new split
      • Ctrl-v - open file in a new vertical split
      • Ctrl-U - clear current partial path
      • Esc - cancel
      • Ctrl-c - cancel
  • CtrlP (top)

    Fuzzy file, buffer, mru, tag, etc finder.

    This is the new fuzzy finder used by dotvim. It replaced Command-T that was used before.

    The default mapping is still the same:

    • ,, - CtrlP - fuzzy find.
    • ,. - CtrlPClearCache followed by CtrlP - clears the cache and searches the files (not including MRU and buffers)
    • ,m - CtrlPBufTag - search tags in the current buffer
    • ,M - CtrlPBufTagAll - search tags in all buffers
    • ,l - CtrlPLine - fuzzy search lines in all opened buffers
    • ,b - CtrlPBuff - fuzzy search open buffers
    • ,,?<ENTER> - to quickly open help for CtrlP

This plugin has lots of options, see :h ctrlp for more.

  • AutoComplPop (top)

    Automatically opens popup menu for completions

    Shouldn't require config.

  • taglist.vim (top)

    Source code browser (supports C/C++, java, perl, python, tcl, sql, php, etc)

    • ,t - toggle tags window
  • YankRing.vim (top)

    Maintains a history of previous yanks, changes and deletes

    • ,y to show the yankring
    • ,[/,] - to cycle the just-pasted text though the yankring.
    • :h yankring.txt and :h yankring-tutorial for more
  • vim-fugitive (top)

    A Git wrapper so awesome, it should be illegal

    • :Gstatus

      Bring up the output of git-status in the preview window. Press - to stage or unstage the file on the cursor line. Press p to do so on a per hunk basis (--patch). Press C to invoke :Gcommit.

    • :Gcommit [args]

      A wrapper around git-commit.

    • :Ggrep [args]

      :grep with git-grep as 'grepprg'.

    • ,g

      shortcut to run :Ggrep

    • //

      global git search for the word under the cursor for for selection (in visual mode)

    • :Gblame

      Run git-blame on the file and open the results in a scroll bound vertical split. Press enter on a line to reblame the file as it was in that commit.

    Much more in the plugin's doc

  • syntastic (top)

    syntax checking plugin

    it will display the number of syntax errors in the current file in the vim's status line.

    use :Errors to display a window detailing the errors

  • snipmate (top)

    TextMate-style snippets for Vim

    write a snipped text and press TAB to expand it.

    To see the list of available snippets type Ctrl-R <Tab> in the insert mode

  • vim-surround (top)

    Delete/change/add parentheses/quotes/XML-tags/much more with ease

    • dsX - delete surround X
    • csXY - change surround X with Y
    • s/S in visual mode - wrap selection
    • ysMovementX - surround movement with X

    You should REALLY read the docs if you want to use this one

  • vim-align (top)

    Align and AlignMaps lets you align statements on their equal signs, make comment boxes, align comments, align declarations, etc.

    • ,t= - align on =
    • ,tsp - align on whitespace
    • ,t, - align on commas
    • ,t| - align on vertical bars
    • ,acom - align comments (C/C++)
    • :AlignSEPARATORS - align on separators
    • :h align - see help for more options
  • ag.vim (top)

    This plugin is a front for ag, A.K.A. the_silver_searcher. Ag can be used as a replacement for 153% of the uses of ack. This plugin will allow you to run ag from vim, and shows the results in a split window.

    • :Ag [options] {pattern} [{directory}] - grep for the pattern in side directory and open result in a QuickFix window
    • :h Ag - more help about Ag

    Installation:

    • on OSX: brew install the_silver_searcher or port install the_silver_searcher
    • on Ubuntu: apt-get install silversearcher-ag
  • vim-indentobject (top)

    A text object for manipulating blocks based on their indentation

    This is good for Python, YAML, HAML etc.

    Usage is similar to textobj-rubyblock, just with i instead of r

    • vai / vii - select indent block including / excluding the outer lines
    • yai / yii - yank ...
  • greplace.vim (top)

    Replace a pattern across multiple files interactively

    Use :Gsearch to search for a pattern. Edit the result buffer to your liking, then :Greplace to incorporate your edits into the source files

    • :Gsearch - Search for a given pattern in the specified group of files and display the matches in the replace buffer.
    • :Gbuffersearch - Search for a given pattern in all the buffers in the Vim buffer list.
    • :Greplace - Incorporate the modifications from the replace buffer into the corresponding files.
  • vim-airline (top)

    Lean & mean status/tabline for vim that's light as air.

    A better replacement for vim-powerline. Optimized for speed; it loads in under a millisecond.

    Install fonts for best results.

  • splice.vim (top)

    A plugin for resolving conflicts during three-way merges.

    Add the following lines to ~/.gitconfig to use

    [merge] tool = splice

    [mergetool "splice"] cmd = "vim -f $BASE $LOCAL $REMOTE $MERGED -c 'SpliceInit'" trustExitCode = true

    Bindings:

    • -g - switch to grid view

    • -l - switch to loupe view

    • -c - switch to compare view

    • -p - switch to path view

    • -o - select the original file

    • -1 - select file one

    • -2 - select file two

    • -r - select the results file

    • -n - next unresolved conflict

    • -N - prev unresolved conflict

    • -<space> - cycle layout

    • -s - toggle scrolllocking

    • -d - cycle diff combinations

    • -D - turn off all diffs

    • -CC - exits vim with error code (like :cquit). this will indicate to git that merge resolution failed

    • -q - exits vim with success; this will indicate to git that merge succeeded

    • :h splice - you should probably read it ;)

  • vim-endwise (top)

    Wisely add "end" in ruby, endfunction/endif/more in vim script, etc

  • delimitMate (top)

    auto-completion for quotes, parens, brackets, etc. in insert mode.

  • Gundo (top)

    Homepage is here

    Graphs your vim undo tree in a side window.

    • ,u - toggle undo window
    • :h gundo.txt - more help
  • vim-dispatch (top)

    Asynchronous build and test dispatcher from Tpope.

    This plugin allows to run sync/async builds and other shell commands in background, with progress support.

    try :Dispatch from inside a Rails rspec file. :h dispatch for more info.

  • unite.vim (top)

    Search and display information from arbitrary sources like files, buffers, recently used files or registers.

    This plugins is to powerful to present here, read the documentation.

    Just to give you the taste of it, try:

    :Unite -no-start-insert -auto-preview colorscheme

    Then try to navigate up and down and see what happens ;)

  • Vim Git Gutter (top) A Vim plugin which shows a git diff in the 'gutter' (sign column). It shows whether each line has been added, modified, and where lines have been removed.

    screenshot

    In the screenshot above you can see:

    • Line 15 has been modified.
    • Lines 21-24 are new.
    • A line or lines were removed between lines 25 and 26.

    Commands:

    • :GitGutterDisable
    • :GitGutterEnable
    • :GitGutterToggle
    • :GitGutterSignsEnable
    • :GitGutterSignsDisable
    • :GitGutterSignsToggle
    • :GitGutterLineHighlightsEnable
    • :GitGutterLineHighlightsDisable
    • :GitGutterLineHighlightsToggle

    Bindings:

    • ]c - jump to next hunk
    • [c - jump to previous hunk
    • ,hs - stage hunk
    • ,hr - revert hunk

    There are quite some customization options. see help.

  • vim-i18n (top)

    Extracts i18n strings from source files into .yml file.

    • ,z - extract selected string
  • Switch (top)

    A plugin to switch segments of text with predefined replacements

    it will switch "foo" to 'foo' to :foo. or {:foo => bar} to {foo: bar}, etc. See :h switch for more.

  • Switch (top)

    emmet.io like html/css workflow plugin.

  • editorconfig-vim (top)

    .editorconfig file support.

top

#### Ruby/Rails support:
  • vim-rails (top)

    Ruby on Rails: easy file navigation, enhanced syntax highlighting, and more

    • :AV - open "alternate" file in a new vertical split
    • :AS - open "alternate" file in a new horizontal split
    • :RV - open "related" file in a new vertical split
    • :RS - open "related" file in a new horizontal split
    • :Rextract - extract partial (select text for extraction first)
    • :Rinvert - takes a self.up migration and writes a self.down.
    • gf - remapped to take context into account. recognizes models associations, partials etc.
    • :h rails for much more info ;)
  • vim-bundler (top)

    Lightweight support for Ruby's Bundler

    • gf when standing over a gem name in a Gemfile will go to gem's directory
    • :Bopen NAME does bundle open NAME - opens gem NAME's lib diretory in the current window.
    • :Bundle - runs bundler
  • vim-rake (top)

    TBD

  • vim-textobj-rubyblock (top)

    A custom text object for selecting ruby blocks.

    In other words it teaches vim to understand what is ruby block, just like vim already understands what is word, paragraph, sentence etc.

    It works with begin/end, if/else/end etc.

    • var - select ruby block around the cursor including begin/end
    • vir - select insides of a ruby block around the cursor not including begin/end
    • dar - delete ruby block around the cursor
    • etc...

    Some 'trickier' usage patterns.

    • varar - select the ruby block that is around the ruby block that is around the cursor. including begin/end
    • vararir - select insides of the ruby block that is around the ruby block that is around the cursor. not including begin/end
    • ...
  • vim-ruby-refactoring (top)

    Refactoring tool for Ruby in vim!

    • ,rap :RAddParameter - Add Parameter(s) to a method
    • ,rcpc :RConvertPostConditional - Convert Post Conditional
    • ,rel :RExtractLet - Extract to Let (Rspec)
    • ,rec :RExtractConstant - Extract Constant (visual selection)
    • ,relv :RExtractLocalVariable - Extract Local Variable (visual selection)
    • ,rit :RInlineTemp - Inline Temp. replace temp parameter by direct function call
    • ,rrlv :RRenameLocalVariable - Rename Local Variable (visual selection/variable under the cursor
    • ,rriv :RRenameInstanceVariable - Rename Instance Variable (visual selection)
    • ,rem :RExtractMethod - Extract Method (visual selection)
  • blockle.vim (top)

    Toggle ruby blocks style, e.g {} to do .. end

    • ,B - toggle block style

    NOTE: thre is an unfortunate interaction with delimitMate, the opening brase gets completed. i.e. you get {} ... }

  • apidock.vim (top)

    Vim plugin that searches http://apidock.com Ruby, Rails, and RSpec docs from within Vim.

    • RR - Search the Rails docs for the word under the cursor.
    • RB - Search the Ruby docs for the word under the cursor.
    • RS - Search the RSpec docs for the word under the cursor.
  • vim-rspec (top)

    Lightweight Rspec runner for Vim.

    Commands are self explanatory:

    • :call RunCurrentSpecFile()
    • :call RunNearestSpec()
    • :call RunLastSpec()

    Bindings:

    • ,r - RunNearestSpec

top

#### Org mode and support plugins

Vim now has support for Emacs' Org mode provided by the VimOrganizer plugin.

Below you will also find a couple of plugins that support it, but can be also used intependently.

  • calendar.vim (top)

    Calendar support w/o calling external programs.

    • Commands:
      • :Calendar - open calendar
      • :Calendar 2012 8 - open calendar for 2012-08
      • :CalendarH - open horizontal calendar
    • Bindings:
      • ,cal - :Calendar
      • ,caL - :CalendarH
  • NrrwRgn (top)

    A Narrow Region Plugin (similar to Emacs)

    Allows to open selected text in a separate buffer for editing preserving the rest of the file around it.

    • Commands
      • [range]:NR - open selection or range in a buffer. write the buffer when done
      • :h NrrwRgn - read the help ;)
  • utl.vim (top)

    Universal Text Linking plugin allow to open urls from text files.

    :h utl_usr to read the help.

    Bindings:

    • ,o - types :Utl. you still need to press enter to open url. This way it allows to type other commands if needed.
  • VimOrganizer (top)

    VimOrganizer is partly a clone of Emacs' Org-mode, and partly a front end to Org-mode itself. Do Org in Vim.

    Some bindings:

    • tab - cycle visibility of single headline/subtree.
    • ,1 - show level 1 only
    • ,2 - show level 1 only
    • ...
    • In normal mode
      • Shift-Enter - cycle TODO state
      • Enter - add item of same level
    • insert mode
      • Shift-Enter - add item of same level
    • Both modes
      • Ctrl-Enter - add item of lover level
      • Shift-Ctrl-Enter - add item of higher level
    • ,dd - add DEADLINE
    • ,ds - add SCHEDULED
    • ,dc - add CLOSED
    • ,dt - add a timestamp

    Datetime prompt works mostly like the one in emacs org mode. See docs here

    Its too big to give much userful information here. open any .org file to start using it. read the help:

    :h VimOrganizer
    

    You can find cheat sheet here

    Working with TODO help is here

    Org mode site is [here](http://orgmode.org/]

"Support" and "minor" plugins

  • vim-textobj-user

    Support for user-defined text objects

  • vim-repeat

    Use the repeat command "." with supported plugins

  • vim-space

    Smart Space key for Vim

    press SPACE to repeat last motion command

  • vim-gist

    create gists on github

    • :Gist - gist the buffer
    • :'<,'>Gist - gist selection
    • :Gist -p - private gist
    • :h Gist.vim

Misc Bindings

The following is a list of commands and key bindings that I personally find interesting stored for easy refreshing my memory of them. there is no much 'system' to it, just randomly chosen bits of vim goodness.

  • ]p paste with autoindent.
  • ga print ascii value of character under the cursor
  • g# like "#", but without using "<" and ">"
  • g< display previous command output
  • zt scroll cursor line to top
  • zz scroll cursor line to center
  • zb scroll cursor line to bottom
  • CTRL-W x exchange current window with n-th window (or next if no count given)
  • gv reselect last selection
  • gt next tab
  • gT prev tab
  • ci change inside delimiters
  • di delete inside delimiters
  • @@ execute last macro
  • "xyy copy line into x register (replace x with any other)
  • <C-R>x while in insert mote will paste content of register x (replace x with any other)
  • "xp paste from register x
  • :reg Display the contents of all numbered and named registers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment