" judd@redhat.com " GPTE DevOps Automation " .vimrc geared towards asciidoc and ansible/yaml " " curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ " https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim " " start vim " :PlugInstall set nocompatible " be iMproved, required """""""""""""""""""" " Plugins - vim-plug - START """""""""""""""""""" call plug#begin('~/.vim/plugged') """"" " Language Server client "Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'nvim-lua/lsp-status.nvim' Plug 'neovim/nvim-lspconfig' Plug 'williamboman/nvim-lsp-installer' Plug 'kabouzeid/nvim-lspinstall' Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " We recommend updating the parsers on update Plug 'neomake/neomake' Plug 'hrsh7th/nvim-compe' """"" " Kube Stuff ""Plug 'c9s/helper.vim' ""Plug 'c9s/treemenu.vim' ""Plug 'c9s/vikube.vim' " Esthetics and Syntax and Workflow Plug 'vifm/vifm.vim' Plug 'junegunn/fzf' Plug 'junegunn/fzf.vim' Plug 'flazz/vim-colorschemes' ""Plug 'nathanaelkane/vim-indent-guides' ""Plug 'vim-airline/vim-airline' "Plug 'edkolev/tmuxline.vim' "" amazing async linter - Vim 8 only ""Plug 'w0rp/ale' Plug '907th/vim-auto-save' "Plug 'scrooloose/nerdtree' "Plug 'Xuyuanp/nerdtree-git-plugin' Plug 'airblade/vim-gitgutter' "Plug 'vim-voom/VOoM' Plug 'jeetsukumaran/vim-buffergator' ""-"Plug 'fholgado/minibufexpl.vim' ""-"Plug 'severin-lemaignan/vim-minimap' "a sublime text minimap - useless ""-"Plug 'scrooloose/syntastic' """""" "" Git Plug 'tpope/vim-fugitive' ""Plug 'idanarye/vim-merginal' ""Plug 'tpope/vim-unimpaired' ""Plug 'tpope/vim-rhubarb' ""Plug 'tpope/vim-vinegar' """""" "" Asciidoc """Plug 'matcatc/vim-asciidoc-folding' ""Plug 'asciidoc/asciidoc' ""Plug 'dagwieers/asciidoc-vim' """""" "" Ansible "pearofducks Plug 'pearofducks/ansible-vim' ""Plug 'chase/vim-ansible-yaml' """""" "" Yaml " Plug 'pedrohdz/vim-yaml-folds' " Plug 'stephpy/vim-yaml' """"" "" Json " Plug 'elzr/vim-json' """"" "" Tmux and Terminals ""Plug 'tpope/vim-tbone' ""Plug 'sjl/vitality.vim' ""Plug 'benmills/vimux' """"" "" Trello "Plug 'malithsen/trello-vim' """" "" Diagramming " Plug 'gyim/vim-boxdraw' """" "" spreadsheet, csv handling ""Plug 'chrisbra/csv.vim' call plug#end() " required " filetype plugin indent on " required """""""""""""""""""" " Plugins - vim-plug - END """""""""""""""""""" """""""""""""""""""" " Plugins - Vim8/neoVim - BEGIN """""""""""""""""""" if has('nvim') "Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } "let g:deoplete#enable_at_startup = 1 " else " Plug 'Shougo/deoplete.nvim' " Plug 'roxma/nvim-yarp' " Plug 'roxma/vim-hug-neovim-rpc' endif """""""""""""""""""" " Language Server - CoC """""""""""""""""""" " ru coc.vim " coc docs: " treesitter """""""""""""""""""" " trim white space on write """""""""""""""""""" autocmd BufWritePre * :%s/\s\+$//e """""""""""""""""""" " Short Commands to do great things """""""""""""""""""" " fj will JSON PRETTY-FORMAT your json. """""""""""""""""""" "nnoremap fj :%!python -m json.tool:set nowrap:set ft:javascript :vnoremap fj %!python -m json.tool """""""""""""""""""" " 64 will base64 decode selection with replace """""""""""""""""""" :vnoremap 64 c=system('base64 --decode', @") """""""""""""""""""" " enable fuzzy finder """""""""""""""""""" if filereadable("/usr/local/opt/fzf/plugin/fzf.vim") if executable("/usr/local/opt/fzf/bin/fzf") set rtp+=/usr/local/opt/fzf/bin/fzf else set rtp+=~/.fzf endif endif """""""""""""""""""" " set working dir to current file/buffer """""""""""""""""""" "set autochdir "may break my world """""""""""""""""""" " vertical bar at cursor """""""""""""""""""" set cuc "cursorcolumn " highlight hl-CursorColumn ctermbg=DarkGrey guibg=#010101 set cul "cursorline """""""""""""""""""" " grepping with rg ripgrep """""""""""""""""""" if executable("rg") set grepprg=rg\ --vimgrep\ --no-heading\ --smart-case set grepformat=%f:%l:%c:%m,%f:%l:%m endif nnoremap g :silent lgrep nnoremap [f :lprevious nnoremap ]f :lnext " bind K to grep word under cursor nnoremap K :grep! "\b\b":cw """""""""""""""""""" " Enable the Amazing Linter """""""""""""""""""" " ale settings - linter let g:ale_sign_column_always = 1 let g:ale_set_highlights = 1 let g:ale_list_window_size = 5 " Set this Ale support for Airline let g:airline#extensions#ale#enabled = 1 " Enable completion where available. let g:ale_completion_enabled = 1 """"""""""""""""""" " Enable GitGutter """"""""""""""""""" let g:gitgutter_enabled = 1 """"""""""""""""""" """"""""""""""""""" " Git Stuff """"""""""""""""""" """"""""""""""""""" " g shows commit that introduced current line map g :call setbufvar(winbufnr(popup_atcursor(systemlist("cd " . shellescape(fnamemodify(resolve(expand('%:p')), ":h")) . " && git log --no-merges -n 1 -L " . shellescape(line("v") . "," . line(".") . ":" . resolve(expand("%:p")))), { "padding": [1,1,1,1], "pos": "botleft", "wrap": 0 })), "&filetype", "git") """"""""""""""""""" " Fugitive """"""""""""""""""" " diff merge conflicts mappings " Fugitive Conflict Resolution nnoremap gd :Gvdiffsplit! nnoremap gdh :diffget //2 nnoremap gdl :diffget //3 """"""""""""""""""" " Indentation, Syntax HL, and Status Lines """""""""""""""""""" let g:airline_powerline_fonts = 1 set laststatus=2 " set t_Co=256 syntax enable set tabstop=2 set shiftwidth=2 set expandtab set number set relativenumber set statusline=%<%f\ %h%m%r%{FugitiveStatusline()}%=%-14.(%l,%c%V%)\ %P function! LspStatus() abort if luaeval('#vim.lsp.buf_get_clients() > 0') return luaeval("require('lsp-status').status()") endif return '' endfunction set statusline+=\ %{LspStatus()} " cd to dir of current file nnoremap cd :cd %:p:h:pwd " wildmenu thing. Please review "set wildmode=lastused """"""""""""""""""" " Plugins Stuff " Vim8 only: """"""""""""""""""" " Plugins need to be added to runtimepath before helptags can be generated. if v:version > 800 packloadall endif " Load all of the helptags now, after plugins have been loaded. " All messages and errors will be ignored. helptags ALL """""""""""""""""""""""""""""""" " COLORS """""""""""""""""""""""""""""""" " set termguicolors = 1 " macvim set bg=dark colorscheme Atelier_HeathDark if has('gui_running') if has("gui_macvim") set guifont = 'Source Code Pro for Powerline:h12' let macvim_skip_cmd_opt_movement = 1 colorscheme Atelier_HeathDark endif if has("gui_vimr") " Here goes some VimR specific settings like color darkocean endif endif " mac clipboard set clipboard+=unnamed " tmuxline let g:tmuxline_preset = { \'a' : '#S', \'b' : '#W', \'c' : '#H', \'win' : '#I #W', \'cwin' : '#I #W', \'x' : '#(/bin/bash ~/.tmux/kube.tmux 250 red cyan)', \'y' : '#(cd #{pane_current_path}; git rev-parse --abbrev-ref HEAD)', \'z' : '#H'} " \'w' : '%a %R', """""""""""""""""""" " Workflow """""""""""""""""""" " Open file in Brave :noremap :! open -n -a "Brave Browser" --args --profile-directory="Default" file:///%:p " Open file in Chrome - tried to ensure that filenames are escaped - failed ":noremap :! open -n -a "Google Chrome" --args --profile-directory="Default"; webapi#http#escape(file:///%:p) " TODO: wtf? :map vat``>F """"" " Vimdiff " vimdiff is unreadable - no syntax highlitghting, whitespace, etc. if &diff map ] ]c map [ [c set cursorline syntax off "colorscheme default "set diffopt+=iwhite highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red endif """"" " NERDTREE " Start NERDTree on startup "autocmd vimenter * NERDTree " Jump to the main window, don't start in NERDTree "autocmd VimEnter * wincmd p " For mouse click in NERDTree :set mouse=a "let g:NERDTreeMouseMode=3 " plugin nerdtree-git " let g:NERDTreeShowGitStatus = 1 """""""""""""""""""" " Asciidoc """""""""""""""""""" " asciidoc-folding let g:asciidoc_fold_style = 'nested' " don't fold when opening files - fold them with zc, unfold with zr set nofoldenable """""""""""""""""""" """""""""""""""""""" " mappings for asciidoc text mgmnt "iab _source [source,sh]--------+Expect output to look similar to this:+[source,texinfo]-------- " Wrap vselect with show_solution=true :vmap ss "zdIifeval::[{show_solution} == true]zendif::[] " Wrap vselect with [source,bash] :vmap sb "zdI+[source,bash]----z---- " Wrap vselect with text and [source,text] :vmap st "zdI+.Sample Output:[source,text]----z---- " Wrap vselect with [source,yaml] :vmap sy "zdI+[source,yaml]----z---- " Wrap vselect with [source,ini] :vmap si "zdI+[source,ini]----z----+ " Delete text between ---- :map d-- :silent ,?----?+1d\|,/----/-1dO " Wrap vselect with link:[^] :vmap sl "zxi link:z[^] " Wrap vselect to hide contents :vmap sq "zdi+++
+++_Sample Output:_+++
+++z+++
+++ " Wrap vselect with ==== :vmap sh "zdI====z==== " " New Slide maps :map nsl i== ifdef::showscript[]Transcript:endif::showscript[]8kA " New Slide with slide title from vselected text :map nsn ^"zd$i== "zpaifdef::showscript[]Transcript:endif::showscript[]?== " New Slide with slide transcript from vselected text :vmap nst "zdI== SLIDE TITLEifdef::showscript[]Transcript:zendif::showscript[] " wrap vselected text in transcript :vmap trans "zdIifdef::showscript[]Transcript:zendif::showscript[] " moving between slides - move up/down and put title at home :map zjztzo :map kzkjztzo " change '.headings' to '=== headings' " no longer necessary, I hope ":cmap hf :%s/^\.\(\w\+.*\)$/=== \1/ ":cmap nhf :%s/^=== \(\w\+.*\)$/.\1/ " delete trailing whitespace and replace three or more consecutive line " endings with two line endings :map cleanup :%s/\s\+$//e:%s/\n\{3,}/\r\r/e " Clean up Doc Links - " delete text before [ ] and preservetext found in [ ] :map spp d\[di[va[p " remove everything up to [ ] and preserve insides :map sap d/[di[va[p """""""""""""""""""" """""""""""""""""""" " """""""""""""""""""" " Ansible """""""""""""""""""" " Plug-in vim-ansible-yaml brings up the module documentation if your cursor is in the module name let g:ansible_options = {'documentation_mapping': 'x'} " Remap user-specified binding to look in ansible-doc for keyword under cursor " Doesn't work: "nnoremap J :splitbelow | sview |r !ansible-doc * " Remap user-specified binding to look in ansible-doc for keyword under cursor if exists('g:ansible_options["documentation_mapping"]') exec 'nmap ' . g:ansible_options["documentation_mapping"] . ' :!ansible-doc *' endif " vim:sts=2:sw=2: " dont indent after a blank line let g:ansible_options = {'ignore_blank_lines': 0} "let g:ansible_yamlKeyName = 'yamlKey' "let g:ansible_extra_keyworkds_highlight = 1 "let g:ansible_goto_role_paths = './roles,../_common/roles' function! FindAnsibleRoleUnderCursor() if exists("g:ansible_goto_role_paths") let l:role_paths = g:ansible_goto_role_paths else let l:role_paths = "./roles" endif let l:tasks_main = expand("") . "/tasks/main.yml" let l:found_role_path = findfile(l:tasks_main, l:role_paths) if l:found_role_path == "" echo l:tasks_main . " not found" else execute "edit " . fnameescape(l:found_role_path) endif endfunction " au BufRead,BufNewFile */ansible/*.yml vnoremap gr :call FindAnsibleRoleUnderCursor() """""""""""""""""""" " Tmux and Terminals """""""""""""""""""" "tbone.vim "Basic tmux support for Vim. ":Tmux lets you call any old tmux command (with really good tab complete). ":Tyank and :Tput give you direct access to tmux buffers. ":Twrite sends a chunk of text to another pane. Give an argument like windowtitle.2, top-right, or last, or let it default to the previously given argument. ":Tattach lets you use a specific tmux session from outside of it. """""""""""""""""""" " Commented out: Possibly useful """""""""""""""""""" " """""""""""""" " Movement Shortcuts " Move a line of text using ALT+[jk] or Comamnd+[jk] on mac "nmap mz:m+`z "nmap mz:m-2`z "vmap :m'>+`mzgv`yo`z "vmap :m'<-2`>my` /^==\sz. """"" " nerdtree ignore - everything but _Lab_ "let NERDTreeIgnore=[' " " Fix some mouse reporting for big terminals "if has('mouse_sgr') " set ttymouse=sgr "endif " """""" " Red Hat GPTE " Shortcuts for assessments: " Turn the line FALSE nnoremap F $6bcwFALSE " Turn the line TRUE nnoremap T $6bcwTRUE " Turn the line 1 100 aka correct nnoremap 1 $2bcw1003bcw1 " Turn the line 0 0 aka incorrect nnoremap 0 $2bcw02bcw0 " TRUE/FALSE line nnoremap X ^iCOURSECOURSEMODULE005.TRUE1100 " Multiple Choice line nnoremap M ^iCOURSECOURSEMODULE001?Thing11100 " Shortcuts for Product Names nnoremap O /OpenShiftcwRHOCP """""" "FROM ASCIIDOC PAGE """""" " Show tabs and trailing characters. "set listchars=tab:»·,trail:·,extends:↷,precedes:↶,nbsp:⁔ "set listchars=tab:»·,trail:·,eol:¬,trail:␣,extends:↷,precedes:↶,nbsp:⁔ "set listchars=eol:•,tab:→\ ,trail:␣,extends:↷,precedes:↶,nbsp:⁔ "set list " Reformat paragraphs and list. "nnoremap r gq} " Delete trailing white space and Dos-returns and to expand tabs to spaces. "nnoremap t :set et:retab!:%s/[\r \t]\+$// " autocmd BufRead,BufNewFile *.txt,*.asciidoc,README,TODO,CHANGELOG,NOTES,ABOUT "\ setlocal autoindent expandtab tabstop=8 softtabstop=2 shiftwidth=2 filetype=asciidoc "\ textwidth=70 wrap formatoptions=tcqn "\ formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\\|^\\s*<\\d\\+>\\s\\+\\\\|^\\s*[a-zA-Z.]\\.\\s\\+\\\\|^\\s*[ivxIVX]\\+\\.\\s\\+ "\ comments=s1:/*,ex:*/,://,b:#,:%,:XCOMM,fb:-,fb:*,fb:+,fb:.,fb:> """"""""""""""""""""""""""""""" " Color Switcher - F8 """"""""""""""""""""""""""""""" if v:version < 700 || exists('loaded_switchcolor') || &cp finish endif let loaded_switchcolor = 0 let paths = split(globpath(&runtimepath, 'colors/*.vim'), "\n") let s:swcolors = map(paths, 'fnamemodify(v:val, ":t:r")') let s:swskip = [ '256-jungle', '3dglasses', 'calmar256-light', 'coots-beauty-256', 'grb256' ] let s:swback = 0 " background variants light/dark was not yet switched let s:swindex = 0 function! SwitchColor(swinc) " if have switched background: dark/light if (s:swback == 1) let s:swback = 0 let s:swindex += a:swinc let i = s:swindex % len(s:swcolors) " in skip list if (index(s:swskip, s:swcolors[i]) == -1) execute "colorscheme " . s:swcolors[i] else return SwitchColor(a:swinc) endif else let s:swback = 1 if (&background == "light") execute "set background=dark" else execute "set background=light" endif " roll back if background is not supported if (!exists('g:colors_name')) return SwitchColor(a:swinc) endif endif " show current name on screen. :h :echo-redraw redraw execute "colorscheme" endfunction map :call SwitchColor(1) imap :call SwitchColor(1) map :call SwitchColor(-1) imap :call SwitchColor(-1)