Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " File: ~/.vim/vimrc_common
- " Author: Barry Arthur
- set nocompatible " NEVER change this! Use Vim mode, not vi mode
- set rtp+=/usr/share/vim/vimfiles
- call pathogen#infect('bundle/shared')
- filetype plugin indent on " Enable automatic settings based on file type
- syntax on " Enable color syntax highlighting
- source $HOME/.vim/vimrc_${USER}_pre
- """"""""""
- " Options
- """"""""""
- " Use :help 'option (inclduing the ' character) to learn more about each one.
- "
- " Buffer (File) Options:
- set hidden " Edit multiple unsaved files at the same time
- set confirm " Prompt to save unsaved changes when exiting
- " Keep various histories between edits
- set viminfo='1000,f1,<500,:100,/100
- set shortmess=atI " Limit Vim's "hit-enter" messages
- " Search Options:
- set hlsearch " Highlight searches. See below for more.
- set ignorecase " Do case insensitive matching...
- set smartcase " ...except when using capital letters
- set incsearch " Incremental search
- " Insert (Edit) Options:
- set backspace=indent,eol,start " Better handling of backspace key
- set autoindent " Sane indenting when filetype not recognised
- set nostartofline " Emulate typical editor navigation behaviour
- set nopaste " Start in normal (non-paste) mode
- set pastetoggle=<f11> " Use <F11> to toggle between 'paste' and 'nopaste'
- " Status / Command Line Options:
- set wildmenu " Better commandline completion
- set wildmode=list:full " Expand match on first Tab complete
- set showcmd " Show (partial) command in status line.
- set laststatus=2 " Always show a status line
- set cmdheight=2 " Prevent "Press Enter" message after most commands
- " Statusline set below after Function definitions
- " Interface Options:
- set number " Display line numbers at left of screen
- set visualbell " Flash the screen instead of beeping on errors
- set t_vb= " And then disable even the flashing
- set mouse=a " Enable mouse usage (all modes) in terminals
- " Quickly time out on keycodes, but never time out on mappings
- set notimeout ttimeout ttimeoutlen=200
- set updatetime=300 " Preview window timeout
- set previewheight=3
- " Indentation Options:
- set shiftwidth=2 " Number of spaces for each indent level
- set softtabstop=2 " Even when using <Tab>'s
- set expandtab " When pressing <Tab>, replace with spaces
- """"""""""""
- " Functions
- """"""""""""
- function! Var(var, default_val)
- if exists(a:var)
- return eval(a:var)
- else
- return a:default_val
- endif
- endfunction
- function! ToggleRedundantSpaces()
- if exists('b:spacecheck') == 0
- let b:spacecheck = 1
- endif
- if b:spacecheck == 1
- hi clear RedundantSpaces
- let b:spacecheck=0
- else
- hi RedundantSpaces ctermbg=red guibg=red
- let b:spacecheck=1
- endif
- endfunction
- " Use current filetype's comment leader to comment a string
- function! CommentString(...)
- let comment = ''
- if a:0 != 0
- let comment = a:1
- endif
- return substitute(&commentstring, '%s.*', '', '') . ' ' . comment
- endfunction
- " Execute current line
- function! ExecuteLine()
- let save_reg = @@
- normal ^y$
- exe @@
- let @@ = save_reg
- endfunction
- " TODO: Breaks insert mode!
- function! CharCount()
- redir => l:gcount
- silent exe "normal! g\<c-g>"
- redir END
- let l:type = matchstr(l:gcount, '\(Char\|Byte\)')
- return substitute(l:gcount, '.*' . l:type . '\s*\(\d\+\)\s*of\s*\(\d\+\).*', 'Char \1 of \2', '')
- endfunction
- " Show all matches within loaded scripts
- let g:scriptnames = []
- function! ScriptnamesList()
- let l:sn = ''
- redir => l:sn
- silent scriptnames
- redir END
- let g:scriptnames = split(l:sn, "\n")
- return g:scriptnames
- endfunction
- command! -nargs=1 SNMatch echo join(filter(ScriptnamesList(), 'v:val =~ "<args>"'), "\n")
- """""""""""""""""""""""""""""
- " Options requiring Functions
- """""""""""""""""""""""""""""
- "set statusline=%f%m%r%h%w\ [%n:%{&ff}/%Y]%=[0x\%04.4B][%03v][%p%%\ line\ %l\ of\ %L,\ %{CharCount()}]
- set statusline=%f%m%r%h%w\ [%n:%{&ff}/%Y]%=[0x\%04.4B][%03v][%p%%\ line\ %l\ of\ %L]
- """""""
- " Maps
- """""""
- "--------------
- " Function keys
- "--------------
- " F1 to be a context sensitive keyword-under-cursor lookup
- " Deliberately left the <CR> off the end to allow modification at call time
- nnoremap <F1> :help <c-r><c-w>
- " F2 to toggle spelling
- nnoremap <F2> :set invspell<CR>
- " TODO: Change this to TagBar
- " F6 to Toggle the Tag List
- nnoremap <F6> :TlistToggle<CR>
- " F7 to visually select word under cursor
- nnoremap <silent> <F7> :let @*=':help '.expand('<cword>')<CR>
- " F8 to highlight all occurrences of word under cursor
- nnoremap <silent> <F8> :let @/='\<'.expand('<cword>').'\>'<bar>set hls<CR>
- nnoremap <silent> <F9> :tabn 1 <bar> help function-list<CR>
- " TODO: Drop Project?
- " F12 to toggle project window
- nnoremap <silent> <F12> <Plug>ToggleProject
- "------------
- " Leader Maps
- "------------
- " TODO: use g:user_leader and g:user_localleader defined in $HOME/.vim/vimrc_user_pre
- " custom mapleader
- let mapleader = ","
- let maplocalleader = ","
- " quick buffer management
- nnoremap <leader>l :ls<CR>:b<space>
- " highlight redundant spaces at end of line and tabs
- highlight RedundantSpaces ctermbg=red guibg=red
- match RedundantSpaces /\s\+$\|\t\+/
- " toggle RedundantSpaces matching
- nnoremap <silent> <leader>S :call ToggleRedundantSpaces()<CR>
- " toggle list mode
- nnoremap <silent> <leader>L :set list!<bar>:set list?<CR>
- " Append current datetime stamp
- nnoremap <leader>d a<c-r>=strftime('%d %b %Y')<CR><Esc>
- " Execute current line
- nnoremap <silent> <leader>e :call ExecuteLine()<CR>
- " Toggle relative and normal line numbers
- nnoremap <silent> <leader>n :if &relativenumber == 1 \| setlocal number \| else \| setlocal relativenumber \| endif<CR>
- "-----------
- " Other Maps
- "-----------
- " temporarily clear highlighting
- nnoremap <silent> <C-l> :noh<CR><C-l>
- " use jj as an alternate <esc>
- inoremap jj <esc>
- " paragraph formatting
- nnoremap Q gq}
- " Use * in visual mode to search for visual selection
- vnoremap * <Esc>/<c-r>=escape(@*, '\/.*$^~[]')<CR><CR>
- " visual up,down
- nnoremap <Up> gk
- nnoremap <Down> gj
- " move between windows
- nnoremap <C-Up> <C-w>k
- nnoremap <C-k> <C-w>k
- nnoremap <C-Down> <C-w>j
- nnoremap <C-j> <C-w>j
- nnoremap <C-Left> <C-w>h
- nnoremap <C-Right> <C-w>l
- nnoremap <C-p> <C-w>p
- " toggle search highlighting
- nnoremap <C-Bslash> :set hls!<bar>:set hls?<CR>
- inoremap <C-Bslash> <Esc>:set hls!<bar>:set hls?<CR>a
- " change local cd
- nnoremap <leader>cd :lcd %:h<cr>:pwd<cr>
- """"""""""""""""
- " Auto Commands
- """"""""""""""""
- " TODO: Remember wtf I used this for. :-/
- function! LoadBufOption(opts)
- for mop in keys(a:opts)
- echo mop a:opts[mop]
- exe "let b:".mop."='".a:opts[mop]."'"
- endfor
- endfunction
- if has("autocmd")
- augroup filetype
- au!
- " Jump to last-known-position when editing files
- au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
- " My file type maps
- au BufRead,BufNewFile *.rem set ft=remind
- au BufRead .conkyrc set filetype=conkyrc
- " Outliner files use tabs, so disable error highlight
- au BufRead,BufNewFile *.otl set noet | call ToggleRedundantSpaces()
- " text files are in asciidoc format
- au BufNewFile *.txt set filetype=asciidoc | so ~/.vim/scripts/asciidoc.vim
- " automatically fold top-most comment block in C files
- au BufRead *.c set fdm=manual | silent 1/^\/\*/,/^\s*\*\//fo
- " reformatter for xml type files
- :au Filetype html,xml,xsl set equalprg="hindent -cs -i2 -t0 test.xml | sed -e '/^\s*$/d'"
- " lyx
- au BufRead *.lyx set syntax=lyx foldmethod=syntax foldcolumn=3
- au BufRead *.lyx syntax sync fromstart
- " Dokuwiki
- au BufRead,BufNewFile *.doku set filetype=dokuwiki
- " Ruby Omnicomplete
- "au FileType ruby,eruby so ~/.vim/scripts/ruby.vim
- "au BufWritePost *.rb silent !ctags -R
- " Help files
- au FileType help so ~/.vim/scripts/help.vim
- " Omni Completion Based on Syntax
- if has("autocmd") && exists("+omnifunc")
- autocmd Filetype *
- \ if &omnifunc == "" |
- \ setlocal omnifunc=syntaxcomplete#Complete |
- \ endif
- endif
- " TODO: is this redundant with the qxolotl plugin?
- " Remember which window we came from when using a QuickFix command
- au BufReadPost quickfix let w:quickfix_source_win = winnr('#')
- augroup END
- endif
- """""""""""
- " Commands
- """""""""""
- " Help
- command! -nargs=* -complete=help HG helpgrep <args>
- " Better Find-in-File Support
- cabbrev lvim
- \ lvim /\<lt><C-R><C-W>\>/gj
- \ *<C-R>=(expand("%:e")=="" ? "" : ".".expand("%:e"))<CR>
- \ <Bar> lw
- \ <C-Left><C-Left><C-Left>
- " Show all matches in the runtimepath
- command! -nargs=1 RTPMatch echo join(filter(split(&rtp, ','), 'v:val =~ "<args>"'), "\n")
- " Better Diffing
- command DiffOrig let g:diffline = line('.') | vert new | set bt=nofile | r # | 0d_ | diffthis | :exe "norm! ".g:diffline."G" | wincmd p | diffthis | wincmd p
- nnoremap <Leader>do :DiffOrig<cr>
- nnoremap <leader>dc :q<cr>:diffoff<cr>:exe "norm! ".g:diffline."G"<cr>
- """"""""""
- " GVim
- """"""""""
- if has("gui_running")
- set t_vb=
- endif
- """"""""""
- " Plugins
- """"""""""
- " Matchit
- runtime macros/matchit.vim
- " Vim Outliner
- let g:otl_bold_headers = 0
- source $HOME/.vim/vimrc_${USER}_post
Advertisement
Add Comment
Please, Sign In to add comment