The ~/.vim directory that we share at work
VimL Python Other
Pull request Compare This branch is 18 commits ahead, 74 commits behind akitaonrails:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
_
autoload
bundle
colors
doc
ftdetect
ftplugin/html
snippets @ 6c1bd73
.gitignore
.gitmodules
README.textile
Rakefile
gvimrc
support_functions.vim
vimrc

README.textile

Vim

It is recommended that you use gVim in either Windows or Linux and MacVim for
Mac. Download from:

Bundled Plugins

  • Ack – type :Ack [search pattern] to search your entire project
  • Align – align blocks of text using equal sign, make comment boxes and more
  • bufexplorer – manage your file buffers
  • endwise – support to close Ruby blocks such as ‘if’, ‘do’ with ‘end’
  • fugitive – support for Git, adding convenient commands such as :Gstatus, :Gread, :Gmove
  • haml – syntax highlight for HAML
  • html5.vim – omnicomplete function and syntax for HTML5
  • markdown – syntax highlight for Markdown
  • NERD_commenter – support to comment lines of code
  • NERD_tree – project pane that you can open with [leader] p
  • ragtag – easier way to create tags for html, erb, etc
  • rails – lot’s of tools to make it easier to manage your Rails projects
  • snipmate – support for textmate-like snippets for several languages
  • supertab – pseudo auto-complete with tab
  • surround – add, change, remove surrounding parentheses, brackets, quotes, etc
  • syntastic – checks for syntax errors in many languages
  • textile – syntax highlight for Textile
  • vim-coffee-script – syntax highlight for Coffee Script
  • vim-jade – Vim syntax highlighting for the Jade templating engine
  • vim-jquery – Vim syntax file to add some colorations for jQuery keywords and css selectors
  • vim-preview – [leader] P previews Markdown, Rdoc, Textile, html. Requires Ruby and other gems.
  • vim-ruby-sinatra – syntax highlight for Sinatra
  • vim-ruby – syntax highlight, smart identation, auto-complete for Ruby
  • vim-textobj-rubyblock – smart block selection in Ruby code

Usage

Troubleshoot: Because of the large amount of submodules, if you ever have any
trouble after pulling from the repository, it will be easier to just back up
your old .vim folder and just git clone a new version.

Clone this repo into your home directory either as .vim (linux/mac) or
vimfiles (Windows). Such as:


git clone git://github.com/vgildeev/vimfiles.git ~/.vim

Then ‘cd’ into the repo and run this to get the snippets submodule:


git submodule update --init

Now you should create a new .vimrc file in your home directory that
loads the pre-configured one that comes bundled in this package. You can do it
on Linux/Mac like this:


echo "source ~/.vim/vimrc" > ~/.vimrc

On Windows you should create a _vimrc (underline instead of dot) and add
the following line inside:


source ~/vimfiles/vimrc

This way you can override the default configuration by adding your own inside
this file.

You should also create a new .gvimrc file in your home directory. You can do
it on Linux/Mac like this:


echo "source ~/.vim/gvimrc" > ~/.gvimrc

On Windows you should create a _gvimrc (underline instead of dot) and add
the following line inside:


source ~/vimfiles/gvimrc

This way you can override the default GUI configuration by adding your own inside
this file.

Help Tags

At first usage of vim, type “:” while in command mode and execute:

call pathogen#helptags()

This will make the plugins documentations available upon :help

Dependencies

You will need these dependencies figured out:

In Ubuntu, for example, you will have to do:


apt-get install exuberant-ctags ncurses-term

In OS X, you can install ctags with homebrew


brew install ctags

On Windows you have to download Ctags and add ctags.exe in your PATH.

Mac OS X and most Linux distros come with Ruby already. If you’re in Windows
look for Luis Lavena’s latest Ruby Installer (http://rubyforge.org/projects/rubyinstaller/)

Learn Vim

Visit the following sites to learn more about Vim:

There are many sites teaching Vim, if you know of any other that are easy
to follow for newcomers, let me know.

Credits

  • Original project and most of the heavy lifting: @scrooloose
  • All the cool plugins for Rails, Cucumber and more: @timpope
  • Hacks and some snippets: @akitaonrails

Usable Things

NERD Commenter

  • ,cc – Comment out the current line or text selected in visual mode.
  • ,cm – Comments the given lines using only one set of multipart delimiters.
  • ,cu – Uncomments the selected line(s).
  • ,c[space] – Toggles the comment state of the selected line(s). If the topmost selected
    line is commented, all selected lines are uncommented and vice versa.
  • ,c$ – Comments the current line from the cursor to the end of line.

Surround

  • Press cs"’ (that’s c, s, double quote, single quote) inside
    “Hello world!”
    to change it to
    ‘Hello world!’
  • Now press cs’ to change it to
    Hello world!
  • 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!

Walking through the splits

  • Use SHIFT-UP/DOWN/RIGHT/LEFT for walking through splits in visual mode

Transposing

  • Use CTRL-UP/DOWN for moving current line or visual selection
  • 5 would move the current line (or visual selection) 5 lines up.

Find&Replace

  • The :substitute command searches for a text pattern, and replaces it with a text string.
  • :%s/foo/bar/g Find each occurrence of ‘foo’, and replace it with ‘bar’.
  • :%s/foo/bar/gc Change each ‘foo’ to ‘bar’, but ask for confirmation first.
  • :%s/\<foo\>/bar/gc Change only whole words exactly matching ‘foo’ to ‘bar’; ask for confirmation.
  • :%s/foo/bar/gci Change each ‘foo’ (case insensitive) to ‘bar’; ask for confirmation.
  • :%s/foo/bar/gcI Change each ‘foo’ (case sensitive) to ‘bar’; ask for confirmation.
    The g flag means global – each occurrence in the line is changed, rather than just the first.
    Search range:
  • :s/foo/bar/g Change each ‘foo’ to ‘bar’ in the current line.
  • :%s/foo/bar/g Change each ‘foo’ to ‘bar’ in all lines.
  • :5,12s/foo/bar/g Change each ‘foo’ to ‘bar’ for all lines from line 5 to line 12 inclusive.
  • :'a,'bs/foo/bar/g Change each ‘foo’ to ‘bar’ for all lines from mark a to mark b inclusive.
  • :.,$s/foo/bar/g Change each ‘foo’ to ‘bar’ for all lines from the current line (.) to the last line ($) inclusive.
  • :.,+2s/foo/bar/g Change each ‘foo’ to ‘bar’ for the current line (.) and the two next lines (+2).
  • :%s/foo/bar/g Equivalent to :1,$s/foo/bar/g (change all lines).
  • :g/^baz/s/foo/bar/g Change each ‘foo’ to ‘bar’ in each line starting with ‘baz’.
    When searching:
  • ., *, \, [, ], ^, and $ are metacharacters.
  • +, ?, |, {, }, (, and ) must be escaped to use their special function.
  • \/ is / (use backslash + forward slash to search for forward slash)
  • \t is tab, \s is whitespace
  • \n is newline, \r is CR (carriage return = Ctrl-M = ^M)
  • \{#\} is used for repetition. /foo.\{2\} will match foo and the two following characters. The \ is not required on the closing } so /foo.\{2} will do the same thing.
  • \(foo\) makes a backreference to foo. Parenthesis without escapes are literally matched. Here the \ is required for the closing \).
    When replacing:
  • \r is newline, \n is a null byte (0×00).
  • \& is ampersand (& is the text that matches the search pattern).
  • \1 inserts the text of the first backreference. \2 inserts the second backreference, and so on.
  • You can use other delimiters with substitute: :s#http://www.example.com/index.html#http://example.com/#
  • Save typing by using \zs and \ze to set the start and end of a pattern. For example, instead of: :s/Copyright 2007 All Rights Reserved/Copyright 2008 All Rights Reserved/ use: :s/Copyright \zs2007\ze All Rights Reserved/2008/

Folding

  • :set foldenable enable folding if it disable
  • zo – open fold;
  • zO – close folds recursively;
  • zc – close fold;
  • zC – close fold recursively;
  • za – if fold opened – close, and vice versa;
  • zA – same as za, but recursively;
  • zr – decrease closed folds level (FOLDLEVEL+=1);
  • zR – open all folds;
  • zm – increase closed folds level (FOLDLEVEL-=1);
  • zM – close all folds.

Select to end of line

  • v SHIFT-4 in visual mode.

AutoComplPop

  • AutoComplPop – With this plugin, your vim comes to automatically opens popup menu for completions when you enter characters or move the cursor in Insert mode. It won’t prevent you continuing entering characters.

Rails.Vim

  • :Rextract {file} – make a partial from visual selection.
  • :Rview – go to view file.
  • :Rmodel – go to model.
  • :Rcontroller – go to controller.

File convertation

  • Convert from dos/unix to unix
    • :update Save any changes.
    • :e ++ff=dos Edit file again, using dos file format (‘fileformats’ is ignored).
    • :setlocal ff=unix This buffer will use LF-only line endings when written.
    • :w Write buffer using unix (LF-only) line endings.
    • In the above, replacing :set ff=unix with :set ff=mac would write the file with mac (CR-only) line endings. Or, if it was a mac file to start with, you would use :e ++ff=mac to read the file correctly, so you could convert the line endings to unix or dos.
  • Convert from dos/unix to dos
    • :update Save any changes.
    • :e ++ff=dos Edit file again, using dos file format (‘fileformats’ is ignored).
    • :w Write buffer using dos (CRLF) line endings.

Close all splits except active

  • :only

Close active tab with all splits

  • :tabclose

Unite tabs in splits and vice versa

  • :sball, :sb – Split all buffers;
  • :tab ball – vice versa.