Skip to content

Instantly share code, notes, and snippets.

@KatrinaHoffert
Last active August 29, 2015 14:10
Show Gist options
  • Save KatrinaHoffert/d58fece297d93edcb9cf to your computer and use it in GitHub Desktop.
Save KatrinaHoffert/d58fece297d93edcb9cf to your computer and use it in GitHub Desktop.
My current .vimrc file

This is my .vimrc file. Just install it to ~/.vimrc. I've tested this on Windows with Cygwin's MinTTY and on Linux with Konsole.

In order to use it, you'll need to make a few other changes.

##Plugins

In order for the plugins to work, you'll have to install Vundle as described here. You'll probably only have to do steps 2 and 4. Step 1 is just getting Git (which you probably already have) and step 3 is already done. vim-airline is the part that really makes it look pretty.

##Fonts

In order for it to work properly, you'll have to install one of the fonts from here and set it as the font used by the terminal. The one I used in that gifycat is Inconsolata-dz.

###Windows

For Cygwin MinTTY on Windows, this is very easy to setup. Just install the font as normal, restart all Cygwin windows, and right click on MinTTY's status bar > Options. You can select a font in the text tab.

###Linux

Just place the font files in ~/.fonts and configure your terminal to use it (exact instructions depend on the terminal used). For Konsole, for example, go to Settings > Edit current profile > Appearance > Select Font.

##Terminal colors

The settings assume you're using a 256 color terminal. If you aren't, you'll have to change that or colors won't show up properly.

###Windows

For Cygwin's MinTTY, right click on window border > Options > Terminal and set Type to be xterm-256color.

###Linux

Add export TERM=xterm-256color in ~/.bash_profile (or similar).

##Some controversial options

You might want to consider carefully regarding these options. They aren't for everyone. These are all set in ~/.vimrc. Remove those lines if you don't want these features.

  • set mouse=a -- Allows the mouse to change the location in the window, visual selection, switching between tabs, etc. The downside is this makes it harder to do regular selecting. Hold shift to select text regularly.
  • set virtualedit=onemore -- This lets you position the cursor after the end of the line in normal mode. I like it because edit mode lets you do that, but normal mode doesn't. Some people dislike this because you're only supposed to be able to set the cursor on characters and there's no character there.
  • func! DeleteTrailingWS() -- Causes trailing whitespace to be removed on save. This is almost always desirable, but could clutter your VCS history if you start developing on a project that has a lot of trailing whitespace.

##Hotkeys

Here's some custom hotkeys and commands you'll want to know:

  • F2 and F3 = switch between tabs (you can't realiably set CTRL + TAB -- disappointing)
  • CTRL + T = new tab
  • Alt + arrow key = switch between windows (when you have multiple open).
  • ,h (comma is the leader key) = clear highlighting. Use this after a search to remove the highlighting from the search. Same as :noh
  • ,pp = toggle paste mode
  • :T4 = set tab size to be 4 (can be any number)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Package manager (Vundle)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
Plugin 'nathanaelkane/vim-indent-guides'
Plugin 'tpope/vim-sleuth'
Plugin 'bling/vim-airline'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'ervandew/supertab'
Plugin 'scrooloose/syntastic'
Plugin 'tpope/vim-surround'
Plugin 'scrooloose/nerdtree'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8
" Use Unix as the standard file type
set ffs=unix,dos,mac
" Sets how many lines of history VIM has to remember
set history=700
" Enable filetype plugins
filetype plugin on
filetype indent on
" Set to auto read when a file is changed from the outside
set autoread
" Turn backup off, since most stuff is in VCS
set nobackup
set nowb
set noswapfile
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Hotkeys
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file. Use "," instead of "\" as the leader
" key.
let mapleader = ","
let g:mapleader = ","
" :W sudo saves the file
" (useful for handling the permission-denied error)
command W w !sudo tee % > /dev/null
" Disable highlight when <leader>h is pressed
map <silent> <leader>h :noh<cr>
" Toggle paste mode on and off
map <leader>pp :setlocal paste!<cr>
" Quick switching between windows with alt + arrow
nmap <silent> <A-Up> :wincmd k<CR>
nmap <silent> <A-Down> :wincmd j<CR>
nmap <silent> <A-Left> :wincmd h<CR>
nmap <silent> <A-Right> :wincmd l<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7
" Turn on the WiLd menu for filename completion. Work like bash
set wildmode=longest:full,full
set wildmenu
" Ignore compiled files in wild menu.
set wildignore=*.o,*~,*.pyc
if has("win16") || has("win32")
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
else
set wildignore+=.git\*,.hg\*,.svn\*
endif
"Always show current position
set ruler
" Height of the command bar
set cmdheight=1
" No word wrap
set nowrap
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Makes search act like search in modern browsers
set incsearch
" Don't redraw while executing macros (good performance config)
set lazyredraw
" For regular expressions turn magic on
set magic
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2
" Add a bit extra margin to the left
set foldcolumn=1
" Set line numbers
set number
" Allow the mouse to be used in the window. Hold shift to get normal mouse
" functionality
set mouse=a
" Allow positioning cursor after end of line (where a character does not
" exist). Makes it easier to, say, delete from the end of a line to a previous
" mark (etc). Displaying trailing whitespace practically a necessity.
set virtualedit=onemore
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax highlighting
syntax enable
try
colorscheme desert
catch
endtry
set background=dark
" Show non printing characters (tabs and trailing spaces) appropriately
set list
set listchars=tab:>-,trail:·,extends:>,precedes:<
" Color now set in indent guide
"highlight SpecialKey ctermfg=235
" Show the ruler at 80 characters
set colorcolumn=81 " Up to this column is 80 (including and after is 81+)
highlight ColorColumn ctermbg=236
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Be smart when using tabs
set smarttab
set shiftwidth=4
set tabstop=4
set ai "Auto indent
set si "Smart indent
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
" Indent guides
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd ctermbg=236 ctermfg=245
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven ctermbg=240 ctermfg=245
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Editor panel, window, and buffer related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <F2> :tabprevious<CR>
noremap <F3> :tabnext<CR>
nnoremap <C-t> :tabnew<CR>
" Tab line uses airline
let g:airline#extensions#tabline#enabled = 1
" Don't display 'mixed' whitespace (often wrong)
let g:airline#extensions#whitespace#enabled = 0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Status line
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2
" Symbols for airline
let g:airline_powerline_fonts = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => On save actions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Delete trailing white space on save
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite * :call DeleteTrailingWS()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Misc functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set tab sizes
func! Tab(var1)
let size=a:var1
let &l:tabstop=size
let &l:shiftwidth=size
let &l:softtabstop=size
IndentGuidesEnable
endfunc
command! -nargs=1 T call Tab(<f-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment