dotfiles

beau's configuration files
git clone https://git.beauhilton.com/dotfiles.git
Log | Files | Refs | README

init.vim (8098B)


      1 " Hello and welcome!
      2 
      3 let mapleader =","
      4 
      5 if ! filereadable(expand('~/.config/nvim/autoload/plug.vim'))
      6 	echo "Downloading junegunn/vim-plug to manage plugins..."
      7 	silent !mkdir -p ~/.config/nvim/autoload/
      8 	silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ~/.config/nvim/autoload/plug.vim
      9 	autocmd VimEnter * PlugInstall
     10 endif
     11 
     12 call plug#begin('~/.config/nvim/plugged')
     13 
     14     Plug 'machakann/vim-sandwich'
     15     Plug 'tpope/vim-commentary'
     16     Plug 'tpope/vim-surround'
     17     Plug 'mcchrish/nnn.vim' "File Manager.
     18 
     19     Plug 'junegunn/goyo.vim'
     20     Plug 'junegunn/limelight.vim'
     21 
     22     Plug 'kovetskiy/sxhkd-vim' " detects sxhkd filetype
     23     Plug 'frazrepo/vim-rainbow'
     24     Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() } }
     25 
     26     Plug 'neoclide/coc.nvim', {'branch': 'release'}
     27     " Plug 'ap/vim-css-color', { 'for': [ 'css', 'scss' ] }
     28 
     29     " theming
     30     syntax on
     31     if (has("termguicolors"))
     32         set termguicolors
     33     endif
     34     colorscheme selenized_bw
     35     set background=dark
     36     " make background transparent
     37     hi NonText ctermbg=none
     38     hi Normal guibg=NONE ctermbg=NONE
     39 
     40     Plug 'vim-airline/vim-airline'
     41     Plug 'vim-airline/vim-airline-themes'
     42         let g:airline_theme='akhatib'
     43 
     44 call plug#end()
     45 
     46 " path to python
     47     let g:python3_host_prog = '/usr/bin/python3'
     48     let g:python_host_prog = '/usr/bin/python2'
     49 
     50 
     51 " Some basics:
     52     set go=a
     53     set mouse=a                         " automatically enable mouse usage
     54     set completeopt+=preview
     55 
     56     " search
     57     set incsearch                       " find as you type
     58     set hlsearch                        " highlight search terms
     59     set ignorecase                      " case insensitive search
     60     set smartcase                       " case sensitive when upper case present
     61     " clear current search highlighting with //
     62     nmap <silent> // :nohlsearch<CR>
     63 
     64     " indentation and tabbing
     65     filetype indent on
     66     set autoindent
     67     set tabstop
     68     set expandtab
     69     set softtabstop=4
     70     set shiftwidth=4
     71 
     72     set clipboard+=unnamedplus
     73     set updatetime=300
     74     set nocompatible
     75     set encoding=utf-8
     76     set number relativenumber
     77     autocmd CursorHold * update
     78     set nofoldenable
     79     set noswapfile
     80     filetype plugin on
     81     set foldmethod=syntax
     82 
     83     nnoremap <leader>sv :source $MYVIMRC<cr>
     84 
     85 " Enable autocompletion:
     86     set wildmode=longest,list,full
     87 
     88 " Move up and down in autocomplete with <c-j> and <c-k>
     89     inoremap <expr> <C-j> ("\<C-n>")
     90     inoremap <expr> <C-k> ("\<C-p>")
     91 
     92     autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif
     93 
     94 " Disables automatic commenting on newline:
     95     autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
     96 
     97 " vim rainbow settings
     98     let g:rainbow_active = 1
     99 
    100 " nnn
    101 let g:nnn#layout = { 'window': { 'width': 0.9, 'height': 0.6, 'highlight': 'Debug' } }
    102 let g:nnn#action = {
    103       \ '<c-t>': 'tab split',
    104       \ '<c-x>': 'split',
    105       \ '<c-v>': 'vsplit' }
    106 nnoremap <leader>n :NnnPicker %:p:h<CR>
    107     map <C-h> <C-w>h
    108     map <C-j> <C-w>j
    109     map <C-k> <C-w>k
    110     map <C-l> <C-w>l
    111 
    112 " Alt-hjkl to resize splits
    113     noremap <A-h> :vertical resize -5<CR>
    114     noremap <A-l> :vertical resize +5<CR>
    115     noremap <A-j> :resize -5<CR>
    116     noremap <A-k> :resize +5<CR>
    117 
    118 " Ctrl maps for buffers
    119     map <C-b> :buffers<CR>
    120     map <C-Up> :bnext<CR>
    121     map <C-n> :bnext<CR>
    122     map <C-Down> :bprevious<CR>
    123 
    124 " run Black with F9
    125     " nnoremap <F9> :Black<CR>
    126 
    127 " spell-check set to <leader>o, 'o' for 'orthography':
    128     map <leader>o :setlocal spell! spelllang=en_us<CR>
    129 
    130 " check file in shellcheck:
    131     map <leader>s :!clear && shellcheck %<CR>
    132 
    133 " replace all is aliased to S.
    134     nnoremap S :%s//g<Left><Left>
    135 
    136 " make it so
    137     map <leader>c :w! \| !compiler <c-r>%<CR>
    138 
    139 " open corresponding .pdf/.html or preview
    140     map <leader>p :!opout <c-r>%<CR><CR>
    141 
    142     autocmd BufRead,BufNewFile /tmp/calcurse* set filetype=markdown
    143     autocmd BufRead,BufNewFile *.ms,*.me,*.mom,*.man set filetype=groff
    144     autocmd BufRead,BufNewFile *.tex set filetype=tex
    145 
    146 " Goyo plugin makes text more readable when writing prose:
    147     map <leader>g :Goyo \| set linebreak<CR>
    148 
    149 " enable Goyo by default for mutt writting
    150 	" Goyo's width will be the line limit in mutt.
    151     autocmd BufRead,BufNewFile /tmp/neomutt* let g:goyo_width=80
    152     autocmd BufRead,BufNewFile /tmp/neomutt* :Goyo
    153 
    154 " Leave goyo with a single :wq, rather than two (two is intended behavior
    155 " but it's annoying, especially when composing emails)
    156     function! s:goyo_enter()
    157       let b:quitting = 0
    158       let b:quitting_bang = 0
    159       autocmd QuitPre <buffer> let b:quitting = 1
    160       cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
    161     endfunction
    162 
    163     function! s:goyo_leave()
    164       if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
    165         if b:quitting_bang
    166           qa!
    167         else
    168           qa
    169         endif
    170       endif
    171     endfunction
    172 
    173     autocmd! User GoyoEnter call <SID>goyo_enter()
    174     autocmd! User GoyoLeave call <SID>goyo_leave()
    175 
    176 " Goyo and Limelight activate and deactivated together
    177     autocmd! User GoyoEnter Limelight
    178     autocmd! User GoyoLeave Limelight!
    179 
    180 " Color name (:help cterm-colors) or ANSI code
    181     let g:limelight_conceal_ctermfg = 'gray'
    182     let g:limelight_conceal_ctermfg = 240
    183 
    184 " Color name (:help gui-colors) or RGB color
    185     let g:limelight_conceal_guifg = 'DarkGray'
    186     let g:limelight_conceal_guifg = '#777777'
    187 
    188 " Automatically deletes all trailing whitespace on save.
    189     autocmd BufWritePre * %s/\s\+$//e
    190 
    191 " When shortcut files are updated:
    192     autocmd BufWritePost ~/.config/bmdirs,~/.config/bmfiles !shortcuts
    193 
    194 " Update binds when sxhkdrc is updated.
    195     autocmd BufWritePost *sxhkdrc !pkill -USR1 sxhkd
    196 
    197 " Run xrdb whenever Xdefaults or Xresources are updated.
    198     autocmd BufWritePost *Xresources,*Xdefaults !xrdb %
    199 
    200 " Alias write and quit to Q
    201     nnoremap Q :wq<CR>
    202 
    203 " Navigating with guides
    204     inoremap ;g <++>
    205     inoremap <leader><leader> <Esc>/<++><Enter>"_c4l
    206     vnoremap <leader><leader> <Esc>/<++><Enter>"_c4l
    207     map <leader><leader> <Esc>/<++><Enter>"_c4l
    208 
    209 " Save file as sudo on files that require root permission
    210     cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
    211 
    212 " add date to bottom of file
    213     map <A-d> Go<ESC>o<ESC>0i last updated: <C-r>=strftime('%F')<CR>
    214 
    215 " markdown
    216     autocmd Filetype markdown,rmd inoremap ,d last updated: <C-r>=strftime('%F')<CR>
    217     autocmd Filetype markdown,rmd map <leader>w yiWi[<esc>Ea](<esc>pa)
    218     autocmd Filetype markdown,rmd inoremap ,n ---<Enter><Enter>
    219     autocmd Filetype markdown,rmd inoremap ,b ****<++><Esc>F*hi
    220     autocmd Filetype markdown,rmd inoremap ,s ~~~~<++><Esc>F~hi
    221     autocmd Filetype markdown,rmd inoremap ,e **<++><Esc>F*i
    222     autocmd Filetype markdown,rmd inoremap ,h ====<Space><++><Esc>F=hi
    223     autocmd Filetype markdown,rmd inoremap ,i ![](<++>)<++><Esc>F[a
    224     autocmd Filetype markdown,rmd inoremap ,a [](<++>)<++><Esc>F[a
    225     autocmd Filetype markdown,rmd inoremap ,1 #<Space><Enter><++><Esc>kA
    226     autocmd Filetype markdown,rmd inoremap ,2 ##<Space><Enter><++><Esc>kA
    227     autocmd Filetype markdown,rmd inoremap ,3 ###<Space><Enter><++><Esc>kA
    228     autocmd Filetype markdown,rmd inoremap ,l --------<Enter>
    229     autocmd Filetype rmd inoremap ,r ```{r}<CR>```<CR><CR><esc>2kO
    230     autocmd Filetype rmd inoremap ,p ```{python}<CR>```<CR><CR><esc>2kO
    231     autocmd Filetype rmd inoremap ,c ```<cr>```<cr><cr><esc>2kO
    232 
    233 " markdown preview
    234     let g:mkdp_auto_start = 0
    235     let g:mkdp_auto_close = 1
    236     let g:mkdp_refresh_slow = 0 " 0 == autorefresh
    237     let g:mkdp_page_title = '「${name}」'
    238 
    239 " citations
    240     " map <leader>b :vsp<space>$BIB<CR>
    241     " map <leader>r :vsp<space>$REFER<CR>
    242     let g:citation_vim_bibtex_file="repos/life/dox/acad.bib"
    243     let g:citation_vim_mode="bibtex"
    244     let g:citation_vim_cache_path='~/.config/nvim/cache'
    245     let g:citation_vim_description_format = "{} ┃ {} ┃ {} ┃ {} ┃ {}"
    246     let g:citation_vim_description_fields = ["key","author","publication","journal","doi"]
    247 
    248     " coc
    249 source $HOME/.config/nvim/plugins/coc.vim