" --------------------------------------------------------------------------------------------------------------------- " ==> .vimrc " --------------------------------------------------------------------------------------------------------------------- " ==> Some settings from Vim Zero: https://www.oliversherouse.com/posts/vim_zero.html " syntax enable filetype plugin on " General let mapleader = '\' set autoread " set to auto read when a file is changed from the outside set belloff=all " no sound/flash on errors set cursorcolumn " highlight current column set cursorline " highlight current row set formatoptions-=ro " Turn off autoinsert of comment char on newline set hidden " Allow background buffers without saving set nolist " do not show invisible characters set nocompatible " be iMproved, required set number " turn on line numbers set path+=** " Search Globally set relativenumber " lines are numbered relative to current line set ruler " show cursor poition set scrolloff=10 " number of lines to keep above and below the cursor set showmatch " show matching brackets when text indicator is over them set splitright " Split to right by default set term=xterm-256color " LOTS of colors set wildmenu " enhanced command line completion " Text Wrapping set textwidth=120 " Set textwidth set colorcolumn= " disable colorzing column set nowrap " turn off word wrapping at " Search and Substitute set gdefault " use global flag by default in s: commands set hlsearch " highlight searches set ignorecase " ignore case in searches set incsearch " make search act like search in modern browsers set smartcase " don't ignore capitals in searches " Tabs set tabstop=4 set softtabstop=4 set shiftwidth=4 set expandtab autocmd! bufwritepost .vimrc source ~/.vimrc " When vimrc is edited, reload it " Turn line numbers on/off for active/inactive buffers augroup BgHighlight autocmd! autocmd WinEnter * set number autocmd WinEnter * set relativenumber autocmd WinLeave * set nonumber autocmd WinLeave * set norelativenumber augroup end " Toggle invisible characters with set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:< noremap :set list! inoremap :set list! cnoremap :set list! " Enable Omnicomplete features set omnifunc=syntaxcomplete#Complete " Personal Notes settings " export NOTES_DIR= before use " Go to index of notes and set working directory nnoremap ww :e $NOTES_DIR/Index.md:cd $NOTES_DIR " [ to grep inside Notes files " I got the idea from here [step 6: search contents of your notes](https://www.edwinwenink.xyz/posts/42-vim_notetaking/#step-6-search-contents-of-your-notes) command! -nargs=1 Ngrep vimgrep "" $NOTES_DIR/**/*.md | copen nnoremap [ :Ngrep " --------------------------------------------------------------------------------------------------------------------- " ==> Plugins with VimPlug " A minimalist Vim plugin manager " https://github.com/junegunn/vim-plug if has("win32") call plug#begin('~/vimfiles/plugged') else call plug#begin('~/.vim/plugged') endif " Think of sensible.vim as one step above 'nocompatible' mode: a universal set of defaults that (hopefully) everyone can agree on " https://github.com/tpope/vim-sensible Plug 'tpope/vim-sensible' " One stop shop for vim colorschemes " https://github.com/flazz/vim-colorschemes Plug 'flazz/vim-colorschemes' " Command Line Fuzzy Finder " https://github.com/junegunn/fzf Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } Plug 'junegunn/fzf.vim' " Fugitive is the premier Vim plugin for Git. Or maybe it's the premier Git plugin for Vim? Either way, " it's so awesome, it should be illegal. That's why it's called Fugitive " https://github.com/tpope/vim-fugitive Plug 'tpope/vim-fugitive' " Vim surround " I tried to do this from scratch, but it seems this is the best alternative " https://github.com/tpope/vim-surround Plug 'tpope/vim-surround' " Vim Markdown " Suggestions from [Writing Markdown in Vim](https://codeinthehole.com/tips/writing-markdown-in-vim/) " [Vim Markdown](https://github.com/preservim/vim-markdown) Plug 'godlygeek/tabular' Plug 'preservim/vim-markdown' " Vim Spellsync " Magically rebuild Vim spell files if word lists are modified outside of Vim " https://github.com/micarmst/vim-spellsync Plug 'micarmst/vim-spellsync' " Vim Bullets " I tried for too long to get Martkdown bullet to work right. " https://github.com/bullets-vim/bullets.vim Plug 'bullets-vim/bullets.vim' " Vim Airline " Lean & mean status/tabline for vim that's light as air. " https://github.com/vim-airline/vim-airline Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' call plug#end() " --------------------------------------------------------------------------------------------------------------------- " ==> Plugin Options " Options and overrides for installed plugins " Vim Markdown " Markdown syntax highlighting for specified languages let g:markdown_fenced_languages = ['html', 'python', 'ini', 'vim', 'bash', 'yaml'] " Set default conceallevel to hide links and some formatting set conceallevel=0 " strikethrough let g:vim_markdown_strikethrough = 1 " follow anchors - allow to follow anchors just like links let g:vim_markdown_follow_anchor = 1 " turn off auto-bullets and indent so `gq` works correctly let g:vim_markdown_auto_insert_bullets=0 let g:vim_markdown_new_list_item_indent=0 let g:vim_markdown_frontmatter = 1 let g:vim_markdown_folding_disabled = 1 " Open folds by default au BufWinEnter * normal zR " bullets-vim let g:bullets_enabled_file_types = [ 'markdown', 'gitcommit' ] let g:bullets_outline_levels = ['num', 'abc', 'std*', 'std+', 'std-'] "vim-airline let g:airline#extensions#tabline#enabled = 1 let g:airline_theme = 'angr' " FZF Actions " to copy FZF result into current buffer let g:fzf_action = { \ 'ctrl-t': 'tab split', \ 'ctrl-x': 'split', \ 'ctrl-v': 'vsplit', \ 'ctrl-o': ':r !echo'} " --------------------------------------------------------------------------------------------------------------------- " ==> Colors " Term GUI Colors " Testing different colorschemes " Only the last uncommented colorscheme will be used " This is typically a history of the schemes I've used "colorscheme slate "colorscheme marklar "colorscheme automation "colorscheme advantage "colorscheme industry "colorscheme industrial colorscheme jelleybeans " cursorcolumn hi cursorcolumn cterm=NONE ctermbg=black ctermfg=white " visual mode colors hi visual cterm=NONE ctermbg=darkyellow ctermfg=white set fillchars=vert:│,fold:┈,diff:┈ " In split windows - active buffer status bar is green, inactive is yellow hi StatusLine ctermfg=white ctermbg=darkgreen cterm=bold hi StatusLineNC ctermfg=darkgray ctermbg=gray cterm=none " --------------------------------------------------------------------------------------------------------------------- " => Keymaps: Highlights " to turn off search highlight nnoremap :nohls " C to toggle row/column highlight nnoremap C :set cursorline! cursorcolumn! " --------------------------------------------------------------------------------------------------------------------- " ==> Keymaps: Buffers & Panes " -arrow left/right to navigate BUFFERS map [1;5D :bp map [1;5C :bp " b to open FZF buffers map b :Buffers " a to abandon buffer nnoremap a :bd! " c to close buffer nnoremap c :bd " to save buffer nnoremap :w " to bring up the copy buffer noremap "+ " -arrow keys to navigate panes " UP map [1;3A " DOWN map [1;3B " LEFT map [1;3D " RIGHT map [1;3C " CLOSE map x q " --------------------------------------------------------------------------------------------------------------------- " ==> Keymaps " to open FZF files map :Files " --------------------------------------------------------------------------------------------------------------------- " ==> Keymaps: Text bubbling (http://vimcasts.org/episodes/bubbling-text/) " Bubble single lines nmap ddkP nmap ddp " Bubble multiple lines vmap xkP`[V`] vmap xp`[V`] " --------------------------------------------------------------------------------------------------------------------- " ==> Keymaps: Movement keys " Navigate according to displayed lines, not physical lines nnoremap j gj nnoremap k gk " --------------------------------------------------------------------------------------------------------------------- " ==> Keymaps: Date and Time stamps imap =strftime("%Y-%m-%d %H:%M:%S") imap =strftime("%Y-%m-%d %a") imap =strftime("%Y-%m-%d") " --------------------------------------------------------------------------------------------------------------------- " ==> Spellcheck " auto-complete spelling suggestions with set complete+=kspell autocmd FileType markdown setlocal complete+=kspell autocmd FileType text setlocal complete+=kspell autocmd FileType gitcommit setlocal complete+=kspell " Toggle spell check highlights with nnoremap :setlocal spell! spelllang=en_us " ==> Spellcheck: only certain file types " https://robots.thoughtbot.com/vim-spell-checking " turn off for files with no extension autocmd BufRead,BufNewFile * setlocal nospell " turn off for files with any extension autocmd BufRead,BufNewFile *.* setlocal nospell " turn on for markdown files autocmd BufRead,BufNewFile *.md setlocal spell " turn on for text files autocmd BufRead,BufNewFile *.txt setlocal spell " ==> Spellcheck Colors " " I hate spellcheck's default colors " (http://stackoverflow.com/questions/6008921/how-do-i-change-the-highlight-style-in-vim-spellcheck) " Vim Colors: (http://alvinalexander.com/linux/vi-vim-editor-color-scheme-syntax) hi clear SpellBad hi clear SpellCap hi clear SpellLocal hi clear SpellRare hi SpellBad cterm=underline ctermbg=black ctermfg=red hi SpellCap cterm=underline ctermbg=black ctermfg=magenta hi SpellLocal cterm=underline ctermbg=black ctermfg=gray hi SpellRare cterm=underline ctermbg=black ctermfg=gray " --------------------------------------------------------------------------------------------------------------------- " ==> Templates: markdown documents (.md) " " autocmd BufNewFile *.md so $HOME/.vim/templates/md " autocmd BufNewFile *.md %s/filename/\=expand('%:t:r')/g " autocmd BufNewFile *.md exe "g/^- Created :.*/s//- Created : " .strftime("%Y-%m-%d") " autocmd BufNewFile *.md exe "normal Go" " autocmd BufWritePre,filewritepre *.md execute "normal! ma" " autocmd BufWritePre,filewritepre *.md exe "g/^- Updated :.*/s//- Updated : " .strftime("%Y-%m-%d %H:%M") " autocmd BufWritePost,filewritepost *.md execute "normal! `a" " --------------------------------------------------------------------------------------------------------------------- " ==> Templates: markdown documents with frontmatter (.md) autocmd BufNewFile *.md so $HOME/.vim/templates/mdfm "autocmd BufNewFile *.md %s/filename:.*/s//filename:\=expand('%:t:r') "autocmd BufNewFile *.md %s/filename:.*/\='filename: '.expand('%:t:r') autocmd BufNewFile *.md exe "g/^filename:.*/s//filename: " .expand('%:t:r') autocmd BufNewFile *.md exe "g/^filecreated:.*/s//filecreated: " .strftime("%Y-%m-%d") autocmd BufNewFile *.md exe "normal Go" autocmd BufWritePre,filewritepre *.md execute "normal! ma" autocmd BufWritePre,filewritepre *.md exe "g/^fileupdated:.*/s//fileupdated: " .strftime("%Y-%m-%d %H:%M") autocmd BufWritePost,filewritepost *.md execute "normal! `a" " --------------------------------------------------------------------------------------------------------------------- " ==> Templates: shell scripts (.sh) autocmd BufNewFile *.sh so $HOME/.vim/templates/sh autocmd BufNewFile *.sh :%s/filename/\=expand('%:t:r')/g autocmd BufNewFile *.sh exe "g/CREATED:.*/s//CREATED: " .strftime("%Y-%m-%d") autocmd BufNewFile *.sh exe "normal Go" autocmd BufWritePre,filewritepre *.sh execute "normal ma" autocmd BufWritePre,filewritepre *.sh exe "g/UPDATED:.*/s//UPDATED: " .strftime("%Y-%m-%d %H:%M") autocmd bufWritePost,filewritepost *.sh execute "normal `a" " --------------------------------------------------------------------------------------------------------------------- " ==> Snippets " Pasting pre-made things " section banner nnoremap ,ban :-1read $HOME/.vim/templates/bannerjA " section begin/end nnoremap ,begend :-1read $HOME/.vim/templates/begendjA " section shell script header nnoremap ,sh :0read $HOME/.vim/templates/sh :1dd :4%s/filename/\=expand('%:t')/g " section readinglist header "nnoremap ,rl :0read $HOME/.vim/templates/readinglist :1dd $ nnoremap ,rl :0read $HOME/.vim/templates/rlfm zR :1dd :%s/^filename:/\="filename: " . expand('%:t:r')/g " section markdown file header "nnoremap ,md :0read $HOME/.vim/templates/md :1dd :%s/filename/\=expand('%:t:r')/g nnoremap ,md :0read $HOME/.vim/templates/mdfm zR :1dd :%s/^filename:/\="filename: " . expand('%:t:r')/g " --------------------------------------------------------------------------------------------------------------------- " ==> NetrwTreeListing readonly fix (https://vi.stackexchange.com/a/13012) " Per default, netrw leaves unmodified buffers open. This autocommand " deletes netrw's buffer once it's hidden (using ':q', for example) autocmd FileType netrw setl bufhidden=delete " --------------------------------------------------------------------------------------------------------------------- " ==> yaml stuff (https://lornajane.net/posts/2018/vim-settings-for-working-with-yaml) " autocmd BufNewFile,BufReadPost *.{yaml,yml} set filetype=yaml foldmethod=indent autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab