Created
May 8, 2025 16:57
-
-
Save crh0831/710172dfab2a5c2559216e9da6e3b49e to your computer and use it in GitHub Desktop.
20250508_vimrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> .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-=rot " 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 | |
if !has('nvim') | |
set term=xterm-256color " LOTS of colors | |
endif | |
set wildmenu " enhanced command line completion | |
" Text Wrapping | |
set colorcolumn= " disable colorzing <textwidth> column | |
set nowrap " turn off word wrapping at <textwidth> | |
" 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 <F5> | |
set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:< | |
noremap <F5> :set list!<CR> | |
inoremap <F5> <C-o>:set list!<CR> | |
cnoremap <F5> <C-c>:set list!<CR> | |
" Enable Omnicomplete features | |
set omnifunc=syntaxcomplete#Complete | |
" Personal Notes settings | |
" export NOTES_DIR=<your notes directory> before use | |
" Go to index of notes and set working directory | |
nnoremap <leader>nn :e $NOTES_DIR/index.md<CR>:cd $NOTES_DIR<CR> | |
" <leader>[ 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 "<args>" $NOTES_DIR/**/*.md | copen | |
nnoremap <leader>[ :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 <ge> 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_detect_theme_from_guicolors = 1 | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> FZF Helper Functions | |
" | |
" Configure FZF default key bindings (actions) within the FZF window | |
" 'ctrl-x': Open in horizontal split | |
" 'ctrl-v': Open in vertical split | |
" 'ctrl-t': Open in new tab (optional, common) | |
" 'ctrl-p': Paste raw filename(s) at cursor | |
" 'ctrl-l': Paste formatted [[wiki link]] at cursor | |
" NOTE: Define these functions BEFORE they are used in g:fzf_action below. | |
" Function to paste FZF selection(s) at the current cursor position | |
function! PasteFzfSelection(lines) | |
if type(a:lines) != type([]) || empty(a:lines) | |
echoerr "FZF Paste Error: No selection passed to function PasteFzfSelection." | |
return | |
endif | |
" Join multiple selections with a space | |
let text_to_paste = join(a:lines, ' ') | |
" Insert the text | |
call feedkeys('i' . text_to_paste . "\<esc>", 'ni') | |
endfunction | |
" Function to paste FZF selection as a formatted wiki link | |
function! PasteFzfWikiLink(lines) | |
if type(a:lines) != type([]) || empty(a:lines) | |
echoerr "FZF Paste Error: No selection passed to function PasteFzfWikiLink." | |
return | |
endif | |
" Typically you only link one file at a time | |
let filename = a:lines[0] | |
" --- CHOOSE YOUR LINK FORMAT --- | |
" Option 1: Wiki format [[filename_without_extension]] | |
"let filename_base = fnamemodify(filename, ':r') " Removes the extension | |
"let link_text = '[[' . filename_base . ']]' | |
" Option 2: Wiki format [[filename_with_extension]] | |
let link_text = '[[' . filename . ']]' | |
" Option 3: Markdown format [filename](filename) | |
" let link_text = '[' . filename . '](' . filename . ')' | |
" --- End Formatting Options --- | |
" Insert the formatted link | |
call feedkeys('i' . link_text . "\<esc>", 'ni') | |
endfunction | |
let g:fzf_action = { | |
\ 'ctrl-x': 'split', | |
\ 'ctrl-v': 'vsplit', | |
\ 'ctrl-t': 'tab split', | |
\ 'ctrl-p': function('PasteFzfSelection'), | |
\ 'ctrl-l': function('PasteFzfWikiLink') | |
\ } | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> Colors | |
" Term GUI Colors | |
" colorscheme replaced by ~/.vimcustom | |
" If there is a file at ~/.vimcustom, the colorscheme defined in that file | |
" will be applied. If not, colorscheme defaults to 'darkburn' | |
" cursorcolumn | |
"hi cursorcolumn cterm=NONE ctermbg=black ctermfg=white | |
" visual mode colors | |
"hi visual cterm=NONE ctermbg=lightyellow ctermfg=black | |
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 | |
" <leader><space> to turn off search highlight | |
nnoremap <leader><space> :nohls <enter> | |
" <leader>C to toggle row/column highlight | |
nnoremap <leader>C :set cursorline! cursorcolumn!<CR> | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> Keymaps: Buffers & Panes | |
" <ctrl>-arrow left/right to navigate BUFFERS | |
map <esc>[1;5D :bp <enter> | |
map <esc>[1;5C :bn <enter> | |
" <leader>b to open FZF buffers | |
map <leader>b :Buffers<CR> | |
" <leader>m to open file marks | |
map <leader>m :Marks<CR> | |
" <leader>a to abandon buffer | |
nnoremap <leader>a :bd! <enter> | |
" <leader>c to close buffer | |
nnoremap <leader>c :bd <enter> | |
" <c-s> to save buffer | |
nnoremap <c-s> :w<CR> | |
" <c-x> to bring up the copy buffer | |
noremap <c-x> "+ | |
" <alt>-arrow keys to navigate panes | |
" UP | |
map <esc>[1;3A <c-w><c-k> | |
" DOWN | |
map <esc>[1;3B <c-w><c-j> | |
" LEFT | |
map <esc>[1;3D <c-w><c-h> | |
" RIGHT | |
map <esc>[1;3C <c-w><c-l> | |
" CLOSE | |
map <esc>x <c-w>q | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> Keymaps | |
" <leader><leader> to open FZF files | |
map <leader><leader> :Files<CR> | |
" <leader>g to open FZF Git files | |
map <leader>g :GFiles<CR> | |
" Map <leader>f to open FZF with word under cursor pre-populated | |
" https://github.com/junegunn/fzf.vim/issues/1235#issuecomment-773726008 | |
nnoremap <leader>f :call fzf#run(fzf#vim#with_preview(fzf#wrap({'source': 'find . \( -name .git -o -name .stversions \) -prune -o -print -iname "*'.expand("<cword>").'*"', 'sink': 'e', 'options': '--query="'.expand("<cword>").'"'})))<CR> | |
" Toggles line wrapping with linebreak enabled when wrapping is turned on with <leader>w | |
nnoremap <leader>w :execute "if &wrap\n set nowrap\nelse\n set wrap linebreak\nendif"<CR> | |
" Toggle line numbers | |
nnoremap <leader>n :set number! relativenumber!<CR> | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> Keymaps: Text bubbling (http://vimcasts.org/episodes/bubbling-text/) | |
" Bubble single lines | |
nmap <c-k> ddkP | |
nmap <c-j> ddp | |
" Bubble multiple lines | |
vmap <c-k> xkP`[V`] | |
vmap <c-j> xp`[V`] | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> Keymaps: Movement keys | |
" Navigate according to displayed lines, not physical lines | |
nnoremap j gj | |
nnoremap k gk | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> Keymaps: Date and Time stamps | |
" Send date and time | |
imap <F2> <C-R>=strftime("%Y-%m-%d %H:%M:%S")<CR> | |
" Send date and DOW | |
imap <F3> <C-R>=strftime("%Y-%m-%d %a")<CR> | |
" alternate keybinding I use in VS Code | |
imap <C-S-i> <C-R>=strftime("%Y-%m-%d %a")<CR> | |
" Sends date | |
imap <F4> <C-R>=strftime("%Y-%m-%d")<CR> | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> Spellcheck | |
" auto-complete spelling suggestions with <ctrl-p> | |
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 <F10> | |
nnoremap <F10> :setlocal spell! spelllang=en_us<CR> | |
" ==> Spellcheck: only certain file types | |
" https://robots.thoughtbot.com/vim-spell-checking | |
" turn on for markdown files | |
autocmd BufRead,BufNewFile *.md setlocal spell | |
" turn on for text files | |
autocmd BufRead,BufNewFile *.txt setlocal spell | |
" turn on for git commits | |
autocmd FileType gitcommit setlocal spell spelllang=en_us | |
" ==> 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 SpellCap cterm=underline ctermbg=none | |
hi SpellBad cterm=underline ctermbg=none | |
hi SpellLocal cterm=underline ctermbg=none | |
hi SpellRare cterm=underline ctermbg=none | |
"hi SpellCap cterm=underline ctermbg=none ctermfg=magenta | |
"hi SpellBad cterm=underline ctermbg=none ctermfg=red | |
"hi SpellLocal cterm=underline ctermbg=none ctermfg=gray | |
"hi SpellRare cterm=underline ctermbg=none ctermfg=gray | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> 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") | |
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") | |
autocmd bufWritePost,filewritepost *.sh execute "normal `a" | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> Snippets | |
" Pasting pre-made things | |
" section banner | |
nnoremap ,ban :-1read $HOME/.vim/templates/banner<CR>jA | |
" section begin/end | |
nnoremap ,begend :-1read $HOME/.vim/templates/begend<CR>jA | |
" section shell script header | |
nnoremap ,sh :0read $HOME/.vim/templates/sh<CR> <bar> :1<CR>dd <bar> :4%s/filename/\=expand('%:t')/g<CR> | |
" section readinglist header | |
"nnoremap ,rl :0read $HOME/.vim/templates/readinglist<CR> <bar> :1<CR>dd $ | |
"nnoremap ,rl :0read $HOME/.vim/templates/rlfm<CR> <bar>zR<CR> <bar> :1<CR>dd :%s/^filename:/\="filename: " . expand('%:t:r')/g<CR> | |
nnoremap ,rl :0read $HOME/.vim/templates/rlfm<CR> <bar>zR<CR> <bar> :1<CR>dd | |
" section markdown file header | |
"nnoremap ,md :0read $HOME/.vim/templates/md<CR> <bar> :1<CR>dd <bar> :%s/filename/\=expand('%:t:r')/g<CR> | |
"nnoremap ,md :0read $HOME/.vim/templates/mdfm<CR> <bar>zR<CR> <bar> :1<CR>dd :%s/^filename:/\="filename: " . expand('%:t:r')/g<CR> | |
nnoremap ,md :0read $HOME/.vim/templates/mdfm<CR> <bar>zR<CR> <bar> :1<CR>dd | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> 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=manual | |
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab | |
" --------------------------------------------------------------------------------------------------------------------- | |
" ==> Source Local Customizations and Set Colorscheme | |
let s:custom_config_path = expand('$HOME/.vimcustom') | |
if filereadable(s:custom_config_path) | |
execute 'source' fnameescape(s:custom_config_path) | |
else | |
colorscheme darkburn | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment