Created
January 28, 2011 18:03
-
-
Save millisami/800662 to your computer and use it in GitHub Desktop.
vimrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" => General | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
set nocompatible " Must come first because it changes other options. | |
"silent! call pathogen#runtime_append_all_bundles() | |
"silent! call pathogen#helptags() | |
" Sets how many lines of history VIM has to remember | |
set history=700 | |
" Enable filetype plugin | |
filetype plugin on | |
filetype indent on | |
" Set to auto read when a file is changed from the outside | |
set autoread | |
" With a map leader it's possible to do extra key combinations | |
" like <leader>w saves the current file | |
let mapleader = "," | |
let g:mapleader = "," | |
" Fast saving | |
nmap <leader>w :w!<cr> | |
" Fast editing of the .vimrc | |
" map <leader>e :e! ~/.vim1/vimrc<cr> | |
" typing ,v in normal mode opens up the ~/.vimrc file in new tab | |
nmap <leader>v :tabedit $MYVIMRC<CR> | |
" When vimrc is edited, reload it | |
autocmd! bufwritepost vimrc source ~/.vim1/vimrc | |
" runtime macros/matchit.vim " Load the matchit plugin. | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => VIM user interface | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Set 7 lines to the curors - when moving vertical.. | |
set so=7 | |
set showcmd " Display incomplete commands. | |
set showmode " Display the mode you're in. | |
set hidden " Handle multiple buffers better. | |
set wildmenu " Enhanced command line completion. | |
set wildmode=list:longest " Complete files like a shell. | |
set number " Show line numbers. | |
set ruler " Show cursor position. | |
set cmdheight=2 "The commandbar height | |
set title " Set the terminal's title | |
" Set backspace config | |
set backspace=indent,eol,start " Intuitive backspacing. | |
set whichwrap+=<,>,h,l | |
" Customizations: http://stevelosh.com/blog/2010/09/coming-home-to-vim/#important-vimrc-lines | |
" Switch to normal mode from insert mode by pressing jj | |
inoremap jj <ESC> | |
" Search Settings | |
"set ignorecase " Case-insensitive searching. | |
"set smartcase " But case-sensitive if expression contains a capital letter. | |
"set incsearch " Highlight matches as you type. | |
"set hlsearch " Highlight matches. | |
"set gdefault | |
"set nolazyredraw "Don't redraw while executing macros | |
" | |
"set magic "Set magic on, for regular expressions | |
" | |
"set showmatch "Show matching bracets when text indicator is over them | |
"set mat=2 "How many tenths of a second to blink | |
" | |
"nnoremap <leader><space> :noh<cr> " Unhighlight the highlghted text when doing search | |
"nnoremap <tab> % | |
"vnoremap <tab> % | |
" Long Lines | |
"set textwidth=79 | |
"set formatoptions=qrn1 | |
"set colorcolumn=85 | |
" Use ,W to strip all trailing whitespace in the current file so I can clean things up quickly | |
"nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR> | |
" I use Ack a lot (described below), so I mapped a leader key for it | |
nnoremap <leader>a :Ack | |
" No sound on errors | |
"set visualbell " No beeping. | |
set noerrorbells | |
set novisualbell | |
set t_vb= | |
set tm=500 | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Colors and Fonts | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
syntax enable "Enable syntax hl | |
" Set font according to system | |
if MySys() == "mac" | |
set gfn=Menlo:h14 | |
set shell=/bin/bash | |
elseif MySys() == "windows" | |
set gfn=Bitstream\ Vera\ Sans\ Mono:h10 | |
elseif MySys() == "linux" | |
set gfn=Monospace\ 10 | |
set shell=/bin/bash | |
endif | |
if has("gui_running") | |
set guioptions-=T | |
set t_Co=256 | |
set background=dark | |
colorscheme peaksea | |
set nonu | |
else | |
colorscheme zellner | |
set background=dark | |
set nonu | |
endif | |
set encoding=utf8 | |
try | |
lang en_US | |
catch | |
endtry | |
set ffs=unix,dos,mac "Default file types | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Files, backups and undo | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Turn backup off, since most stuff is in SVN, git anyway... | |
set nobackup | |
set nowb | |
set noswapfile | |
set nowritebackup | |
"Persistent undo | |
try | |
if MySys() == "windows" | |
set undodir=C:\Windows\Temp | |
else | |
set undodir=~/.vim1/undodir | |
endif | |
set undofile | |
catch | |
endtry | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Text, tab and indent related | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
set expandtab " Use spaces instead of tabs | |
set shiftwidth=2 | |
set tabstop=2 | |
set smarttab | |
set lbr | |
set tw=500 | |
set ai "Auto indent | |
set si "Smart indet | |
set wrap "Wrap lines | |
"""""""""""""""""""""""""""""" | |
" => Visual mode related | |
"""""""""""""""""""""""""""""" | |
" Really useful! | |
" In visual mode when you press * or # to search for the current selection | |
vnoremap <silent> * :call VisualSearch('f')<CR> | |
vnoremap <silent> # :call VisualSearch('b')<CR> | |
" When you press gv you vimgrep after the selected text | |
vnoremap <silent> gv :call VisualSearch('gv')<CR> | |
map <leader>g :vimgrep // **/*.<left><left><left><left><left><left><left> | |
function! CmdLine(str) | |
exe "menu Foo.Bar :" . a:str | |
emenu Foo.Bar | |
unmenu Foo | |
endfunction | |
" From an idea by Michael Naumann | |
function! VisualSearch(direction) range | |
let l:saved_reg = @" | |
execute "normal! vgvy" | |
let l:pattern = escape(@", '\\/.*$^~[]') | |
let l:pattern = substitute(l:pattern, "\n$", "", "") | |
if a:direction == 'b' | |
execute "normal ?" . l:pattern . "^M" | |
elseif a:direction == 'gv' | |
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.') | |
elseif a:direction == 'f' | |
execute "normal /" . l:pattern . "^M" | |
endif | |
let @/ = l:pattern | |
let @" = l:saved_reg | |
endfunction | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Command mode related | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Smart mappings on the command line | |
cno $h e ~/ | |
cno $d e ~/Desktop/ | |
cno $j e ./ | |
cno $c e <C-\>eCurrentFileDir("e")<cr> | |
" $q is super useful when browsing on the command line | |
cno $q <C-\>eDeleteTillSlash()<cr> | |
" Bash like keys for the command line | |
cnoremap <C-A> <Home> | |
cnoremap <C-E> <End> | |
cnoremap <C-K> <C-U> | |
cnoremap <C-P> <Up> | |
cnoremap <C-N> <Down> | |
func! Cwd() | |
let cwd = getcwd() | |
return "e " . cwd | |
endfunc | |
func! DeleteTillSlash() | |
let g:cmd = getcmdline() | |
if MySys() == "linux" || MySys() == "mac" | |
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "") | |
else | |
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "") | |
endif | |
if g:cmd == g:cmd_edited | |
if MySys() == "linux" || MySys() == "mac" | |
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "") | |
else | |
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "") | |
endif | |
endif | |
return g:cmd_edited | |
endfunc | |
func! CurrentFileDir(cmd) | |
return a:cmd . " " . expand("%:p:h") . "/" | |
endfunc | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => 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 | |
" 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 | |
map <right> :bn<cr> | |
map <left> :bp<cr> | |
" Tab configuration | |
map <leader>tn :tabnew<cr> | |
map <leader>te :tabedit | |
map <leader>tc :tabclose<cr> | |
map <leader>tm :tabmove | |
" When pressing <leader>cd switch to the directory of the open buffer | |
map <leader>cd :cd %:p:h<cr> | |
command! Bclose call <SID>BufcloseCloseIt() | |
function! <SID>BufcloseCloseIt() | |
let l:currentBufNum = bufnr("%") | |
let l:alternateBufNum = bufnr("#") | |
if buflisted(l:alternateBufNum) | |
buffer # | |
else | |
bnext | |
endif | |
if bufnr("%") == l:currentBufNum | |
new | |
endif | |
if buflisted(l:currentBufNum) | |
execute("bdelete! ".l:currentBufNum) | |
endif | |
endfunction | |
" Specify the behavior when switching between buffers | |
try | |
set switchbuf=usetab | |
set stal=2 | |
catch | |
endtry | |
"""""""""""""""""""""""""""""" | |
" => Statusline | |
"""""""""""""""""""""""""""""" | |
" Always hide the statusline | |
set laststatus=2 | |
" Useful status information at bottom of screen | |
" set statusline=[%n]\ %<%.99f\ %h%w%m%r%y\ %{fugitive#statusline()}%{exists('*CapsLockStatusline')?CapsLockStatusline():''}%=%-16(\ %l,%c-%v\ %)%P | |
function! HasPaste() | |
if &paste | |
return 'PASTE MODE ' | |
else | |
return '' | |
endif | |
endfunction | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Parenthesis/bracket expanding | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
vnoremap $1 <esc>`>a)<esc>`<i(<esc> | |
vnoremap $2 <esc>`>a]<esc>`<i[<esc> | |
vnoremap $3 <esc>`>a}<esc>`<i{<esc> | |
vnoremap $$ <esc>`>a"<esc>`<i"<esc> | |
vnoremap $q <esc>`>a'<esc>`<i'<esc> | |
vnoremap $e <esc>`>a"<esc>`<i"<esc> | |
" Map auto complete of (, ", ', [ | |
inoremap $1 ()<esc>i | |
inoremap $2 []<esc>i | |
inoremap $3 {}<esc>i | |
inoremap $4 {<esc>o}<esc>O | |
inoremap $q ''<esc>i | |
inoremap $e ""<esc>i | |
inoremap $t <><esc>i | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => General Abbrevs | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr> | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Editing mappings | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
"Remap VIM 0 | |
map 0 ^ | |
"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 | |
if MySys() == "mac" | |
nmap <D-j> <M-j> | |
nmap <D-k> <M-k> | |
vmap <D-j> <M-j> | |
vmap <D-k> <M-k> | |
endif | |
"Delete trailing white space, useful for Ruby ;) | |
func! DeleteTrailingWS() | |
exe "normal mz" | |
%s/\s\+$//ge | |
exe "normal `z" | |
endfunc | |
autocmd BufWrite *.rb,*.haml,*.erb,Gemfile :call DeleteTrailingWS() | |
set guitablabel=%t | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Cope | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Do :help cope if you are unsure what cope is. It's super useful! | |
map <leader>cc :botright cope<cr> | |
map <leader>n :cn<cr> | |
map <leader>p :cp<cr> | |
"""""""""""""""""""""""""""""" | |
" => bufExplorer plugin | |
"""""""""""""""""""""""""""""" | |
"let g:bufExplorerDefaultHelp=0 | |
"let g:bufExplorerShowRelativePath=1 | |
"map <leader>o :BufExplorer<cr> | |
"""""""""""""""""""""""""""""" | |
" => Minibuffer plugin | |
"""""""""""""""""""""""""""""" | |
"let g:miniBufExplModSelTarget = 1 | |
"let g:miniBufExplorerMoreThanOne = 2 | |
"let g:miniBufExplModSelTarget = 0 | |
"let g:miniBufExplUseSingleClick = 1 | |
"let g:miniBufExplMapWindowNavVim = 1 | |
"let g:miniBufExplVSplit = 25 | |
"let g:miniBufExplSplitBelow=1 | |
"let g:bufExplorerSortBy = "name" | |
"autocmd BufRead,BufNew :call UMiniBufExplorer | |
"map <leader>u :TMiniBufExplorer<cr> | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Omni complete functions | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
autocmd FileType css set omnifunc=csscomplete#CompleteCSS | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Spell checking | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
"Pressing ,ss will toggle and untoggle spell checking | |
map <leader>ss :setlocal spell!<cr> | |
"Shortcuts using <leader> | |
map <leader>sn ]s | |
map <leader>sp [s | |
map <leader>sa zg | |
map <leader>s? z= | |
"""""""""""""""""""""""""""""" | |
" => JavaScript section | |
""""""""""""""""""""""""""""""" | |
au FileType javascript call JavaScriptFold() | |
au FileType javascript setl fen | |
au FileType javascript setl nocindent | |
au FileType javascript imap <c-t> AJS.log();<esc>hi | |
au FileType javascript imap <c-a> alert();<esc>hi | |
au FileType javascript inoremap <buffer> $r return | |
au FileType javascript inoremap <buffer> $f //--- PH ----------------------------------------------<esc>FP2xi | |
function! JavaScriptFold() | |
setl foldmethod=syntax | |
setl foldlevelstart=1 | |
syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend | |
function! FoldText() | |
return substitute(getline(v:foldstart), '{.*', '{...}', '') | |
endfunction | |
setl foldtext=FoldText() | |
endfunction | |
"""""""""""""""""""""""""""""" | |
" => MRU plugin | |
"""""""""""""""""""""""""""""" | |
"let MRU_Max_Entries = 400 | |
"map <leader>f :MRU<CR> | |
"""""""""""""""""""""""""""""" | |
" => Command-T | |
"""""""""""""""""""""""""""""" | |
"let g:CommandTMaxHeight = 15 | |
"set wildignore+=*.o,*.obj,.git,*.pyc | |
"noremap <leader>j :CommandT<cr> | |
"noremap <leader>y :CommandTFlush<cr> | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => MISC | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Remove the Windows ^M - when the encodings gets messed up | |
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm | |
"Quickly open a buffer for scripbble | |
map <leader>q :e ~/buffer<cr> | |
au BufRead,BufNewFile ~/buffer iab <buffer> xh1 =========================================== | |
map <leader>pp :setlocal paste!<cr> | |
map <leader>bb :cd ..<cr> | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Vimcasts Tweaks | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
"Vimcasts, Show invisibles | |
nmap <leader>l :set list!<CR> | |
set listchars=tab:▸\ ,eol:¬ | |
"Vimcasts, irb and vim | |
"Restore cursor position if opened via irb | |
"Note you've to install the interactive_editor gem to make this work | |
"if has("autocmd") | |
" autocmd BufReadPost * | |
" \ if line("'\"") > 1 && line("'\"") <= line("$") | | |
" \ exe "normal! g`\"" | | |
" \ endif | |
"endif | |
" 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 | |
"Vimcasts, Whitespace Preferences and File Types | |
"autocmd BufNewFile,BufRead *.ru,Gemfile,*.lock setfiletype ruby | |
" For the MakeGreen plugin and Ruby RSpec. Uncomment to use. | |
"autocmd BufNewFile,BufRead *_spec.rb compiler rspec | |
"Peepcode Smash Into Vim II at time 27:23 | |
":vmap > >gv | |
":vmap < <gv | |
":imap <Tab> <C-N> | |
" Controversial...swap colon and semicolon for easier commands | |
"nnoremap ; : | |
"nnoremap : ; | |
"vnoremap ; : | |
"vnoremap : ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I uncomment the last chunk that remaps the : to ; the leader key stops to work?
Its just this .vimrc file without any bundles and plugins.
What might be wrong?