Advertisement
chinmayv

cv_vimrc

Nov 16th, 2011
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 10.54 KB | None | 0 0
  1. " Author: Chinmay Vaishampayan
  2. " This vimrc is derived from Steve Francia's vimrc file.
  3.  
  4. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  5. " Environment {
  6.     set nocompatible        " |This setting prevents vim from emulating the original vi's bugs and limitations.
  7.     "set background=dark    " |dark background
  8. "}
  9. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  10.  
  11.  
  12.  
  13. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  14. " General {
  15.     scriptencoding utf-8
  16.     filetype plugin on
  17.     filetype indent on " |detect filetype and indent accordingly
  18.     set mouse=a        " |autmatic enable mouse usage
  19.     set viewoptions=folds,options,cursor,unix,slash " |better unix / windows compatibility
  20.     set virtualedit=onemore " |allow for cursor beyond last character
  21.     set history=1000    " |increase history size
  22.     set shortmess+=filmnrxoOtT   " |abbrev. of messages (avoids 'hit enter')
  23.  
  24.     au BufWinLeave * silent! mkview  " |make vim save view (state) (folds, cursor, etc)
  25.     au BufWinEnter * silent! loadview " |make vim load view (state) (folds, cursor, etc)
  26.  
  27.     set bufhidden=hide  " |Hide buffer when not in window (to prevent relogin with FTP edit)
  28. " }
  29. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  30.  
  31.  
  32.  
  33. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  34. " VIM UI {
  35.     set background=dark
  36.     colorscheme ir_black
  37.     syntax on               " |Enable syntax highlight
  38.     if has('win32') || has('win64') " |Set the font and font size
  39.         set gfn=Consolas:h15
  40.     endif
  41.     set t_Co=256
  42.     set vb t_vb=        " |Flash screen on invalid command instead of beep
  43.     set showmode        " |Display current mode                        
  44.     set tabpagemax=10   " |only show 15 tabs
  45.    
  46.     if has('cmdline_info')
  47.         set ruler   " |show the ruler
  48.         set rulerformat=%35(%=\:b%n%y%m%r%w\ %l\(%L\),%c%V\ %P%) " |ruler format
  49.         set showcmd         " |show partial commands in status line and
  50.     endif
  51.  
  52.     if has('statusline')
  53.         set laststatus=2
  54.  
  55.         set statusline=%<%F                 " |Filename
  56.         set statusline+=\ %m%r%h%w          " |Options
  57.         set statusline+=\ [b%n:\ %Y/%{&ff}]             " |filetype
  58.         "set statusline+=\ [A=\%03.3b/H=\%02.2B]    " |ASCII / Hexadecimal value of char
  59.         set statusline+=%=%-20.(%l/%L,\ %c%V%)\ %p%%    " |Right aligned file nav info
  60.     endif
  61.  
  62.     set backspace=indent,eol,start 
  63.         set linespace=0     " |No extra spaces between rows
  64.     set nu                      " |Line numbers on
  65.     set showmatch                   " |show matching brackets/parenthesis
  66.     set incsearch                   " |find as you type search
  67.     set hlsearch                    " |highlight search terms
  68.     set winminheight=0              " |windows can be 0 line high
  69.     set ignorecase                  " |case insensitive search
  70.     set smartcase                   " |case sensitive when uc present
  71.     set wildmenu                    " |show list instead of just completing
  72.     set wildmode=list:longest,full  " |comand <Tab> completion, list matches, then longest common part, then all.
  73.     set whichwrap=b,s,h,l,<,>,[,]   " |backspace and cursor keys wrap
  74.     "set scrolloff=3        " |3 lines of offset(in top/bottom) while scrolling
  75. " }
  76. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  77.  
  78.  
  79.  
  80. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  81. " Formatting {
  82.     set nowrap                      " |don't wrap long lines
  83.     set autoindent                  " |indent at the same level of the previous line
  84.     set smartindent         " |Do smart autoindent
  85.     set shiftwidth=4                " |use indents of 4 spaces
  86.     set noexpandtab                 " |tabs are tabs, not spaces
  87.     set tabstop=4                   " |an indentation every four columns
  88.     "set matchpairs+=<:>                " |match, to be used with %
  89.     "set pastetoggle=<F12>              " |pastetoggle (sane indentation on pastes)
  90.     "set comments=sl:/*,mb:*,elx:*/  " |auto format comment blocks
  91.     " Remove trailing whitespaces and ^M chars
  92.     autocmd FileType c,cpp,java,php,js,twig,xml,yml autocmd BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
  93. " }
  94. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  95.  
  96.  
  97.  
  98. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  99. " Key Mappings {
  100.    
  101.     "---------------------------------------
  102.     " Key Mappings not depending on plugins
  103.     "---------------------------------------
  104.  
  105.         " Leader key
  106.             "The default leader is '\', but many people prefer ',' as it's in a standard location
  107.             let mapleader = ','
  108.  
  109.  
  110.         " Save and delete buffers
  111.             nnoremap <Leader>x :w<CR>:bd<CR>
  112.  
  113.  
  114.         " Folding
  115.             " Set space to toggle fold
  116.             nnoremap <space> za    
  117.  
  118.             " ,f to fold code between { }
  119.             nnoremap ,f zfa{       
  120.  
  121.             """ Code folding options
  122.             nmap <leader>f0 :set foldlevel=0<CR>
  123.             nmap <leader>f1 :set foldlevel=1<CR>
  124.             nmap <leader>f2 :set foldlevel=2<CR>
  125.             nmap <leader>f3 :set foldlevel=3<CR>
  126.             nmap <leader>f4 :set foldlevel=4<CR>
  127.             nmap <leader>f5 :set foldlevel=5<CR>
  128.             nmap <leader>f6 :set foldlevel=6<CR>
  129.             nmap <leader>f7 :set foldlevel=7<CR>
  130.             nmap <leader>f8 :set foldlevel=8<CR>
  131.             nmap <leader>f9 :set foldlevel=9<CR>
  132.        
  133.  
  134.         " Autoindent
  135.             "Shortcut to auto indent entire file (ctrl + I)
  136.             nmap <C-I> 1G=G
  137.             imap <C-I> <ESC>1G=Ga
  138.  
  139.  
  140.         " Stupid shift key fixes
  141.             cmap Wq wq
  142.             cmap wQ wq
  143.             cmap Q q
  144.             cmap Tabe tabe
  145.  
  146.  
  147.         " Easier movement between windows
  148.             map <C-J> <C-W>j<C-W>_
  149.             map <C-K> <C-W>k<C-W>_
  150.             map <C-L> <C-W>l<C-W>_
  151.             map <C-H> <C-W>h<C-W>_
  152.  
  153.  
  154.         " Yank from the cursor to the end of the line, to be consistent with C and D.
  155.             nnoremap Y y$
  156.  
  157.  
  158.         " For when you forget to sudo.. save using w!!
  159.             cmap w!! w !sudo tee % >/dev/null
  160.  
  161.  
  162.         " Change Working Directory to that of the current file
  163.             cmap cwd lcd %:p:h
  164.             cmap cd. lcd %:p:h
  165.  
  166.  
  167.         " visual shifting (does not exit Visual mode)
  168.             vnoremap < <gv
  169.             vnoremap > >gv
  170.  
  171.  
  172.         " command for new tab
  173.             nnoremap <Leader>nt :tabnew
  174.  
  175.        
  176.         " command for tab navigation
  177.             map <Leader>, :tabprevious<CR>
  178.             map <Leader>. :tabnext<CR>
  179.  
  180.  
  181.  
  182.         " shortcut to quickly change the folder to apache workspace
  183.             nnoremap <Leader>cd :cd C:\wamp\www\
  184.  
  185.  
  186.         " shortcut to set filetype
  187.             nnoremap <Leader>fth :set filetype=html<CR>
  188.             nnoremap <Leader>ftp :set filetype=php<CR>
  189.             nnoremap <Leader>ftj :set filetype=javascript<CR>
  190.  
  191.  
  192.         " Shortcut to paste in insert mode
  193.             inoremap <C-v> <Esc>"+p`]a
  194.  
  195.  
  196.     "-----------------------------------
  197.     " Key Mappings depending on plugins
  198.     "-----------------------------------
  199.  
  200.         " plugin: checksyntax
  201.             noremap <leader><F5> :CheckSyntax<cr>
  202.  
  203.  
  204.         " plugin: taglist
  205.             "toggle tagList, :TlistToggle, for taglist plugin
  206.             map <F11> :TlistToggle<CR>
  207.  
  208.             "it requires ctags, to make the ctags in windows use <Leader>ct
  209.             nmap <Leader>ct :!C:\ctags58\ctags.exe -R *<CR>
  210.  
  211.  
  212.         " plugin: showmarks
  213.             noremap <leader>s :ShowMarksToggle<cr>
  214.  
  215.  
  216.         " plugin: php-doc
  217.             nmap <leader>d :call PhpDocSingle()<CR>
  218.             vmap <leader>d :call PhpDocRange()<CR>
  219.  
  220.  
  221.         " plugin: BufExplorer
  222.             noremap <leader>b :BufExplorer<cr>
  223.             noremap <leader>bh :BufExplorerHorizontalSplit<cr>
  224.             noremap <leader>bv :BufExplorerVerticalSplit<cr>
  225.  
  226.  
  227.         " plugin: NERDTree
  228.             map <C-e> :NERDTreeToggle<CR>:NERDTreeMirror<CR>
  229.             map <F12> :NERDTreeToggle<CR>:NERDTreeMirror<CR>
  230.             map <F10> :NERDTreeFind<CR>
  231.  
  232.  
  233.         " plugin: writebackup
  234.             nnoremap <Leader>bkp :WriteBackup<CR>
  235.  
  236.  
  237. " }
  238. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  239.  
  240.  
  241.  
  242. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  243. " Plugins (Settings)
  244.     " Key mappings related to plugins are in keymappings section in last{
  245.    
  246.     " plugin: checksyntax
  247.         let g:checksyntax_auto = 1
  248.  
  249.  
  250.     " plugin: taglist
  251.         "gain focus on TlistToggle
  252.         let Tlist_GainFocus_On_ToggleOpen=1
  253.  
  254.         let Tlist_Auto_Highlight_Tag = 1
  255.         let Tlist_Auto_Update = 1
  256.         let Tlist_Exit_OnlyWindow = 1
  257.         let Tlist_File_Fold_Auto_Close = 1
  258.         let Tlist_Highlight_Tag_On_BufEnter = 1
  259.         let Tlist_Use_SingleClick = 1
  260.  
  261.         let g:ctags_statusline=1
  262.         " Override how taglist does javascript
  263.         let g:tlist_javascript_settings = 'javascript;f:function;c:class;m:method;p:property;v:global'
  264.  
  265.         if has('win32') || has('win64')
  266.             let Tlist_Ctags_Cmd='C:\ctags58\ctags.exe'
  267.         endif
  268.  
  269.  
  270.     " plugin: showmarks
  271.         let showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  272.         " Don't leave on by default, use :ShowMarksOn to enable
  273.         let g:showmarks_enable = 0
  274.         " For marks a-z
  275.         highlight ShowMarksHLl gui=bold guibg=LightBlue guifg=Blue
  276.         " For marks A-Z
  277.         highlight ShowMarksHLu gui=bold guibg=LightRed guifg=DarkRed
  278.         " For all other marks
  279.         highlight ShowMarksHLo gui=bold guibg=LightYellow guifg=DarkYellow
  280.         " For multiple marks on the same line.
  281.         highlight ShowMarksHLm gui=bold guibg=LightGreen guifg=DarkGreen
  282.  
  283.  
  284.         " plugin: NERDTree
  285.             let NERDTreeShowBookmarks=1
  286.             let NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr']
  287.             let NERDTreeChDirMode=0
  288.             let NERDTreeQuitOnOpen=1
  289.             let NERDTreeShowHidden=1
  290.             let NERDTreeKeepTreeInNewTab=1
  291.  
  292.     " plugin: supertab
  293.         "let g:SuperTabDefaultCompletionType = "context"
  294.         "let g:SuperTabContextDefaultCompletionType = "<c-x><c-o>"
  295.  
  296.    
  297.     " plugin: writebackup
  298.     if has('win32') || has('win64')
  299.         let g:WriteBackup_BackupDir = 'D:\backups\vim'
  300.     else
  301.         let g:WriteBackup_BackupDir = '~/backups/vim'
  302.     endif
  303.  
  304. " }
  305. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  306. " Backup {
  307.     set backup
  308.     function InitBackupDir()
  309.         let separator = "."
  310.         let parent = $HOME .'/' . separator . 'vim/'
  311.         let backup = parent . 'backup/'
  312.         let tmp    = parent . 'tmp/'
  313.         if exists("*mkdir")
  314.             if !isdirectory(parent)
  315.                 call mkdir(parent)
  316.             endif
  317.             if !isdirectory(backup)
  318.                 call mkdir(backup)
  319.             endif
  320.             if !isdirectory(tmp)
  321.                 call mkdir(tmp)
  322.             endif
  323.         endif
  324.  
  325.         let missing_dir = 0
  326.         if isdirectory(tmp)
  327.             execute 'set backupdir=' . escape(backup, " ") . "/,."
  328.         else
  329.             let missing_dir = 1
  330.         endif
  331.  
  332.         if isdirectory(backup)
  333.             execute 'set directory=' . escape(tmp, " ") . "/,."
  334.         else
  335.             let missing_dir = 1
  336.         endif
  337.  
  338.         if missing_dir
  339.             echo "Warning: Unable to create backup directories: "
  340.  
  341.             . backup ." and " . tmp
  342.             echo "Try: mkdir -p " . backup
  343.  
  344.             echo "and: mkdir -p " . tmp
  345.             set backupdir=.                
  346.  
  347.             set directory=.
  348.         endif
  349.  
  350.     endfunction          
  351.  
  352.     call InitBackupDir()
  353.  
  354. " }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement