Skip to content

Instantly share code, notes, and snippets.

@andrefs
Created January 5, 2012 17:18
Show Gist options
  • Save andrefs/1566203 to your computer and use it in GitHub Desktop.
Save andrefs/1566203 to your computer and use it in GitHub Desktop.
" Configuration file for Vim
" Place in: ~/.vimrc
" André Santos
" 2009.10.18
" Turn off vi compatibility mode
set nocompatible
" Turn off message 'Thanks for flying vim'
" set notitle
set title
" Set leader
" The leader character is your own personal modifier key
" default is \
let mapleader = ","
" Show line numbers (off= set nonu)
set nu
" Use incremental search
set incsearch
" Highlight search results
set hlsearch
" Allow Vim to manage multiple buffers efectively
" 1. The current buffer can be put to the background without writing to disk
" 2. When a background buffer becomes current again, marks and undo-history are
" remembered
set hidden
" Boost history (20 to 1000)
set history=1000
" Extend % to switch among if/elsif/else/end, XML tags, ...
" % normally switches between opening and closing brackets
runtime /usr/share/vim/addons/plugin/matchit.vim
" Make tab in command mode smarter and similar to shell
set wildmenu
set wildmode=list:longest
" Set the terminal title
set title
" Intuitive backspacing in insert mode
set backspace=indent,eol,start
" keep a backup file
" in ~/.vim/backup
set backup
set backupdir=~/.vim/backup
" persistent undo
" allows to undo even after closing vim or even
" shutting down the computer
set undofile
set undodir=~/.vim/undo
" remember some stuff after quiting vim:
" marks, registers, searches, buffer list
set viminfo='20,<50,s10,h,%
""""""""""""""""""""""""""""""""""""""""
" Syntax highlighting
""""""""""""""""""""""""""""""""""""""""
" Turn on syntax highlighting...
syn on
""""""""""""""""""""""""""""""""""""""""
" Dark background
""""""""""""""""""""""""""""""""""""""""
set background=dark
""""""""""""""""""""""""""""""""""""""""
" Indenting
""""""""""""""""""""""""""""""""""""""""
" Auto indent when editing
" set autoindent
" Each saving tab has 4 character length, but IS NOT 4 spaces
set tabstop=4
set shiftwidth=4
" Don't use this one
"set expandtab
set smartindent
""""""""""""""""""""""""""""""""""""""""
" Key bindings
""""""""""""""""""""""""""""""""""""""""
" Yank the current line into buffer y and execute it"
" nao funciona :(
" map - "yyy:@y^M
" Fix command typos (stolen from Adam Katz)
nmap ; :
" Press F4 to toggle highlighting on/off.
nmap <silent> <leader>n :set hls!<CR>
" mx adds a mark on the current line and column (x may be any letter)
" 'x will jump to the line and column marked with mx
" `x will jump to the line and column marked with mx
" defaults are switched
nnoremap ' `
nnoremap ` '
" Activate/deactivate paste mode
nmap <leader>p :set paste!<CR>
nmap <S-x><S-x> :q!<CR>
" Repeat last collon (:) command
nmap <leader>. @:
" if modifier to if block
map <leader>if V:s/\(\s*\) if \(.*\);/\1if (\2) {/<CR>kVdp>>$a;<CR><BS>}<CR><Esc>kkk^
" Catch trailing whitespace (make white space visible)
" Shortcut to rapidly toggle `set list`
" shows invisible characters
nmap <leader>s :set list!<CR>
set listchars=tab:>-,eol:$
" Use the same symbols as TextMate for tabstops and EOLs
" set listchars=tab:▸\ ,eol:¬
""""""""""""""""""""""""""""""""""""""""
" Motion and text wrap
""""""""""""""""""""""""""""""""""""""""
" Don't visually break lines in the middle of words
set lbr
" Set arrow keys up and down to move between screen lines
" map: Normal, Visual, Operator-pending
map <down> gj
map <up> gk
" imap: Insert
imap <up> <ESC>gka
imap <down> <ESC>gja
" Allow cursor motion to wrap
set ww=b,s,<,>,[,]
" Scroll margin 10 lines
set scrolloff=10
" Break lines longer than 70
":set wrapmargin=180
""""""""""""""""""""""""""""""""""""""""
" File type handling
""""""""""""""""""""""""""""""""""""""""
" Use plugins according to filetypes
filetype on
filetype plugin on
" Use latin1 (ISO-8859-1) text encoding
"set enc=latin1
" or UTF-8
"set enc=utf-8
set fileencodings=ucs-bom,utf-8,latin1
" " These settings are needed for latex-suite
" filetype indent on
" let g:tex_flavor='latex'
" set grepprg=grep\ -nH\ $*
"
" let g:Tex_Folding=0 "I don't like folding.
" set iskeyword+=:
" Treat .pde files as arduino
autocmd! BufNewFile,BufRead *.pde setlocal ft=arduino
""""""""""""""""""""""""""""""""""""""""
" Sessions
""""""""""""""""""""""""""""""""""""""""
" save session with SQ
nmap SQ <ESC>:mksession! $PWD/.session.vim<CR>:wqa<CR>
" open existing session in this folder
function! RestoreSession()
if argc() == 0 "vim called without arguments
let session=$PWD."/.session.vim"
if filereadable(session)
execute "source ".session
end
end
endfunction
autocmd VimEnter * call RestoreSession()
" Remember cursor position
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
""""""""""""""""""""""""""""""""""""""""
" Functions and external commands
""""""""""""""""""""""""""""""""""""""""
" Indent XML readably
function! DoPrettyXML()
1,$!xmllint --format --recover -
endfunction
command! PrettyXML call DoPrettyXML()
" Reload snippets
function! ReloadSnippets( snippets_dir, ft )
if strlen( a:ft ) == 0
let filetype = "_"
else
let filetype = a:ft
endif
call ResetSnippets()
call GetSnippets( a:snippets_dir, filetype )
endfunction
nmap <leader>rr :call ReloadSnippets(snippets_dir, &filetype)<CR>
" Perl Critic
"function! DoPerlCritic()
" 1,$!perlcritic
"endfunction
"" command! PC call DoPerlCritic()
"nmap <leader>c :call DoPerlCritic()<CR>
" make
nmap <leader>m :make<CR>
" Language settings for the spell checker
setlocal spell spelllang=en_us
" setlocal spell spelllang=pt_pt
" Use spell checkers
set nospell
" Press ,j to toggle spell checking on/off
nmap <leader>j :set nospell!<CR>
" automatically give executable permissions if file begins with #!
" au BufWritePost * if getline(1) =~ "^#!" | silent !chmod a+x <afile> | endif
" " error bin/bash endif
" Andrefs smart indentation: edit with tabs, save with spaces!
" exclude [Mm]akefiles
autocmd BufWritePre Makefile let b:afs_noSmartTabIndent=1
autocmd BufWritePre makefile let b:afs_noSmartTabIndent=1
" Flag if file has been edited+saved
autocmd BufWritePre * let b:afs_edited=1
" autocmd BufWinLeave * buffers
" autocmd BufWinLeave * buffer 3 | buffers
" autocmd BufWinLeave * buffers | echo '%'expand('<abuf>') | buffer expand('<abuf>') | buffers
" if !exists('b:afs_noSmartTabIndent')
" Convert space-indentation to tab-indentation when opening file
" autocmd BufWinEnter * set noexpandtab
" autocmd BufWinEnter * exe 'retab!'
" Convert tab-indentation to space-indentation when quiting single file
" if exists('b:afs_edited')
" "autocmd BufUnload * let b:afs_curbuf=expand('<afile>')
" autocmd BufUnload * buffer <afile>
" autocmd BufWinLeave * buffer | set expandtab | exe 'retab!w' | :write
" endif
" endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment