" I just copied stuff from all over the internet and built a decent .vimrc """ """ Mappings """ noremap map :w:source ~/.vimrc map :w map! :wl map :q map :bw map :mksession! ~/.vim/session:quitall map :tabnew map r "_dd noremap r r "map d :g/^[^0g]/d map d V/^ -d map c :s/^/#/j map s qaq map a "Add map p "AP map Q gq map Y y$ map "_x map "_X map $l map :redo noremap noremap! noremap noremap! " copy-paste map "+dd map "+yy vmap "+d vmap "+y map "+P map v "+P$l " In visual mode, C-r starts a search-replace on selection vmap :%s/*//gc map i map :nohl:TabopsSortByPath map :tabp map :tabn map ä :tabp map ö :tabn map 1 1gt map 2 2gt map 3 3gt map 4 4gt map 5 5gt map 6 6gt map 7 7gt map 8 8gt map 9 9gt map 0 10gt "map ggVG$ " Insert literal inoremap " search next nmap n vmap n inoremap n cmap w!! w !sudo tee > /dev/null % map q @q map w :set wrap! map! å set nocompatible set viminfo+=n$HOME/.vim/.viminfo """ """ Colors """ colorscheme desert set background=dark autocmd ColorScheme * highlight WildMenu ctermfg=160 ctermbg=black cterm=bold autocmd ColorScheme * highlight StatusLine ctermfg=39 ctermbg=black cterm=none "autocmd ColorScheme * highlight StatusLineFill ctermbg=black guibg=black autocmd ColorScheme * highlight TabLine guibg=black ctermbg=black cterm=none ctermfg=39 autocmd ColorScheme * highlight TabLineFill guibg=black ctermbg=black autocmd ColorScheme * highlight TabLineSel ctermbg=black ctermfg=160 cterm=bold "autocmd ColorScheme * highlight Title ctermfg=LightBlue ctermbg=Magenta autocmd ColorScheme * highlight Normal guibg=black autocmd ColorScheme * highlight Visual ctermbg=22 cterm=none autocmd ColorScheme * highlight Search cterm=none ctermfg=grey ctermbg=24 autocmd ColorScheme * highlight Identifier cterm=none au BufRead,BufNewFile *.log setfiletype irc """ """ Settings """ set fileencodings=ucs-bom,utf-8,latin1 set enc=utf-8 set tenc=utf-8 set noswapfile set history=50 " keep 50 lines of command line history set noruler " show the cursor position all the time set showcmd " display incomplete commands set incsearch " do incremental searching set showmode set wrap set complete=.,w,b,u,U,t,i,d set hlsearch set t_Co=256 set autoindent smartindent copyindent " always set autoindenting on set smarttab set shiftwidth=4 set softtabstop=4 set tabstop=4 "set expandtab set guicursor+=a:blinkon0 set hidden set wildmenu " Better command-line completion set wildmode=longest,list,full set showcmd " Show partial commands in the last line of the screen " Use case insensitive search, except when using capital letters set ignorecase set smartcase " Allow backspacing over autoindent, line breaks and start of insert action set backspace=indent,eol,start " Stop certain movements from always going to the first character of a line. " While this behaviour deviates from that of Vi, it does what most users " coming from other editors would expect. set nostartofline " Always display the status line, even if only one window is displayed "set laststatus=2 " Instead of failing a command because of unsaved changes, instead raise a " dialogue asking if you wish to save changed files. set confirm set novisualbell set t_vb= " Enable use of the mouse for all modes set mouse=a " Display line numbers on the left set nonumber " Quickly time out on keycodes, but never time out on mappings set notimeout ttimeout ttimeoutlen=200 set ruler set pastetoggle= set pastetoggle= set nobackup set whichwrap=b,s,[,],<,>,h,l " allow cursor to wrap between lines set virtualedit=all " allow virtual editing in Visual block mode set lazyredraw " don't redraw screen while executing macros/mappings set scrolloff=1 " minimal number of screen lines to keep above and below the cursor set showtabline=2 " always show tab page labels " for virtualedit=onemore set virtualedit=block,onemore cnoreabbr Q q nohl syntax on filetype indent plugin on if !exists(":DiffOrig") command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis \ | wincmd p | diffthis endif """ """ Tabline """ if has('gui') set guioptions-=e endif if exists("+showtabline") function! MyTabLine() let s = '' let t = tabpagenr() let i = 1 while i <= tabpagenr('$') let buflist = tabpagebuflist(i) let winnr = tabpagewinnr(i) let s .= '%' . i . 'T' let s .= (i == t ? '%1*' : '%2*') let s .= ' ' let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#') let s .= i . ' ' " let s .= winnr . '/' . tabpagewinnr(i,'$') " let s .= ' %*' " let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#') let bufnr = buflist[winnr - 1] let file = bufname(bufnr) let buftype = getbufvar(bufnr, 'buftype') if buftype == 'nofile' if file =~ '\/.' let file = substitute(file, '.*\/\ze.', '', '') endif else let file = fnamemodify(file, ':p:t') endif if file == '' let file = '[No Name]' endif let s .= file let s .= ' ' let i = i + 1 endwhile "let s .= '%T%#TabLineFill#%=' "let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X') return s endfunction set stal=2 set tabline=%!MyTabLine() map :tabnext imap :tabnext map :tabprev imap :tabprev endif """ """ The rest is functions for tabs """ if !exists('g:Tabops_prefix') let g:Tabops_prefix = '' endif if !exists('g:Tabops_useGoto') let g:Tabops_useGoto = 1 endif if !exists('g:Tabops_useMove') let g:Tabops_useMove = 1 endif if !exists('g:Tabops__closedTabHistory') let g:Tabops__closedTabHistory = [] " [{'b': closed bufnr, 't': placed position}] endif augroup Tabops autocmd! "to setting key mappings autocmd BufEnter * call Tabops_onBufEnter() "to handle closing a tab autocmd BufLeave * call Tabops_onBufLeave() autocmd TabLeave * call Tabops_onTabLeave() autocmd BufWinLeave * call Tabops_onBufWinLeave() augroup END command! TabopsSortByPath :call Tabops_sortByPath() command! TabopsSortByBufnr :call Tabops_sortByBufnr() command! TabopsSortByLastChange :call Tabops_sortByLastChange() command! TabopsReopenClosedTab :call Tabops_reopenClosedTab() command! TabopsUniq :call Tabops_uniq() function! s:Tabops_onBufEnter() if g:Tabops_useGoto call s:Tabops__enableCtrlGoto() call s:Tabops__enableNumberGoto() endif if g:Tabops_useMove call s:Tabops__enableMove() endif endfunction "if this is 1, do not record closing tabs. let s:Tabops__reopening = 0 "nop when these are 0. let s:Tabops__leavingBufferNumber = 0 let s:Tabops__leavingTabNumber = 0 function! s:Tabops_onBufLeave() if s:Tabops__reopening | return | endif let s:Tabops__leavingBufferNumber = bufnr('%') endfunction function! s:Tabops_onTabLeave() if s:Tabops__reopening | return | endif let s:Tabops__leavingTabNumber = tabpagenr() endfunction function! s:Tabops_onBufWinLeave() if s:Tabops__reopening | return | endif if s:Tabops__leavingBufferNumber == 0 || s:Tabops__leavingTabNumber == 0 | return | endif call insert(g:Tabops__closedTabHistory, {'b': s:Tabops__leavingBufferNumber, 't': s:Tabops__leavingTabNumber}, 0) let g:Tabops__closedTabHistory = g:Tabops__closedTabHistory[:4] endfunction function! s:Tabops__enableCtrlGoto() noremap :tabnext noremap :tabprevious endfunction function! s:Tabops__enableNumberGoto() execute 'noremap '.g:Tabops_prefix."1 :call \Tabops__goto(1)" execute 'noremap '.g:Tabops_prefix."2 :call \Tabops__goto(2)" execute 'noremap '.g:Tabops_prefix."3 :call \Tabops__goto(3)" execute 'noremap '.g:Tabops_prefix."4 :call \Tabops__goto(4)" execute 'noremap '.g:Tabops_prefix."5 :call \Tabops__goto(5)" execute 'noremap '.g:Tabops_prefix."6 :call \Tabops__goto(6)" execute 'noremap '.g:Tabops_prefix."7 :call \Tabops__goto(7)" execute 'noremap '.g:Tabops_prefix."8 :call \Tabops__goto(8)" execute 'noremap '.g:Tabops_prefix.'9 :tablast' endfunction function! s:Tabops__enableMove() execute 'noremap '.g:Tabops_prefix."l :call \Tabops__swapNext()" execute 'noremap '.g:Tabops_prefix."h :call \Tabops__swapPrev()" endfunction " " uniq-ing " function! s:Tabops_uniq() let tabs = [] " fillin each value for i in range(1, tabpagenr('$')) let value = s:Tabops_sortByBufnr__Evalfunc(i) call extend(tabs, [{'nr':i, 'value':value, 'dup':0}]) endfor " sort by bufnr call sort(tabs, 's:Tabops_uniq__sortByBufnr') " find duplicates & mark latter ones for i in range(tabpagenr('$'), 2, -1) if tabs[i - 2].value == tabs[i - 1].value let tabs[i - 1].dup = 1 endif endfor " re-sort by tabnr call sort(tabs, 's:Tabops_uniq__sortByTabnr') " close tabs let ld = &lazyredraw let &lazyredraw = 1 for i in range(tabpagenr('$'), 1, -1) if tabs[i - 1].dup call s:Tabops__goto(tabs[i - 1].nr) tabclose endif endfor let &lazyredraw = ld endfunction function! s:Tabops_uniq__sortByBufnr(v1, v2) return (a:v1.value . ':' . a:v1.nr) == (a:v2.value . ':' . a:v2.nr) ? 0 : (a:v1.value . ':' . a:v1.nr) > (a:v2.value . ':' . a:v2.nr) ? 1 : -1 endfunction function! s:Tabops_uniq__sortByTabnr(v1, v2) return a:v1.nr == a:v2.nr ? 0 : a:v1.nr > a:v2.nr ? 1 : -1 endfunction " " sorting " function! s:Tabops_sortByPath() call s:Tabops__sortByHoge(function('s:Tabops_sortByPath__Evalfunc'), function('s:Tabops_sortByPath__Cmpfunc')) endfunction function! s:Tabops_sortByPath__Evalfunc(tabidx) return expand('#'.tabpagebuflist(a:tabidx)[0].':p') endfunction function! s:Tabops_sortByPath__Cmpfunc(v1, v2) return a:v1.value == a:v2.value ? 0 : a:v1.value > a:v2.value ? 1 : -1 endfunction function! s:Tabops_sortByLastChange() call s:Tabops__sortByHoge(function('s:Tabops_sortByLastChange__Evalfunc'), function('s:Tabops_sortByLastChange__Cmpfunc')) endfunction function! s:Tabops_sortByLastChange__Evalfunc(tabidx) call s:Tabops__goto(a:tabidx) "let currbufnr = bufnr('%') redir => ul_as_str silent undolist redir END let ul = split(ul_as_str, '\n')[1:] if len(ul) == 0 return '' else let lastchange = matchstr(ul[-1], '\V\(\d\+:\d\+:\d\+\)') if lastchange !~ '\V\(\d\+:\d\+:\d\+\)' let seconds = 0 + matchstr(ul[-1], '\V\(\d\+\)', '\1', '') let lastchange = strftime('%H:%M:%S', localtime() - seconds) endif return lastchange endif endfunction function! s:Tabops_sortByLastChange__Cmpfunc(v1, v2) if a:v1.value == a:v2.value return 0 elseif a:v1.value == '' return 1 elseif a:v2.value == '' return -1 else "undolist doesn't have DATE column... let now = strftime('%H:%M:%S', localtime()) if a:v1.value > now && a:v2.value > now || a:v1.value < now && a:v2.value < now return a:v1.value < a:v2.value ? 1 : -1 elseif a:v2.value > now return 1 else return -1 endif endif endfunction function! s:Tabops_sortByBufnr() call s:Tabops__sortByHoge(function('s:Tabops_sortByBufnr__Evalfunc'), function('s:Tabops_sortByBufnr__Cmpfunc')) endfunction function! s:Tabops_sortByBufnr__Evalfunc(tabidx) return tabpagebuflist(a:tabidx)[0] endfunction function! s:Tabops_sortByBufnr__Cmpfunc(v1, v2) return a:v1.value == a:v2.value ? 0 : a:v1.value > a:v2.value ? 1 : -1 endfunction function! s:Tabops__sortByHoge(Evalfunc, Cmpfunc) let tabs = [] let currtabidx = tabpagenr() let ld = &lazyredraw let &lazyredraw = 1 "fillin each values for i in range(1, tabpagenr('$')) let value = a:Evalfunc(i) call extend(tabs, [{'src':i, 'value':value}]) "echom i-1.' src: '.i.', value: '.value endfor "sort call sort(tabs, a:Cmpfunc) "where should i goto, after moving let desttabidx = 1 for i in range(1, len(tabs)) let elem = tabs[i - 1] if elem.src == currtabidx let desttabidx = i endif endfor "move for i in range(1, len(tabs)) let elem = tabs[i - 1] if i != elem.src call s:Tabops__goto(elem.src) execute 'tabmove ' . string(i - 1) for j in range(i + 1, len(tabs)) if elem.src >= tabs[j - 1].src let tabs[j - 1].src = tabs[j - 1].src + 1 endif endfor endif endfor call s:Tabops__goto(desttabidx) let &lazyredraw = ld endfunction " " other operations " function! s:Tabops_reopenClosedTab() if len(g:Tabops__closedTabHistory) == 0 | return | endif let top = g:Tabops__closedTabHistory[0] let g:Tabops__closedTabHistory = g:Tabops__closedTabHistory[1:] let ld = &lazyredraw let &lazyredraw = 1 let s:Tabops__reopening = 1 silent tablast silent tabedit silent execute string(top.b).'b ' for i in range(tabpagenr('$')) if i == top.t | continue | endif call s:Tabops__swapPrev() endfor let s:Tabops__reopening = 0 let s:Tabops__leavingBufferNumber = 0 let s:Tabops__leavingTabNumber = 0 let &lazyredraw = ld endfunction " " utilities " function! s:Tabops__goto(tabindex) silent execute 'tabnext ' . string(a:tabindex) endfunction function! s:Tabops__swapNext() let lasttabidx = tabpagenr('$') - 1 let tabidx = tabpagenr() - 1 if tabidx == lasttabidx let desttabidx = 0 else let desttabidx = tabidx + 1 endif execute 'tabmove ' . string(desttabidx) endfunction function! s:Tabops__swapPrev() let lasttabidx = tabpagenr('$') - 1 let tabidx = tabpagenr() - 1 if tabidx == 0 let desttabidx = lasttabidx else let desttabidx = tabidx - 1 endif execute 'tabmove ' . string(desttabidx) endfunction