set history=300 " Configure the leader for easier access let mapleader = "," let g:mapleader = "," " sudo-trick.. Save precious changes as root, fuck yeah command W w !sudo tee % > /dev/null " Stay centered-ish by pushing lines when scrolling set so=7 " Opening files easier set wildmenu set wildignore=*.o,*~,*.pyc set wildignore+=.git\*,.hg\*,.svn\* " Finding stuff set ignorecase set smartcase " Convert to case sensitive if an uppercase letter is in the search set hlsearch " set incsearch " Jump directly to searchterm.. Not using that all the time " Macro performance set lazyredraw " RegEx magic set magic " Flash matching bracket set showmatch set mat=1 " Turn off annoying elements set noerrorbells set novisualbell set t_vb= set tm=500 " Left margin set foldcolumn=0 " Set syntax highlighting syntax enable " Set colorscheme try colorscheme desert catch endtry " Background setting, set line numbers and the cursor line on current line set background=dark set number set cursorline " Set utf8 as standard encoding set encoding=utf8 " Use Unix as the standard file type set ffs=unix,dos,mac " Navigation set expandtab set smarttab set shiftwidth=2 set tabstop=2 set ai "Auto indent set si "Smart indent set wrap "Wrap lines " Ignore wrapping when moving around on lines map j gj map k gk " Linebreak on 500 characters set lbr set tw=500 " Visual mode pressing * or # searches for the current selection vnoremap * :call VisualSelection('f', '') vnoremap # :call VisualSelection('b', '') " Search just by using space bar map / " Disable highlight map :noh " Close the current buffer map bd :Bclose " Close all the buffers map ba :1,1000 bd! " Tab management map tn :tabnew map to :tabonly map tc :tabclose map tm :tabmove map t :tabnext map :tabn map :tabp map :tabnew " New tab with cur buffer path map te :tabedit =expand("%:p:h")/ " Switch CWD to the directory of the open buffer map cd :cd %:p:h:pwd " Specify the behavior when switching between buffers try set switchbuf=useopen,usetab,newtab set stal=2 catch endtry " Return to last edit position when opening files autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif " Remember info about open buffers on close set viminfo^=% " Always show the status line set laststatus=2 " Format the status line set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l " Remap VIM 0 to first non-blank character map 0 ^ " r to replace text vnoremap r :call VisualSelection('replace', '') " Remove the Windows ^M - when the encodings gets messed up noremap m mmHmt:%s///ge'tzt'm " Toggle paste mode on and off map pp :setlocal paste! function! CmdLine(str) exe "menu Foo.Bar :" . a:str emenu Foo.Bar unmenu Foo endfunction function! VisualSelection(direction, extra_filter) 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 . '/' . ' **/*.' . a:extra_filter) elseif a:direction == 'replace' call CmdLine("%s" . '/'. l:pattern . '/') elseif a:direction == 'f' execute "normal /" . l:pattern . "^M" endif let @/ = l:pattern let @" = l:saved_reg endfunction function! HasPaste() if &paste return 'PASTE MODE ' en return '' endfunction command! Bclose call BufcloseCloseIt() function! 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