Created
October 31, 2013 23:41
-
-
Save osdiab/7258989 to your computer and use it in GitHub Desktop.
vimrc
This file contains 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
execute pathogen#infect() | |
set encoding=utf-8 | |
" STATUSLINE | |
"recalculate the trailing whitespace warning when idle, and after saving | |
autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning | |
"return '[\s]' if trailing white space is detected | |
"return '' otherwise | |
function! StatuslineTrailingSpaceWarning() | |
if !exists("b:statusline_trailing_space_warning") | |
if !&modifiable | |
let b:statusline_trailing_space_warning = '' | |
return b:statusline_trailing_space_warning | |
endif | |
if search('\s\+$', 'nw') != 0 | |
let b:statusline_trailing_space_warning = '[\s]' | |
else | |
let b:statusline_trailing_space_warning = '' | |
endif | |
endif | |
return b:statusline_trailing_space_warning | |
endfunction | |
"return the syntax highlight group under the cursor '' | |
function! StatuslineCurrentHighlight() | |
let name = synIDattr(synID(line('.'),col('.'),1),'name') | |
if name == '' | |
return '' | |
else | |
return '[' . name . ']' | |
endif | |
endfunction | |
"recalculate the tab warning flag when idle and after writing | |
autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning | |
"return '[&et]' if &et is set wrong | |
"return '[mixed-indenting]' if spaces and tabs are used to indent | |
"return an empty string if everything is fine | |
function! StatuslineTabWarning() | |
if !exists("b:statusline_tab_warning") | |
let b:statusline_tab_warning = '' | |
if !&modifiable | |
return b:statusline_tab_warning | |
endif | |
let tabs = search('^\t', 'nw') != 0 | |
"find spaces that arent used as alignment in the first indent column | |
let spaces = search('^ \{' . &ts . ',}[^\t]', 'nw') != 0 | |
if tabs && spaces | |
let b:statusline_tab_warning = '[mixed-indenting]' | |
elseif (spaces && !&et) || (tabs && &et) | |
let b:statusline_tab_warning = '[&et]' | |
endif | |
endif | |
return b:statusline_tab_warning | |
endfunction | |
"recalculate the long line warning when idle and after saving | |
autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning | |
"return a warning for "long lines" where "long" is either &textwidth or 80 (if | |
"no &textwidth is set) | |
" | |
"return '' if no long lines | |
"return '[#x,my,$z] if long lines are found, were x is the number of long | |
"lines, y is the median length of the long lines and z is the length of the | |
"longest line | |
function! StatuslineLongLineWarning() | |
if !exists("b:statusline_long_line_warning") | |
if !&modifiable | |
let b:statusline_long_line_warning = '' | |
return b:statusline_long_line_warning | |
endif | |
let long_line_lens = s:LongLines() | |
if len(long_line_lens) > 0 | |
let b:statusline_long_line_warning = "[" . | |
\ '#' . len(long_line_lens) . "," . | |
\ 'm' . s:Median(long_line_lens) . "," . | |
\ '$' . max(long_line_lens) . "]" | |
else | |
let b:statusline_long_line_warning = "" | |
endif | |
endif | |
return b:statusline_long_line_warning | |
endfunction | |
"return a list containing the lengths of the long lines in this buffer | |
function! s:LongLines() | |
let threshold = (&tw ? &tw : 80) | |
let spaces = repeat(" ", &ts) | |
let long_line_lens = [] | |
let i = 1 | |
while i <= line("$") | |
let len = strlen(substitute(getline(i), '\t', spaces, 'g')) | |
if len > threshold | |
call add(long_line_lens, len) | |
endif | |
let i += 1 | |
endwhile | |
return long_line_lens | |
endfunction | |
"find the median of the given array of numbers | |
function! s:Median(nums) | |
let nums = sort(a:nums) | |
let l = len(nums) | |
if l % 2 == 1 | |
let i = (l-1) / 2 | |
return nums[i] | |
else | |
return (nums[l/2] + nums[(l/2)-1]) / 2 | |
endif | |
endfunction | |
"statusline setup | |
set statusline=%f "tail of the filename | |
"display a warning if fileformat isnt unix | |
set statusline+=%#warningmsg# | |
set statusline+=%{&ff!='unix'?'['.&ff.']':''} | |
set statusline+=%* | |
"display a warning if file encoding isnt utf-8 | |
set statusline+=%#warningmsg# | |
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''} | |
set statusline+=%* | |
set statusline+=%h "help file flag | |
set statusline+=%y "filetype | |
set statusline+=%r "read only flag | |
set statusline+=%m "modified flag | |
"display a warning if &et is wrong, or we have mixed-indenting | |
set statusline+=%#error# | |
set statusline+=%{StatuslineTabWarning()} | |
set statusline+=%* | |
set statusline+=%{StatuslineTrailingSpaceWarning()} | |
set statusline+=%{StatuslineLongLineWarning()} | |
set statusline+=%#warningmsg# | |
set statusline+=%{SyntasticStatuslineFlag()} | |
set statusline+=%* | |
"display a warning if &paste is set | |
set statusline+=%#error# | |
set statusline+=%{&paste?'[paste]':''} | |
set statusline+=%* | |
set statusline+=%= "left/right separator | |
function! SlSpace() | |
if exists("*GetSpaceMovement") | |
return "[" . GetSpaceMovement() . "]" | |
else | |
return "" | |
endif | |
endfunc | |
set statusline+=%{SlSpace()} | |
set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight | |
set statusline+=%c, "cursor column | |
set statusline+=%l/%L "cursor line/total lines | |
set statusline+=\ %P "percent through file | |
set laststatus=2 | |
"{{{Auto Commands | |
" Automatically cd into the directory that the file is in | |
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ') | |
" Remove any trailing whitespace that is in the file | |
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif | |
" Restore cursor position to where it was before | |
augroup JumpCursorOnEdit | |
au! | |
autocmd BufReadPost * | |
\ if expand("<afile>:p:h") !=? $TEMP | | |
\ if line("'\"") > 1 && line("'\"") <= line("$") | | |
\ let JumpCursorOnEdit_foo = line("'\"") | | |
\ let b:doopenfold = 1 | | |
\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) | | |
\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 | | |
\ let b:doopenfold = 2 | | |
\ endif | | |
\ exe JumpCursorOnEdit_foo | | |
\ endif | | |
\ endif | |
" Need to postpone using "zv" until after reading the modelines. | |
autocmd BufWinEnter * | |
\ if exists("b:doopenfold") | | |
\ exe "normal zv" | | |
\ if(b:doopenfold > 1) | | |
\ exe "+".1 | | |
\ endif | | |
\ unlet b:doopenfold | | |
\ endif | |
augroup END | |
"}}} | |
"{{{Misc Settings | |
" Necesary for lots of cool vim things | |
set nocompatible | |
" This shows what you are typing as a command. I love this! | |
set showcmd | |
" Folding Stuffs | |
set foldmethod=marker | |
" Needed for Syntax Highlighting and stuff | |
filetype on | |
filetype plugin on | |
syntax enable | |
set grepprg=grep\ -nH\ $* | |
" Who doesn't like autoindent? | |
set autoindent | |
" Spaces are better than a tab character | |
set expandtab | |
set smarttab | |
" Who wants an 8 character tab? Not me! | |
set shiftwidth=4 | |
set softtabstop=4 | |
" Use english for spellchecking, but don't spellcheck by default | |
if version >= 700 | |
set spl=en spell | |
set nospell | |
endif | |
" Cool tab completion stuff | |
set wildmenu | |
set wildmode=list:longest,full | |
" Enable mouse support in console | |
set mouse=a | |
" Got backspace? | |
set backspace=2 | |
" Line Numbers PWN! | |
set number | |
" Ignoring case is a fun trick | |
set ignorecase | |
" And so is Artificial Intellegence! | |
set smartcase | |
" This is totally awesome - remap jj to escape in insert mode. You'll never type jj anyway, so it's great! | |
inoremap jj <Esc> | |
nnoremap JJJJ <Nop> | |
" Incremental searching is sexy | |
set incsearch | |
" Highlight things that we find with the search | |
set hlsearch | |
" Since I use linux, I want this | |
let g:clipbrdDefaultReg = '+' | |
" When I close a tab, remove the buffer | |
set nohidden | |
" Set off the other paren | |
highlight MatchParen ctermbg=4 | |
" }}} | |
"Status line gnarliness | |
set laststatus=2 | |
set statusline=%F%m%r%h%w\ (%{&ff}){%Y}\ [%l,%v][%p%%] | |
" }}} | |
"{{{ Functions | |
"{{{ Open URL in browser | |
function! Browser () | |
let line = getline (".") | |
let line = matchstr (line, "http[^ ]*") | |
exec "!konqueror ".line | |
endfunction | |
"}}} | |
"{{{Theme Rotating | |
let themeindex=0 | |
function! RotateColorTheme() | |
let y = -1 | |
while y == -1 | |
let colorstring = "inkpot#ron#blue#elflord#evening#koehler#murphy#pablo#desert#torte#" | |
let x = match( colorstring, "#", g:themeindex ) | |
let y = match( colorstring, "#", x + 1 ) | |
let g:themeindex = x + 1 | |
if y == -1 | |
let g:themeindex = 0 | |
else | |
let themestring = strpart(colorstring, x + 1, y - x - 1) | |
return ":colorscheme ".themestring | |
endif | |
endwhile | |
endfunction | |
" }}} | |
"{{{ Paste Toggle | |
let paste_mode = 0 " 0 = normal, 1 = paste | |
func! Paste_on_off() | |
if g:paste_mode == 0 | |
set paste | |
let g:paste_mode = 1 | |
else | |
set nopaste | |
let g:paste_mode = 0 | |
endif | |
return | |
endfunc | |
"}}} | |
"{{{ Todo List Mode | |
function! TodoListMode() | |
e ~/.todo.otl | |
Calendar | |
wincmd l | |
set foldlevel=1 | |
tabnew ~/.notes.txt | |
tabfirst | |
" or 'norm! zMzr' | |
endfunction | |
"}}} | |
"}}} | |
"{{{ Mappings | |
" Open Url on this line with the browser \w | |
map <Leader>w :call Browser ()<CR> | |
" Open the Project Plugin <F2> | |
nnoremap <silent> <F2> :Project<CR> | |
" Open the Project Plugin | |
nnoremap <silent> <Leader>pal :Project .vimproject<CR> | |
" TODO Mode | |
nnoremap <silent> <Leader>todo :execute TodoListMode()<CR> | |
" Open the TagList Plugin <F3> | |
nnoremap <silent> <F3> :Tlist<CR> | |
" Next Tab | |
nnoremap <silent> <C-Right> :tabnext<CR> | |
" Previous Tab | |
nnoremap <silent> <C-Left> :tabprevious<CR> | |
" New Tab | |
nnoremap <silent> <C-t> :tabnew<CR> | |
" Rotate Color Scheme <F8> | |
nnoremap <silent> <F8> :execute RotateColorTheme()<CR> | |
" DOS is for fools. | |
nnoremap <silent> <F9> :%s/$//g<CR>:%s// /g<CR> | |
" Paste Mode! Dang! <F10> | |
nnoremap <silent> <F10> :call Paste_on_off()<CR> | |
set pastetoggle=<F10> | |
" Edit vimrc \ev | |
nnoremap <silent> <Leader>ev :tabnew<CR>:e ~/.vimrc<CR> | |
" Edit gvimrc \gv | |
nnoremap <silent> <Leader>gv :tabnew<CR>:e ~/.gvimrc<CR> | |
" Up and down are more logical with g.. | |
nnoremap <silent> k gk | |
nnoremap <silent> j gj | |
inoremap <silent> <Up> <Esc>gka | |
inoremap <silent> <Down> <Esc>gja | |
" Good call Benjie (r for i) | |
nnoremap <silent> <Home> i <Esc>r | |
nnoremap <silent> <End> a <Esc>r | |
" Create Blank Newlines and stay in Normal mode | |
nnoremap <silent> zj o<Esc> | |
nnoremap <silent> zk O<Esc> | |
" Space will toggle folds! | |
nnoremap <space> za | |
" Search mappings: These will make it so that going to the next one in a | |
" search will center on the line it's found in. | |
map N Nzz | |
map n nzz | |
" Testing | |
set completeopt=longest,menuone,preview | |
inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<c-g>u\<cr>" | |
inoremap <expr> <c-n> pumvisible() ? "\<lt>c-n>" : "\<lt>c-n>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>" | |
inoremap <expr> <m-;> pumvisible() ? "\<lt>c-n>" : "\<lt>c-x>\<lt>c-o>\<lt>c-n>\<lt>c-p>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>" | |
" Fix email paragraphs | |
nnoremap <leader>par :%s/^>$//<CR> | |
"ly$O#{{{ "lpjjj_%A#}}}jjzajj | |
"}}} | |
"{{{Taglist configuration | |
let Tlist_Use_Right_Window = 1 | |
let Tlist_Enable_Fold_Column = 0 | |
let Tlist_Exit_OnlyWindow = 1 | |
let Tlist_Use_SingleClick = 1 | |
let Tlist_Inc_Winwidth = 0 | |
"}}} | |
let g:rct_completion_use_fri = 1 | |
"let g:Tex_DefaultTargetFormat = "pdf" | |
let g:Tex_ViewRule_pdf = "kpdf" | |
filetype plugin indent on | |
syntax on | |
" tmp and backup directories | |
set backup | |
set backupdir=~/.vim/backup | |
set directory=~/.vim/tmp | |
" chdir for files | |
set autochdir | |
" cursor line | |
set cul | |
hi CursorLine term=none cterm=none ctermbg=8 | |
" kill bells | |
set noerrorbells | |
set visualbell | |
set t_vb= | |
" up and down logically | |
inoremap <Down> <C-o>gj | |
inoremap <Up> <C-o>gk | |
" tabs | |
function! Mosh_Tab_Or_Complete() | |
if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w' | |
return "\<C-N>" | |
else | |
return "\<Tab>" | |
endfunction | |
inoremap <Tab> <C-R>=Mosh_Tab_Or_Complete()<CR> | |
" textwidth enforcing, highlighting | |
set tw=79 | |
set fo+=t | |
augroup vimrc_autocmds | |
autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#592929 | |
autocmd BufEnter * match OverLength /\%79v.*/ | |
augroup END | |
" cpp11 syntax | |
au BufNewFile, BufRead *.cpp set syntax=cpp11 | |
" autoformat | |
noremap <F7> :Autoformat<CR><CR> | |
" gjslint checker for js | |
let g:syntastic_javascript_checkers=['gjslint, jshint'] | |
" color theme | |
set t_Co=256 | |
colorscheme luna-term | |
" airline powerline fonts | |
let g:airline_powerline_fonts=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment