Skip to content

Instantly share code, notes, and snippets.

@qmmr
Created August 2, 2012 21:25
Show Gist options
  • Save qmmr/3240799 to your computer and use it in GitHub Desktop.
Save qmmr/3240799 to your computer and use it in GitHub Desktop.
VIM configuration files for Windows
"
" _gvimrc File
" Maintained by: Marcin Kumorek
" kumeek@gmail.com
" http://kummar.pl
"
" Copy to ~/.gvimrc (linux) or ~/_gvimrc (windows)
"Forget compatibility with Vi. Who cares.
set nocompatible
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup " Don't make a backup before overwriting a file.
set nowritebackup " And again.
set noswapfile
"Enable filetypes
filetype on
filetype plugin on
filetype indent on
syntax on
" Write the old file out when switching between files.
"set autowrite
" Ever notice a slight lag after typing the leader key + command? This lowers the timeout.
set timeoutlen=500
" Switch between buffers without saving
set hidden
" Set font type and size. Depends on the resolution. Larger screens, prefer h20
"set guifont=DejaVu\ Sans\ Mono\ 12
"set guifont=DejaVu_Sans_Mono:h12:cEASTEUROPE
set guifont=Inconsolata:h14:cEASTEUROPE
set antialias " MacVim: smooth fonts.
set encoding=utf-8 " Use UTF-8 everywhere.
"scriptencoding utf-8
set background=light " Background.
set guioptions-=r " Dont show right scrollbar
set guioptions-=T " Hide toolbar.
" Set the color scheme. Change this to your preference.
" Here's 100 to choose from: http://www.vim.org/scripts/script.php?script_id=625
"colorscheme wombat
colorscheme molokai
"------------------------
" Tab stuff
"------------------------
set tabstop=4
set shiftwidth=4
set softtabstop=4
set et " expandtab changes tabs into spaces, so tabstop is not needed
" ===============================================================================
if has("autocmd")
augroup vim_files
au!
autocmd filetype cmd set expandtab " disallow tabs in Vim files
augroup end
au BufRead,BufNewFile *.scss set filetype=scss
au BufRead,BufNewFile *.js.erb set filetype=eruby.js
au BufRead,BufNewFile *.html.erb set filetype=eruby.html
" use closetag plugin to auto-close HTML tags
" autocmd filetype html,xml,xsl source ~/.vim/scripts/html_autoclosetag.vim
" render YAML front matter inside Textile documents as comments
" autocmd filetype textile syntax region frontmatter start=/\%^---$/ end=/^---$/
" autocmd filetype textile highlight link frontmatter Comment
" Automatic fold settings for specific files. Uncomment to use.
" autocmd Filetype scss setlocal ts=4 sw=4 sts=4 expandtab nocindent
" autocmd Filetype ruby setlocal ts=2 sw=2 expandtab
" autocmd Filetype javascript setlocal ts=4 sw=4 sts=4 expandtab
" autocmd Filetype coffee setlocal ts=2 sw=2 sts=2 noexpandtab
" au BufRead,BufNewFile *.scss set ft=scss.css | set sw=4 | set et
" Saves on blur. Uncomment to use.
" au FocusLost * :wa
endif " has("autocmd")
" ===============================================================================
autocmd FileType css setlocal sw=4 ts=4 sts=4 "foldmethod=indent expandtab
" Indent stuff
set smartindent
set autoindent
"set cindent " ? some say it's better than smartindent
" Prefer a slightly higher line height
set linespace=3
" Better line wrapping
set wrap
set textwidth=79
set formatoptions=qrn1
" case insensitive search
set ignorecase
set smartcase
" Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
"Delete all buffers (via Derek Wyatt)
nmap <silent> ,da :exec "1," . bufnr('$') . "bd"<cr>
" indenting in Visual Mode
vmap > >gv
vmap < <gv
" vmap <Tab> >gv
" vmap <S-Tab> <gv
" indenting in Normal Mode
"nmap > >gv
"nmap < <gv
nmap <Tab> >>
nmap <S-Tab> <<
" Get to home dir easier
" <leader>hm is easier to type than :cd ~
nmap <leader>hm :cd c:\xampp\htdocs<CR>
" Alphabetically sort CSS properties in file with :SortCSS
:command! SortCSS :g#\({\n\)\@<=#.,/}/sort
" Sort CSS properties alphabetically when inside css block {}
map <leader><leader>s ?{<CR>jV/^\s*\}\=$<CR>k:sort<CR>:let @/=''<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Map space to / (search) and c-space to ? (backgwards search)
map <space> /
map <c-space> ?
map <silent> <leader><cr> :noh<cr>
" Smart way to move btw. windows
"map <C-j> <C-W>j
"map <C-k> <C-W>k
"map <C-h> <C-W>h
"map <C-l> <C-W>l
" easy way to go to next/previous tab
noremap <C-j> :tabprevious<cr>
noremap <C-k> :tabnext<cr>
" Close the current buffer
map <leader>bd :Bclose<cr>
" Close all the buffers
map <leader>ba :1,300 bd!<cr>
" Use the arrows to something usefull
" switch buffers in current window
map <right> :bn<cr>
map <left> :bp<cr>
"Shortcut to fold tags with leader (usually \) + ft
"nnoremap <leader>ft Vatzf
"Automatically change current directory to that of the file in the buffer
autocmd BufEnter * cd %:p:h
"Map code completion to , + tab
imap <leader><tab> <C-x><C-p>
"http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE
set completeopt=longest,menuone
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
\ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
inoremap <expr> <M-,> pumvisible() ? '<C-n>' :
\ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
"Map escape key to jj -- much faster
imap jj <esc>
" sets fold method to indent
" you can later change to manual folds
"set foldmethod=indent
augroup vimrc
au BufReadPre * setlocal foldmethod=indent
au BufWinEnter * if &fdm == 'indent' | setlocal foldmethod=manual | endif
augroup END
" maps fd to toggle fold (easier than za)
map fd za
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PLUGINS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"------------------------
" DETECTINDENT
"------------------------
" setting for DetectIndentation plugin
autocmd BufReadPost * :DetectIndent
" To prefer 'expandtab' to 'noexpandtab' when no detection is possible:
let g:detectindent_preferred_expandtab = 1
" To specify a preferred indent level when no detection is possible:
let g:detectindent_preferred_indent = 4
" ----------------------------
" NERDTREE PLUGIN SETTINGS
" ----------------------------
" Shortcut for NERDTreeToggle
"nmap <leader>nt :NERDTreeToggle <CR>
" Show hidden files in NerdTree
"let NERDTreeShowHidden=1
"autopen NERDTree and focus cursor in new document
"autocmd VimEnter * NERDTree c:\xampp\htdocs
"autocmd VimEnter * NERDTree ~/htdocs
"autocmd VimEnter * wincmd p
" mapping
" nmap, vmap, imap, map (normal, visual and operating-pending modes), map! - command and insert modes
" ----------------------------
" T-comment
" ----------------------------
" line comment
map <leader>c <c-_><c-_>
" file type comment (need to type the filetype)
map <leader>ca <c-_>a
" <!-- html style comment -->
map <leader>ch <c-_>a html<Enter>
" ----------------------------
" Easymotion
" ----------------------------
" update EasyMotion.vim <Leader> to any key you want ie. ',,'
" ----------------------------
" FuzzyFinder
" ----------------------------
" maps ff to FuzzyFinderFile
"map ff :FufFile<Enter>
" ----------------------------
" Command-T
" ----------------------------
nnoremap <silent> <Leader>t :CommandT<CR>
"map <Leader>t :Command-T<CR>
" ----------------------------
" Align%294
" ----------------------------
" align by :
noremap <leader>l :Align :<CR>
" Example Vim configuration.
" Copy or symlink to ~/.vimrc or ~/_vimrc.
set nocompatible " Must come first because it changes other options.
let mapleader = "," " Want a different map leader than \
set langmenu=en_GB.UTF-8 " change menu language to english
language messages en
syntax enable " Turn on syntax highlighting.
filetype plugin indent on " Turn on file type detection.
set showcmd " Display incomplete commands.
set showmode " Display the mode you're in.
set backspace=indent,eol,start " Intuitive backspacing.
set hidden " Handle multiple buffers better.
set wildmenu " Enhanced command line completion.
set wildmode=list:longest " Complete files like a shell.
set ignorecase " Case-insensitive searching.
set smartcase " But case-sensitive if expression contains a capital letter.
set number " Show line numbers.
set ruler " Show cursor position.
set incsearch " Highlight matches as you type.
set hlsearch " Highlight matches.
set wrap " Turn on line wrapping.
set scrolloff=3 " Show 3 lines of context around the cursor.
set title " Set the terminal's title
set visualbell " No beeping.
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup " Don't make a backup before overwriting a file.
set nowritebackup " And again.
set noswapfile
"=========== TABS ============
set ts=4 " Global tabstop
set sw=4 " Shiftwidth
set expandtab " Use spaces instead of tabs
set laststatus=2 " Show the status line all the time
" Useful status information at bottom of screen
set statusline=[%n]\ %<%.99f\ %h%w%m%r%y\ %{exists('*CapsLockStatusline')?CapsLockStatusline():''}%=%-16(\ %l,%c-%v\ %)%P
" ease of use keyboard mappings (why do I care about top/bottom of screen?)
map H ^
map L $
" easier moving screen
map <C-k> <C-e>
map <C-j> <C-y>
" Tab mappings.
map <leader>tn :tabnew<cr>
map <leader>te :tabedit
map <leader>tc :tabclose<cr>
map <leader>to :tabonly<cr>
map <leader>tn :tabnext<cr>
map <leader>tp :tabprevious<cr>
map <leader>tf :tabfirst<cr>
map <leader>tl :tablast<cr>
map <leader>tm :tabmove
" make tabs and trailing spaces visible when requested
set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
nmap <silent> <leader>s :set nolist!<CR>
" Automatic fold settings for specific files. Uncomment to use.
" autocmd FileType ruby setlocal foldmethod=syntax
" autocmd FileType css setlocal foldmethod=indent shiftwidth=2 tabstop=2
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
"-------------------------------------------------------------------------------
" Vim Addon Manager
fun! EnsureVamIsOnDisk(vam_install_path)
" windows users may want to use http://mawercer.de/~marc/vam/index.php
" to fetch VAM, VAM-known-repositories and the listed plugins
" without having to install curl, 7-zip and git tools first
" -> BUG [4] (git-less installation)
let is_installed_c = "isdirectory(a:vam_install_path.'/vim-addon-manager/autoload')"
if eval(is_installed_c)
return 1
else
if 1 == confirm("Clone VAM into ".a:vam_install_path."?","&Y\n&N")
" I'm sorry having to add this reminder. Eventually it'll pay off.
call confirm("Remind yourself that most plugins ship with ".
\"documentation (README*, doc/*.txt). It is your ".
\"first source of knowledge. If you can't find ".
\"the info you're looking for in reasonable ".
\"time ask maintainers to improve documentation")
call mkdir(a:vam_install_path, 'p')
execute '!git clone --depth=1 git://github.com/MarcWeber/vim-addon-manager '.shellescape(a:vam_install_path, 1).'/vim-addon-manager'
" VAM runs helptags automatically when you install or update plugins
exec 'helptags '.fnameescape(a:vam_install_path.'/vim-addon-manager/doc')
endif
return eval(is_installed_c)
endif
endf
fun! SetupVAM()
" Set advanced options like this:
" let g:vim_addon_manager = {}
" let g:vim_addon_manager['key'] = value
" Example: drop git sources unless git is in PATH. Same plugins can
" be installed from www.vim.org. Lookup MergeSources to get more control
" let g:vim_addon_manager['drop_git_sources'] = !executable('git')
" let g:vim_addon_manager.debug_activation = 1
" VAM install location:
" uncomment line below when NOT on Windows
"let vam_install_path = expand('$HOME') . '/.vim/vim-addons'
" uncomment line below when ON Windows
let vam_install_path = $USERPROFILE . '/vim-addons'
if !EnsureVamIsOnDisk(vam_install_path)
echohl ErrorMsg
echomsg "No VAM found!"
echohl NONE
return
endif
exec 'set runtimepath+='.vam_install_path.'/vim-addon-manager'
" Tell VAM which plugins to fetch & load:
call vam#ActivateAddons([ 'L9', 'DetectIndent',
\ 'surround', 'repeat', 'matchit.zip', 'Align%294',
\ 'sparkup', 'EasyMotion', 'tComment', 'vim-coffee-script',
\ 'snipmate', 'snipmate-snippets', 'AutoComplPop' ], {'auto_install' : 0})
" Addons are put into vam_install_path/plugin-name directory
" unless those directories exist. Then they are activated.
" Activating means adding addon dirs to rtp and do some additional magic
" How to find addon names?
" - look up source from pool
" - (<c-x><c-p> complete plugin names):
" You can use name rewritings to point to sources:
" ..ActivateAddons(["github:foo", .. => github://foo/vim-addon-foo
" ..ActivateAddons(["github:user/repo", .. => github://user/repo
" Also see section "2.2. names of addons and addon sources" in VAM's documentation
endfun
" run the setup on VIM start
call SetupVAM()
" list of plugins you may want to install
" 'The_NERD_Commenter', 'supertab', 'SQLUtilities_-_SQL_utilities_-_Formatting_generate', 'vorax', 'taglist', 'genutils',
" 'bufexplorer.zip', 'minibufexpl.vim_-_Elegant_buffer_explorer', 'tcalc', 'arpeggio', 'ack', 'xptemplate'
" experimental [E1]: load plugins lazily depending on filetype, See
" NOTES
" experimental [E2]: run after gui has been started (gvim) [3]
" option1: au VimEnter * call SetupVAM()
" option2: au GUIEnter * call SetupVAM()
" See BUGS sections below [*]
" Vim 7.0 users see BUGS section [3]
"-------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment