" @Tracked " Author: Tumbler Terrall [TumblerTerrall@gmail.com] " Last Edited: 07/11/2019 03:03 PM " TODO: Can have errors when doing ex commands on directories if the directory name contains a "%" " TODO: Check if $HOME/.vim works just as well on Windows as $HOME/vimfiles "> Settings if (line('$') == 1 && getline(1) == '' && has("gui_running")) set columns=84 set lines=45 endif " If we have a new window, give it a decent size set number " Turn on line numbers set incsearch " When searching with "/" you will see initial matches as you search set hlsearch " Highlight all search matches set makeprg=mk set ruler " Add line and column information to the bottom right of the window set autoindent set smartindent " Intelligently auto-indents when new lines that are created with or "o" set list listchars=tab:>-,trail:·,precedes:<,extends:> " Tabs are shown as >- and trailing spaces are shown as · See? -> " When wrap is off (like when in a diff) and the line extends past the screen, " show < or > to indicate that the line continues set sidescrolloff=20 " Keep 20 characters of context for horizontal scrolling set sidescroll=1 " Scroll one column horizontally as needed set expandtab " Pressing tab will actually put the appropriate amount of spaces (Because tabs are EVIL!!) set shiftwidth=3 set tabstop=3 set softtabstop=3 " Tabs are three characters long set backspace=2 " Make backspace work in insert mode if has("win32") && !has("gui_running") inoremap endif " When in windows-terminal vim, backspace gets mapped to " This will allow ternimal vim to function set ignorecase set smartcase " Make searches be case insensitive unless capital letters are used set showmatch " When an ending bracket (or parin, or brace) is typed, jump to the matching one briefly for confirmation " (Highlighting parin is actually a standard plugin that is turned on by "DoMatchParen") set tags=./tags; " File it looks for to define ctags set winaltkeys=no " Allows us to use the menu shortcuts for ourselves, YAY! (i.e. Alt+h) set autochdir " Automatically sets the pwd to current file as you browse set diffopt=filler,vertical,context:1000000 " Automatically opens diffs with filler lines for sync, vertically " (side-by-side), and with all folds open set wildignore+=*.o,*.obj,*.bak,*.exe,*.aux,*.dvi,*.info,*.d,*.hex,*.map,*.lib,*.swp,*.elf,*.bin,*.out,*.zip,tags,*.lst,*.pp,*.dll,*.lst,*.rlf,*.sdb,*cof,*.dep,*.hxl,*.mcs,*.sym,Nmakefile " vimgrep ignores object files set wildmenu " Tab completing in command-line gives visual menu set shellslash " Uses forward slashes, because Windows is wrong. set directory=$HOME/vimfiles/swap,. " Makes .swp files go here so we don't have to see them, but still get the " benefit from using them (Defaults to current directory if that one is " unavailable for some reason). set undofile set undodir=$HOME/vimfiles/undo " Makes undo's persistant. AKA if you exit a file and then edit again you can " still undo your changes from before. (It's sweet) set undolevels=10000 " Sets undo history to 10K changes (Default is 1000). set sessionoptions=blank,buffers,curdir,folds,globals,localoptions,options,resize,slash,tabpages,winpos,winsize " Save ALL the things when saving sessions set comments+=:\" " How could we forget about vim comments?! if has("gui_running") && has("autocmd") augroup Focus au! autocmd FocusGained * let @" = @+ autocmd FocusLost * let @+ = @" augroup END else set clipboard^=unnamed endif " I often find myself wanting to copy between vims. The clipboard option " works OK for this but wipes out the clipboard when you do basically " anything and can get frustrating if you want to delete a line and " then paste. Now it only wipes out the clipboard when you leave vim. " However, this only works in Gvim. set omnifunc=syntaxcomplete#Complete " Attempt to intelligently fill the omnicomplete by filetype set formatoptions=jrql2 " Remove extra comment headers when [J]oining " When in a comment, [r]eturn will automatically add a comment header " When formatting text, use the indent of the [2]nd line of a paragraph " See :h fo-table for more info " ftplugin kind of overrides this (which is ANNOYING BTW), still figuring out " how I want to handle this (one option is an autocmd that sets fo everytime " you open a new buffer but seems kind of heavy handed). " TODO Trying a fix out and I don't care if it's heavy handed. ">> Plugin settings let g:netrw_sort_sequence='[\/]$,*,\.o$,\.obj$,\.info$,\.d$,\.hex$,\.map$,\.mcp$,\.mcw$,\.lib$,\.swp$,\.bak$,\.lst$,\.rlf$,\.sdb$,\.CVSfolderStatus,\~$' " Change sorting sequence of netrw explorer to leave different filetypes together let g:netrw_sort_options="i" " Case insensitive sorting (still not sure why you would want to sort by case, but whatever) let g:netrw_banner = 0 " Don't show netrw's "helpful" banner at the beginning of every directory let g:netrw_list_hide ="^\.#" " Doesn't show any files that start with .# let do_syntax_sel_menu = 1 " Show filetypes in syntax menu (enables SetSyn() command) if has("win32") let g:loaded_zipPlugin = 1 let g:loaded_zip = 1 " Prevent vim from trying to open zip files (annoying when vimgrepping if not setup) endif let g:projectManager_TagKeyCombo = '' " Changes the mapping for tag under cusor let g:baseConverter_leading_binary_zeros = 1 let g:ale_set_quickfix = 0 let g:ale_set_loclist = 0 let g:ale_sign_column_always = 1 let g:ale_change_sign_column_color = 1 hi SignColumn guibg=#333333 hi ALESignColumnWithoutErrors guibg=#333333 hi ALESignColumnWithErrors guibg=#333333 "<< if has("gui_running") set guioptions-=m " This removes the menu bar from the gui set guioptions-=T " This removes the toolbar from the gui endif filetype indent on " Turn on filetype dependent indenting inoreabbrev ture true " Insert mode abbreviation for misspelling true. " Command line abbreviations: cnoreabbrev h (getcmdtype() == ':' && getcmdline() =~ '^h$')? 'tab help' : 'h' " Help opens in new tab cnoreabbrev w (getcmdtype() == ':' && getcmdline() =~ '^w$')? 'call SaveBuffer(0)' : 'w' cnoreabbrev wq call SaveBuffer(1) cnoreabbrev wy call SaveBuffer(2) cnoreabbrev wqy call SaveBuffer(3) " wf = write force cnoreabbrev wf call SaveBuffer(4) " When saving tracked files, vim will auto-update the last edited info cnoreabbrev qt tabclose " Like :qa, but only closes the current tab cnoreabbrev q (getcmdtype() == ':' && getcmdline() =~ '^q$' && v:char != '!')? 'call Quit()' : 'q' " Intelligently quits out of quickfixes automatically cnoreabbrev D Diffsplit " I use diffsplit a lot, might as well make it easer to type cnoreabbrev qh tabdo if (!buflisted(bufnr('%')) && &modifiable == 0) tabclose endif " Closes all help tabs (Technically all unlisted non-modifiable, but this is usually going to just be help) if has("unix") && !has("gui_running") let c='a' while c <= 'z' exec "set =\e".c exec "imap \e".c." " let c = nr2char(1+char2nr(c)) endwhile set timeout ttimeoutlen=50 endif " Linux terminals have this weird thing where alt commands don't work at all. " I would die without my alt commands so this is a workaround. command! -nargs=1 -complete=file Diffsplit diffsplit | wincmd p " Diff a file and switches focus back on the original file command! Whitespace :call ReplaceBadWhitespaceInDir() " Replaces tabs and trailing whitespace in all files in a directory " Colorscheme moved to plugins so we can use a plugin manager. if !exists("syntax_on") syntax enable endif "< End of Settings "> Mappings " means Ctrl+x " means Alt+x ( means the same thing) " means Shift+x " These commands can be chained. I.E. NOTE: and does not work unless x is an F-key inoremap " Give an alternative to that doesn't take your hand as far off of the keyboard inoremap inoremap cnoremap " Delete is hard to press and is in different places on different keyboards " Basically makes it so that if a line goes over one visual line, " j and k behave intuitively noremap j gj noremap k gk " If you need the default behavior for some reason use this: noremap gj j noremap gk k " Thanks DJMcMayhem, that was a good idea. cnoremap getcmdtype() ==# '@' ? InputHistory(0): '' cnoremap getcmdtype() ==# '@' ? InputHistory(1): '' cnoremap getcmdtype() ==# '@' ? InputHistory(2): '' " When inside an Input() use the up and down arrows for command line recall noremap H :call search('\(^\s\+\)\@<=\S\\|^', 'b', line('.')) " Go to beginning of text (like '^') or beginning of line, whichever comes first noremap L $ " Go to end of line if has("win32") nnoremap K :exe "tab help ".expand('') nnoremap gK :exe "tab help ".expand('') " Opens help on word under cursor in a new tab endif onoremap O v:operator == 'd' ? ':.diffget' : '' onoremap P v:operator == 'd' ? ':.diffput' : '' " Now dO and dP work like do and dp except only obtain/put a single line nnoremap si i_r nnoremap sa a_r " Insert single character " Make copy pasta act like windows. " Because we all know how broken the middle click method is..... " Also sets the paste option temporarily so that vim doesn't try " to auto-indent as it pastes (Almost never what you want). noremap :set paste"+gP:set nopaste inoremap :set paste+:set nopaste cnoremap + vnoremap d"+gP vnoremap "+y cnoremap " inoremap " " "Pastes" the current unnamed register vnoremap J j vnoremap K k nnoremap :call ParagraphToEightyChars() nnoremap :call ParagraphToEightyChars(1) nnoremap J maJ`a " Keep the cursor in the same place when doing a Join inoremap " AutoComplete. (Activated with Ctrl+Space) " Change Focus Between Split Windows nnoremap j inoremap pumvisible() ? "" : "j" " If AutoComplete box is open tab through the menu, otherwise shift focus down nnoremap k inoremap pumvisible() ? "" : "k" " If AutoComplete box is open tab through the menu, otherwise shift focus up nnoremap h " Left nnoremap l inoremap l " Right if version >= 810 tnoremap j tnoremap k tnoremap h tnoremap l endif " Same as the above but for termal splits (Only available starting in 8.1) nnoremap :res +10 inoremap :res +10 nnoremap :vertical res +10 inoremap :vertical res +10 " Increases size of splits incrementally nnoremap search('x\\|\(\<\)', "bpcn") == 1 ? "\vUgUTxFxe" : "\" nnoremap search('x\\|\(\<\)', "bpcn") == 1 ? "\vUgUTxFxe" : "\" " TODO: hax problems when there are actual x's in the preceeding text. " Makes hex digits show up capital when auto-incrementing/decrementing nnoremap @q inoremap @q " Because @ is WAY too hard to hit nnoremap @w inoremap @w " Because sometimes you need two macros nnoremap exists('g:cvsnetrwIntegration')? ":tabnext\:call UpdateCVSHilighting()\" : ":tabnext\" inoremap " Switch to next tab nnoremap :tabmove +1 inoremap :tabmove +1 " Moves tab to the right one position cnoremap " Moves right in the command line nnoremap exists('g:cvsnetrwIntegration')? ":tabprevious\:call UpdateCVSHilighting()\" : ":tabprevious\" inoremap " Switch to previous tab nnoremap :tabmove -1 inoremap :tabmove -1 " Moves tab to the left one position cnoremap " Moves left in the command line nnoremap :call OpenNewTabWithNetrw() inoremap :call OpenNewTabWithNetrw() " Opens a new tab with explorer view, looking at previous file noremap :call ShiftScreen("j") inoremap :call ShiftScreen("j") vnoremap j noremap :call ShiftScreen("k") inoremap :call ShiftScreen("k") vnoremap k " Move cursor and shift window at the same time (I use this everyday) cnoremap cnoremap nnoremap &diffopt=~'iwhite'? ":set diffopt-=iwhite" : ":set diffopt+=iwhite" " Toggles whitespace diffing. nnoremap &diff? "]c" : "" nnoremap &diff? "[c" : "" " Move half a page down and up respectively " or (when in a diff) move to next/previous difference nnoremap .n inoremap .n " Micro Macros :P nnoremap :setlocal spell! spelllang=en_us :let g:spellSuggestionCount = 1 inoremap :setlocal spell! spelllang=en_us :let g:spellSuggestionCount = 1 " Toggle spell check nnoremap ]s ]s:let g:spellSuggestionCount = 1 nnoremap [s [s:let g:spellSuggestionCount = 1 " Finds next/prev spelling mistake (not a change just also clears cycle count) nnoremap ]a :call CycleTrhoughSpellSuggestion() nnoremap [a :call CycleTrhoughSpellSuggestion() " Automatically changes word under cursor to the next suggested word in spell check " (press repeatedly to advance to next word) nnoremap ]q :call BringUpSpellSuggestionList()z= nnoremap [q :call BringUpSpellSuggestionList()z= " Pulls up a list of suggestions for word under cursor (If you've been cycling " it will revert word back to original first). nnoremap ][ ]] nnoremap ]] ][ " This just makes more sense to my brain. nnoremap :call BlockAutoIndent() inoremap :call BlockAutoIndent() " Auto indents current block {} nnoremap C=strftime("%m/%d/%Y %I:%M %p") inoremap C=strftime("%m/%d/%Y %I:%M %p") " Puts current date and time nnoremap :call ToggleReadOnlyBit() " Toggles the read only bit on the file.... Did I really need this comment?? nnoremap :w:make inoremap :w:make " Attempt a make nnoremap :w:!% inoremap :w:!% " Attempt a make for a sripting language nnoremap :call BlockCheck(0) inoremap :call BlockCheck(1) " On first call, pops to the top of current toplevel function. On second call, " returns to the previous location nnoremap :set number! inoremap :set number! " Toggle line numbers nnoremap :call ToggleBinaryMode() inoremap :call ToggleBinaryMode() " Open current file in binary mode nnoremap :set splitright vsplit set nosplitright " Open up a vertical split to the right. (I want my vplits to use splitright, " but I almost never want my diffsplits to. This is my workaround) nnoremap :call OpenVimrc():silent! normal! zO " Opens vimrc (this file) in new tab nnoremap :call OpenVimrc(1):silent! normal! zO " Opens vimrc (this file) in new tab nnoremap :call OpenVimrc()GzR " Opens vimrc (this file) in new tab and jumps to the regular expression section for quick reference. nnoremap :pop " Goes to the previous location in the tag stack inoremap {{ {}k " Auto puts closing brace and indents you to the right place automatically nnoremap za " Toggles current fold (It doesn't seem like much of a shortcut but za is really hard to hit) nnoremap :!start gvim " Opens another gVim instance " Vimgrep nnoremap :exec "ProjectGrep \\<". expand('') ."\\>" nnoremap g :exec "ProjectGrep ". expand('') " * vimgrep: works like * but greps the current directory instead of just the file nnoremap :call NextQuickFix() nnoremap :call NextQuickFix(1) " Jumps to the next/previous item in the quickfix nnoremap :set switchbuf+=newtab:set switchbuf-=newtab " Shift+Enter opens files from quickfix in a new tab nnoremap (&diff)? ':diffoff!w:q' : ':cclose :lclose' inoremap (&diff)? ':diffoff!w:q' : ':cclose :lclose' " Closes diff or quickfix window nnoremap :let @z=@" let @"=@s let @s=@z " Saves the unamed register to register s for later use. Press again to restore. vnoremap csb " Pastes contents of the "saved" register " File stuff map "Alt+G to go to alternate file (Usually the last file edited) vnoremap > >gv vnoremap < exists('g:undotree_TreeNodeShape')?':UndotreeToggle':'' " Give a graphical view of the undo tree (Requires undotree plugin) " (http://www.vim.org/scripts/script.php?script_id=4177) nnoremap :mksession $HOME/vimfiles/Session.vim :qa " Save session and exit (will be re-opened next time vim is launched) nnoremap :call ToggleAutoScroll() inoremap :call ToggleAutoScroll() " Toggles cursor being held in the middle of the screen nnoremap :let b:lastSearch = @/ma/{%y'a:let @/ = b:lastSearch inoremap :let b:lastSearch = @/ma/{%y'a:let @/ = b:lastSearch " Yank C-style block nnoremap :noh inoremap :noh " Clears all highlighting nmap :call VimFunctionDoc() " Adds Tevis style documentation for functions " (Place cursor on function name and press F6) nnoremap :call Javadoc() " Adds Javadoc nnoremap :syn off:syn on:source $MYVIMRC inoremap :syn off:syn on:source $MYVIMRC " Reloads syntax file and vimrc nnoremap :%MkVimball! TumblerVimball nnoremap :call RemoveTrailingWhitespace() retab inoremap :call RemoveTrailingWhitespace() retab " Removes all trailing whitespace in file nnoremap :call setqflist([]) \| cclose " Closes and wipes the quickfix so we can more easily traverse the location list. " (See and inoremap ^< " Don't need Ex mode, but visual block mode is useful vmap exists('g:DVB_TrimWS')? DVB_Drag('left') : '' vmap exists('g:DVB_TrimWS')? DVB_Drag('right') : '' vmap exists('g:DVB_TrimWS')? DVB_Drag('down') : '' vmap exists('g:DVB_TrimWS')? DVB_Drag('up') : '' vmap D exists('g:DVB_TrimWS')? DVB_Duplicate() : '' cnoremap %% %:p:h:t/% " Creates a generalized previous directory as well as file on the command line. "< End of mappings "> Autocommands if has("autocmd") augroup Tumbler au! "Make sure to wipe out previous declarations so we can reload safely " Initialization (can't be called until functions are loaded) autocmd VimEnter * call LoadSession() " If a session was previously saved, load it autocmd VimEnter * if exists('g:loaded_helplink') | let g:helplink_copy_to_registers = ['+', '*', '"'] | endif " Add unnamed register to helplink " Buffer specific stuff autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif " When editing a file, always jump to the last cursor position. autocmd BufReadPost * if (&filetype != 'qf' && !exists('w:ColorColumnID')) | let w:ColorColumnID = matchadd('ColorColumn', '\%81v.') | endif " Highlight the 81st character on the line if it's not the quickfix. autocmd FilterWritePost * if (&diff && exists('w:ColorColumnID')) | call matchdelete(w:ColorColumnID) | unlet w:ColorColumnID | endif " When diffing take out the coloring because it looks like diff highlighting. autocmd BufReadPre * nmap I//$ autocmd BufReadPre * imap I//$ autocmd BufReadPre * nmap ^2x$ autocmd BufReadPre * imap ^2x$ " Generalized quick comments (C-style) autocmd BufReadPost * call SetLineEndings() " Filetype dependent stuff " Perl autocmd FileType perl nmap I#$ autocmd FileType perl imap I#$ autocmd FileType perl nmap ^x$ autocmd FileType perl imap ^x$ " Perl style quick comments autocmd FileType python nmap I#$ autocmd FileType python imap I#$ autocmd FileType python nmap ^x$ autocmd FileType python imap ^x$ " Python style quick comments " HTML autocmd FileType html nmap A-->II