"" .vimrc " 2019 " Created by Azuhmier "-------------------------------------------------------------------------------------------------------------------------------------------" "===============================================================" "=========================|| PRESETS ||========================="{{{ "===============================================================" execute pathogen#infect() set nocompatible filetype plugin indent on syntax on if exists("t:term_win")==1 unlet t:term_win endif let g:loaded_matchparen=1 let g:netrw_winsize = 10 let g:netrw_preview = 1 let g:netrw_mousemaps = 0 let g:indentLine_enabled = 0 let g:netrw_use_errorwindow = 0 let g:netrw_liststyle= 0 let g:netrw_keepdir=0 set path=.,/usr/local/Cellar/vim/8.1.2250/share/vim/vim81/**,/Users/Work/Documents/hmofa/**,/Users/Work/.hmofa/**,/Users/Work/.vim/**,/Users/Work ""}}} "============================================================" "=========================|| AUTO CMDS ||===================="{{{ "============================================================" "-------------------" "-----| IEL |-----{{{ "-------------------" augroup IEL au! au InsertEnter * call s:VVenter() au InsertLeave * call s:VVclose() augroup end "-----| s:VVenter() |-----" function s:VVenter() hi cursorlineNR ctermfg=blue ctermbg=yellow endfunction "-----| s:VVclose() |-----" function s:VVclose() hi cursorlineNR ctermfg=white ctermbg=NONE endfunction "}}} "---------------------" "-----| MISC |-----{{{ "---------------------" augroup MISC au! au BufEnter * silent! :lcd%:p:h " automatically changes Vim's working dir to the current file au Filetype perl set commentstring=#%s au Filetype perl set shiftwidth=2 au Filetype perl set tabstop=2 au SourcePre ~/.vimrc set stl= au FileType netrw setl bufhidden=wipe au FileType netrw setl bufhidden=wipe au FileType * setlocal fo=tcq au FileType netrw let g:netrw_bookmarklist= [ \'/Users/Work/.vim/', \'/Users/Work/Documents/hmofa/', \'/Users/Work/Documents/hmofa/pastebin/', \'/Users/Work/Documents/hmofa/pastebin/code_examples/goto_files/', \'/Users/Work/Documents/hmofa/fics/', \'/usr/local/', \'/usr/local/Cellar/', \] augroup END "}}} "}}} "=================================================================" "=========================|| FUNCTIONS ||========================="{{{ "=================================================================" "-------------------------------------" "-----| ReturnHighlightTerm() |-----{{{ "-------------------------------------" function ReturnHighlightTerm(group, term) " Store output of group to variable let l:output = execute('hi ' . a:group) " Find the term we're looking for return matchstr(l:output, a:term.'=\zs\S*') endfunction "}}} "}}} "================================================================" "=========================|| COOMANDS ||========================="{{{ "================================================================" "---------------------" "-----| :SS |------"{{{ "---------------------" command -nargs=0 SS execute "mks! ~/.vim/sessions/hmofa_tagging.vim | mkview! ~/.vim/views/hmofa_tagging.vim | echo 'saved'" "}}} "-----------------------" "-----| :Foobar |------{{{ "-----------------------" command -nargs=+ Foobar call Foobar_fun() " 1) Makes copy of current buffer to register @+ " 2) Makes global substitute on register contents of @+ " 3) Makee line substitutions for every line that matches {pattern} "-----| Foobar_fun() |-----" function Foobar_fun(ARGS) " FUN VARS " let l:args = a:ARGS "-----| MAIN |-----" exe "normal cx" let l:reg_contents = getreg("+") let l:reg_array = split(l:reg_contents,"\n") let l:first_done = 0 for l:line in l:reg_array if l:line =~ "^\[" let l:ops = matchstr(l:line, '\]\[.*\]\zs.*') let l:tags = substitute(l:line, '\V'.l:ops, '', "g") let l:tags = substitute(l:tags, ',\s', ',', "g") let l:tags = substitute(l:tags, '[^\]\[,]\+', ';&;', "g") let l:tags = substitute(l:tags, ',', ' ', "g") let l:line = l:tags.l:ops endif if l:first_done == 0 let @+ = l:line."\n" else let @+ .= l:line."\n" endif let l:first_done = 1 endfor endfunction "}}} "-----------------------" "-----| :Kosher |------{{{ "-----------------------" command -range=% Kosher call Kosher_fun() "-----| s:myfun() |-----" function Kosher_fun() try let l:alt_file = expand('%:p') %y+ | enew | execute 'normal! "+p ggdd' setlocal bufhidden=wipe nobuflisted noswapfile buftype=nofile let l:succeeded = 1 %s/\c\(post.*\)*virgin?*, \|\c\(post.*\)*virgin?*\|\c, \(post.*\)*virgin?*\|\cexperienced?*, \|\cexperienced?*\|\c, experienced?*//g catch if !exists('l:succeeded') echoerr "something went wrong" endif finally endtry let @# = l:alt_file endfunction "}}} "------------------" "-----| :R |-----{{{ "------------------" command -complete=shellcmd -nargs=+ R call s:RunShellCommand() " run terminal command and return STDOUT to a scratch buffer and.... " -complete=shellcmd means tab style completion of shell commands. " - s:RunShellCommand(cmdline) -" "-----| s:RunShellCommand() |-----" function s:RunShellCommand(cmdline) " DRESSING THE ARGUMENTS FOR SHELL EXECUTION let l:cwd_buff = getcwd() let l:expanded_cmdline = a:cmdline for part in split(a:cmdline, ' ') if part[0] =~ '\v[%#<]' "let l:expanded_part = fnameescape(expand(part)) "let l:expanded_cmdline = substitute(l:expanded_cmdline, part, l:expanded_part, '') endif endfor "-----| Remeber Prog Window |-----" let t:prog_win = win_getid() "-----| BUFFER CREATION |-----" " IF - STDOUT window does not exist if exists("t:term_win")==0 vert bo new "exe "normal \J" let t:term_win = win_getid() " ELSEIF - STDOUT window was deleted elseif win_gotoid(t:term_win)==0 vert bo new "exe "normal \J" let t:term_win = win_getid() else silent execute "call win_gotoid(t:term_win)" silent execute "0,$ normal dd" endif execute "cd ".l:cwd_buff "-----| BUFFER WRITING |-----" setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile call setline(1,'you entered: ' . a:cmdline) call setline(2,substitute(getline(1),'.','=','g')) silent execute '$read! '. l:expanded_cmdline silent execute "call win_gotoid(t:prog_win)" endfunction "}}} "-------------------------" "-----| BufOnly |-----{{{ "-------------------------" " " Copyright November 2003 by Christian J. Robinson " " Distributed under the terms of the Vim license. See ":help license". " " Usage: " " :Bonly / :BOnly / :Bufonly / :BufOnly [buffer] " " Without any arguments the current buffer is kept. With an argument the " buffer name/number supplied is kept. "-----| :Bonly |-----" command -nargs=? -complete=buffer -bang Bonly \ :call BufOnly('', '') "-----| :BOnly |-----" command -nargs=? -complete=buffer -bang BOnly \ :call BufOnly('', '') "-----| :Bufonly |-----" command -nargs=? -complete=buffer -bang Bufonly \ :call BufOnly('', '') "-----| :BufOnly |-----" command -nargs=? -complete=buffer -bang BufOnly \ :call BufOnly('', '') "-----| :BufOnly() |-----" function BufOnly(buffer, bang) if a:buffer == '' " No buffer provided, use the current buffer. let l:buffer = bufnr('%') elseif (a:buffer + 0) > 0 " A buffer number was provided. let l:buffer = bufnr(a:buffer + 0) else " A buffer name was provided. let l:buffer = bufnr(a:buffer) endif if l:buffer == -1 echohl ErrorMsg echomsg "No matching buffer for" a:buffer echohl None return endif let l:last_buffer = bufnr('$') let l:delete_count = 0 let l:n = 1 while l:n <= l:last_buffer if l:n != buffer && buflisted(l:n) if a:bang == '' && getbufvar(l:n, '&modified') echohl ErrorMsg echomsg 'No write since last change for buffer' \ n '(add ! to override)' echohl None else silent exe 'bdel' . a:bang . ' ' . l:n if ! buflisted(l:n) let l:delete_count = l:delete_count+1 endif endif endif let l:n = l:n+1 endwhile if l:delete_count == 1 echomsg l:delete_count "buffer deleted" elseif l:delete_count > 1 echomsg l:delete_count "buffers deleted" endif endfunction "}}} ""}}} "===============================================================" "=========================|| MAPS ||=========================={{{ "===============================================================" let mapleader = "-" nnoremap K :bn nnoremap gx yiW:!open " & nnoremap cx :%y+ nnoremap p "+p nnoremap gf nnoremap ev :e $MYVIMRC nnoremap sv :tabdo source $MYVIMRC nnoremap i nnoremap o o nnoremap O O "vim.txt em "protocals ep "note en "journel entry ej noremap k :tabp noremap j :tabn noremap J :tabmove+ noremap K :tabmove- noremap t :IndentLinesToggle vnoremap y "+y vnoremap // y/\V" inoremap jj "------------------------------" "-----| |---------------{{{ "------------------------------" nnoremap :call InsertTime() inoremap :call InsertTime() fun InsertTime() let l:CurrentTime = strftime("%a %m/%d/%y %X") exe "normal i" . l:CurrentTime endfun "}}} "------------------------------" "-----| |---------------{{{ "------------------------------" nnoremap :call Ins_head()i inoremap :call Ins_head() fun Ins_head() let l:CurrentTime = strftime("%a %m/%d/%y %X") let l:File_Name = getreg("%") let l:string = "#===============================================================================\r \#\r \# FILE: " . l:File_Name . "\r \#\r \# DESCRIPTION: \r \#\r \# AUTHOR: Azuhmier (aka taganon), azuhmier@gmail\.com\r \# ORGANIZATION: HMOFA\r \# VERSION: 1.0\r \# Created: " . l:CurrentTime . "\r \#===============================================================================\r" exe 'normal i' . l:string . "\?DESCRIPTION: \\zs \" endfun "}}} "-------------------------------" "-----| |---------------{{{ "-------------------------------" nnoremap d :call Ins_bot()i inoremap d :call Ins_bot() fun Ins_bot() let l:string = "#-----| |-----#" exe 'normal i' . l:string . "\?|\h" endfun "}}} "-------------------------------" "-----| |---------------{{{ "-------------------------------" nnoremap s :call Ins_mid()i inoremap s :call Ins_mid() fun Ins_mid() let l:string = "#----------------------------------------------#\r \#-----| |---------------#\r \#----------------------------------------------#\r" exe 'normal i' . l:string . "\?|\h" endfun "}}} "-------------------------------" "-----| |---------------{{{ "-------------------------------" nnoremap a :call Ins_top()i inoremap a :call Ins_top() fun Ins_top() let l:string = "#=============================================================================================#\r \#==================================|| ||===================================#\r \#=============================================================================================#" exe 'normal i' . l:string . "\?|\nh" endfun "}}} "--------------------" "-----| -dp |------{{{ "--------------------" noremap dp :call FUN_startprofile() fun FUN_startprofile() exe 'profile start profile.log' exe 'profile func *' exe 'profile file *' echo 'profiling' endfun "}}} "------------------------------" "-----| netrw_mapping |------{{{ "------------------------------" fun! ExampleUserMap(islocal) exe 'normal jp' let retval= ["refresh"] return retval endfun fun! ExampleUserMap_2(islocal) exe 'normal kp' let retval= ["refresh"] return retval endfun fun! ExampleUserMap_3(islocal) exe 'Ex ~' let retval= ["refresh"] return retval endfun let g:Netrw_UserMaps = [["\h","ExampleUserMap_2"],["\n","ExampleUserMap"],["~","ExampleUserMap_3"]] "}}} "-----------------------------" "-----| -g |---------------{{{ "-----------------------------" nnoremap g :call LoadPerlModule() function! LoadPerlModule() execute 'e `perldoc -l ' . expand("") . '`' endfunction "}}} "----------------------------" "-----| cd |---------------{{{ "----------------------------" nnoremap cd :e. "}}} "-------------------" "-----| -cd |------{{{ "-------------------" nnoremap cd :EXD command EXD call EXBD() function EXBD() silent execute ":e." try silent execute ":bd#" catch finally endtry endfunction "}}} "------------------" "-----| -r |-----{{{ "------------------" nnoremap r :W " runs the file of the current buffer in its respective interpretor and/or " ...compiler "-----| :W |-----" command W call W_run() "-----| W_run() |-----{{{ function W_run() let l:file_types = {'perl':'perl','php':'php','vim':'so','python':'python','cpp':'g++','c':'gcc'} if has_key(l:file_types,&filetype) let l:path = expand('%:p') if &filetype == 'vim' silent execute "w ".l:path execute "source ".l:path elseif &filetype == 'cpp' silent execute "w ".l:path let l:path_2 = substitute(l:path,'\.cpp','\.out',"") execute "R g++ ".l:path." -o ".l:path_2 execute "R ".l:path_2 elseif &filetype == 'c' silent execute "w ".l:path let l:path_2 = substitute(l:path,'\.c','\.out',"") execute "R gcc ".l:path." -o ".l:path_2 execute "R ".l:path_2 else silent execute "w ".l:path silent exe "R ".l:file_types[&filetype]." ".l:path endif else echoerr "Not A Executable File!" endif endfunction "}}} "}}} "------------------" "-----| -R |-----{{{ "------------------" nnoremap R :Win "-----| :W_in |-----" command Win call W_arg() "-----| W_arg() |-----" function W_arg() let l:file_types = {'perl':'perl','php':'php','python':'python'} if has_key(l:file_types,&filetype) let l:input = input("Insert ARGS: ") let l:path = expand('%:p') silent execute "w ".l:path silent execute "R ".l:file_types[&filetype]." ".l:path." ".l:input else echoerr "Not A Executable File!" endif endfunction "}}} "---------------------" "-----| |-----{{{ "---------------------" nnoremap :LSA "-----| :LSA |-----" command LSA call s:getLS() let w:BH=[] " declare the window variable 'BH' as a list "-----| s:getLS() |-----" function s:getLS() " IF STATEMENT - no saving attempts to help files if expand('%:p') =~ '/usr/local/Cellar/vim/8.1.1900/share/vim/vim81/doc/.*.txt' setlocal buftype=nofile nobuflisted endif try " IF STATEMENT - no saving attempts to buffers of type 'nofile' if &buftype !='nofile' execute ':w' else endif catch finally endtry " IF STATEMENT - determins if the current file is a netrw directory (need to change it to unloaded) if getftype(expand('%:p')) != 'dir' if &buftype != 'nofile' let l:curbuf=bufnr("%") "get current buffer number as 'curbuf' call add(w:BH, string(l:curbuf)) "add the current buffer number to the end of the list 'BH' endif endif " IF STATEMENTS - keep 'BH' from having duplicates and/or getting too large if len(w:BH) > 1 if w:BH[0] == w:BH[-1] "checks whether the first and last elements of the list 'BH' are equal let w:BH = [string(l:curbuf)] "set the list 'BH' to the buffer number endif endif " get list of buffer numbers that are non visible redir @"|silent execute 'ls'|redir END|enew|put setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile " try statment for when there are no non-visible loaded buffers try " cleaning up the :ls output redir @"|silent execute 'g/\_^\s*\d\+\s.[^a]'|redir END|enew|silent put setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile silent execute '%s/\d\+\s*\d\+\zs.*\_$\ze//' " if try was sucessful let l:succeeded=1 silent execute '%s/\_^\s*\d*\s\+//' silent execute '%g/^$/d' let l:buff=getline(1, '$') " sets 'buff' as list of buff numbers of buffers that are not visible let l:LL = len(w:BH) " get length of list 'BH' let l:LL -= 1 " subtracts the value of LL by one " FOR LOOP - find the index of every member of 'BH' in the list 'Buff' for i in range(0,l:LL) let l:qqq=index(l:buff, w:BH[i]) " returns a -1 if w:BH[i] is not a member of buff " IF STATMENT if l:qqq ==-1 " checks if any members of w:BH or visible buffers elseif l:qqq != -1 call remove(l:buff, l:qqq) " removes buffnumbers that are already in 'BH' endif endfor " manipulating buff and moving to next buff let l:buff = buff + w:BH silent execute "b ". l:buff[0] " Catch statment catch if !exists('l:succeeded') let w:BH = [] execute ':bp' | echom 'ERROR: no non-visible buffers' endif finally endtry endfunction "-----| AU - defines 'w:BH' when new tab |-----" augroup LSA" au! au TabNew * call s:ExistBH() function s:ExistBH() if exists("w:BH")==0 let w:BH = [] endif endfunction "-----| AU - defines 'w:BH' when new window |-----" au WinNew * call s:ExistBHH() function s:ExistBHH() if exists("w:BH")==0 let w:BH = [] endif endfunction augroup end "}}} "-------------------" "-----| -f |------{{{ "-------------------" " Toggles hilighting the entire current line nnoremap f :call WB() function WB() if ReturnHighlightTerm('CursorLine', 'ctermbg') == 231 hi CursorLine cterm=NONE ctermfg=NONE ctermbg=NONE else hi CursorLine cterm=NONE ctermfg=darkgrey ctermbg=white endif endfunction "}}} "------------------" "-----| + |------{{{ "------------------" nnoremap + :call HS() function HS() if &hlsearch == 1 set nohlsearch else set hlsearch hi search ctermbg=blue ctermfg=gray endif endfunction "}}} "------------------" "-----| S |------{{{ "------------------" nnoremap S :call VE_toggle() function VE_toggle() if &ve == 'onemore' set ve=all else set ve=onemore endif echo &ve endfunction "}}} "=======================================================================" "=========================|| OPTIONS/HILIGHTS ||========================"{{{ "=======================================================================" set ruler " ruler d oes not work when statusline is manually set by user set wildmenu set wildmode=list:longest,full set foldmethod=marker set report=0 set ve=onemore "------------------------------------------------" "-----| MOUSE/KEYBOARD Tabs and Titles |------{{{ "------------------------------------------------" set mouse=a set selection=exclusive set number set tabstop=2 set shiftwidth=2 set smarttab set expandtab " The expandtab property will ensure that when you hit tab it will actually use spaces. set autoindent set backspace=indent,eol,start " To allow backspacing over everything in insert mode (including automatically inserted indentation, line breaks and start of insert) "}}} "------------------------" "-----| SESSION |------{{{ "------------------------" set ssop-=options " do not store global and local values in a session set ssop-=folds " do not store foldw "}}} "-----------------------" "-----| SEARCH |------{{{ "-----------------------" set shortmess-=S " shows search count message when searching "}}} "-----------------------------------" "-----| TABS/TITLES/STATUS |------{{{ "-----------------------------------" " tab pages line, where there are no labels hi TabLineFill cterm=NONE ctermfg=white ctermbg=black hi TabLine cterm=underline ctermfg=white ctermbg=black hi TabLineSel cterm=NONE ctermfg=white ctermbg=darkgrey hi Title cterm=NONE ctermfg=white ctermbg=NONE hi VertSplit ctermfg=grey set showtabline=2 " the '!' means to treat the following as a expression set tabline=%!MyTabLine() "-----| MyTabline() |-----{{{ fun MyTabLine() let s = '' let t = tabpagenr() " current tab number let i = 1 while i <= tabpagenr('$') let buflist = tabpagebuflist(i) " list of buffer numbers let winnr = tabpagewinnr(i) " number of windows let s .= '%' . i . 'T' let s .= (i == t ? '%1*' : '%2*') let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#') let bufnr = buflist[winnr - 1] let file = bufname(bufnr) let buftype = getbufvar(bufnr, '&buftype') let nwins = tabpagewinnr(i, '$') if nwins > 1 let s .= ' '.nwins endif "-| filename |-" if buftype == 'help' let file = 'help:' . fnamemodify(file, ':t:r') elseif buftype == 'quickfix' let file = 'quickfix' elseif buftype == 'nofile' let file = '[scratch]' else let file = pathshorten(fnamemodify(file, ':t')) if getbufvar(bufnr, '&modified') let file = '+' . file endif endif if file == '' && buftype != 'nofile' 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 endfun "}}} " StatusLine hi statusline cterm=NONE ctermfg=white ctermbg=darkgrey hi StatusLineNC cterm=NONE ctermfg=black ctermbg=darkgrey set laststatus=2 " To display the status line always set statusline+=%F " Full path to the file in the buffer. set statusline+=%= " Separation point between left and right aligned items. set statusline+=%c/%l/%L " Evaluate expression between '%{' and '}' and substitute result. "}}} "---------------------------" "-----| CursorLine |------{{{ "---------------------------" set cursorline hi LineNr cterm=NONE ctermfg=red ctermbg=NONE hi Cursor cterm=NONE ctermfg=white ctermbg=blue hi CursorLineNR cterm=NONE ctermfg=white ctermbg=NONE hi CursorLine cterm=NONE ctermfg=NONE ctermbg=NONE "}}} "-------------------------" "-----| Spelling |------{{{ "-------------------------" hi SpellLocal ctermbg=blue "}}} "-----------------------" "-----| FORMAT |------{{{ "-----------------------" set fo=tcq set wrap set linebreak set nolist " list disables linebreak "}}} "-------------------------" "-----| SPELLING |------{{{ "-------------------------" hi SpellBad ctermbg=red "}}} "-----------------------" "-----| SYNTAX |-----{{{ "-----------------------" hi Comment ctermfg = 27 hi Folded ctermfg=6 ctermbg = 236 "}}} "}}}