dotfiles/.config/nvim/init.vim
Marty Oehme faf4739711 Fix NerdTree lazy loading
Did not load NerdTree on NerdTreeFind command, which also causes it to
open via a mapping. This caused the mapping to only work after having
opened NerdTree at least once through another method.
2019-11-21 14:58:50 +01:00

531 lines
18 KiB
VimL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

" vim: set foldmethod=marker foldlevel=0 nomodeline:
" ================================================================================
" .init.vim / .vimrc of Marty Oehme {{{
" ================================================================================
"
" - stolen from many different sources including
" Steve Losh
" Junegunn Choi
" Tim Pope
" this config does not set nocompatible - neovim does this automatically
" this config does not set filetype plugin - vim-sensible does this
" }}}
" PLUGIN INSTALLATION - handled by VIM-PLUG {{{
" ================================================================================
"
" automatically install vim-plug if it does not exist
" Note: this installs it in the neovim folder, not the vim folder
if empty(glob('~/.local/share/nvim/site/autoload/plug.vim'))
silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC | q
endif
" automatically install any missing plugins
autocmd VimEnter *
\ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | q
\| endif
" defines plugin directory
" Install plugins from vim with :PlugInstall
silent! if plug#begin('~/.local/share/nvim/plugged')
" Base
" a minimal definition of variables TODO still necessary for nvim?
Plug 'tpope/vim-sensible'
" add seamless movement between vim and tmux, switch windows with C-hjkl
Plug 'christoomey/vim-tmux-navigator'
" automatically switch between relative and absolute numbers as buffers move
" into / out of focus (requires number & relativenumber to be set)
Plug 'jeffkreeftmeijer/vim-numbertoggle'
" Plug 'liuchengxu/vim-which-key', { 'on': ['WhichKey', 'WhichKey!'] } ->
" instructions: http://liuchengxu.org/vim-which-key/, needs setup tp become
" useful. TODO enable when setup is more settled down
" sneak around your files using
Plug 'justinmk/vim-sneak'
" highlight all occurences of the current word under the cursor (after 250ms
" delay)
Plug 'RRethy/vim-illuminate'
" " editing Workflow
Plug 'tpope/vim-commentary' " easily toggle comments for lines, paragraphs etc with gc
Plug 'tommcdo/vim-exchange' " adds exchange operator with cx. common use: cxiw . on 2 words to switch
Plug 'tpope/vim-surround' " lets you change surrounding things with cs (or ds to del, ys to add)
" " Ecosystem
" " Plug 'tpope/vim-fugitive' - Will have to take a closer look some other time
Plug 'scrooloose/nerdtree', { 'on': ['NERDTreeToggle', 'NERDTreeFind'] } " show a directory listing within vim
Plug 'Xuyuanp/nerdtree-git-plugin', { 'on': ['NERDTreeToggle', 'NERDTreeFind'] } " show git status in nerdtree for files and dirs
" Fuzzy matching
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
Plug 'junegunn/fzf.vim'
Plug 'alok/notational-fzf-vim'
Plug 'dyng/ctrlsf.vim'
" Language Integration
Plug 'sheerun/vim-polyglot' " syntax plugins for almost every language
Plug 'stephpy/vim-yaml'
Plug 'mhartington/nvim-typescript', {'for': 'typescript','do': './install.sh'}
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'deoplete-plugins/deoplete-go', { 'do': 'make'}
Plug 'aliou/bats.vim'
" HTML Workflow
Plug 'valloric/matchtagalways', { 'on': [] }
Plug 'alvan/vim-closetag', { 'on': [] }
Plug 'jiangmiao/auto-pairs', { 'on': [] } " Auto close brackets and ''
augroup load_html_utils
autocmd!
autocmd InsertEnter * call plug#load('matchtagalways', 'vim-closetag', 'auto-pairs')
\| autocmd! load_html_utils
augroup END
" Prose Workflow
Plug 'kana/vim-textobj-user' " dependency for most other textobj plugins
Plug 'reedes/vim-textobj-sentence' " extends the capabilities of sentence detection
" and allows you to jump to the *end* of this <g)> or last <g(> sentence.
Plug 'reedes/vim-pencil', { 'for': ['markdown', 'txt'], 'on': 'Goyo' } " provide md convenience functions like hard/softwrap
Plug 'junegunn/goyo.vim', { 'for': ['markdown', 'txt'], 'on': 'Goyo' } " provide distraction free writing
Plug 'junegunn/limelight.vim', { 'for': ['markdown', 'txt'], 'on': 'Goyo' } " provide even distraction free-er writing (lowlight paragraphs)
" RMarkdown & LaTeX workflow
Plug 'vim-pandoc/vim-pandoc-syntax'
Plug 'vim-pandoc/vim-pandoc'
" Plug 'vim-pandoc/vim-rmarkdown'
" Note-Taking Workflow
Plug 'lervag/wiki.vim'
" For async completion
Plug 'Shougo/deoplete.nvim', { 'on': [] } " automatic suggestions, can also perhaps be changed for newer plugs
Plug 'Shougo/echodoc.vim', { 'on': [] }
Plug 'w0rp/ale', { 'on': [] } " asynchronous linting - might be superseded by lsp or coc.nvim at some point
" lazy loading since they require a lot of startup time
augroup load_ide_features
autocmd!
autocmd InsertEnter * call plug#load('ale', 'deoplete.nvim', 'echodoc.vim')
\| autocmd! load_ide_features
autocmd InsertEnter * call deoplete#enable()
autocmd InsertEnter * call echodoc#enable()
" Add pandoc citations to deoplete automatic completions
autocmd InsertEnter * call deoplete#custom#var('omni', 'input_patterns', {
\ 'pandoc': '@'
\})
augroup END
" Design
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'edkolev/tmuxline.vim'
" Colorschemes
Plug 'rafi/awesome-vim-colorschemes'
Plug 'reedes/vim-colors-pencil'
Plug 'rakr/vim-togglebg'
call plug#end()
endif
" }}}
" PLUGIN CONFIGURATION {{{
" ================================================================================
let g:sneak#s_next = 1
let g:sneak#use_ic_scs = 1
" PLUGIN: NERDTree
" highlight the line the cursor is on
let NERDTreeHighlightCursorline = 1
" remove Press ? for help
let NERDTreeMinimalUI=1
" loads nerdtree plugin when starting vim with a directory
" this is necessary when we lazyload nerdtree with vimplug above
" since it would only get loaded with nttoggle otherwise, and run netrw
augroup nerd_loader
autocmd!
autocmd VimEnter * silent! autocmd! FileExplorer
autocmd BufEnter,BufNew *
\ if isdirectory(expand('<amatch>'))
\| call plug#load('nerdtree')
\| execute 'autocmd! nerd_loader'
\| endif
augroup END
" " PLUGIN: markdown-group
" " unify markdown extensions to all use markdown filetype
" au! BufRead,BufNewFile *.markdown set filetype=markdown
" au! BufRead,BufNewFile *.md set filetype=markdown
" au! BufRead,BufNewFile *.mkd set filetype=markdown
" automatically enables markdown plugins for md & txt files
function! Prose()
call plug#load('vim-pencil')
call pencil#init()
" PLUGIN: vim-textobj-sentence
" enable extended sentence textobject use on md and plaintext files
call textobj#sentence#init()
" hide the markdown cruft
setlocal conceallevel=2
setlocal foldlevel=2
endfunction
" enable syntax highlighting for codeblocks WITHIN markdown
let g:markdown_fenced_languages = ['html', 'python', 'bash=sh', 'javascipt', 'go']
" call the prose function defined above for any md files
au FileType pandoc,markdown call Prose()
" or invoke it manually by writing :Prose
command! -nargs=0 Prose call Prose()
" PLUGIN: vim-pandoc
" handle markdown files with pandoc (and pandoc syntax!)
let g:pandoc#modules#disabled = ["folding"]
let g:pandoc#filetypes#pandoc_markdown = 1
" disable all default keymaps
let g:pandoc#keyboard#use_default_mappings=0
let g:pandoc#hypertext#use_default_mappings=0
" if there's a pdf and an html or similar, open the pdf
let g:pandoc#command#prefer_pdf=1
" look for bibtex files w/ same name as edited one, then .bib in current dir, yaml frontmatter, and finally the globally set bibs file
let g:pandoc#biblio#sources="bcyg"
" the globally set bibs file
let g:pandoc#biblio#bibs=[expand("~/Nextcloud/Library/academia/academia.bib")]
let g:pandoc#biblio#use_bibtool=1
let g:pandoc#biblio#use_preview=1
let g:pandoc#completion#bib#mode='citeproc'
let g:pandoc#folding#fold_yaml=1
let g:pandoc#folding#fastfolds=1
" let g:pandoc#folding#level=2
let g:pandoc#spell#default_langs=["en_us", "de_de"]
let g:pandoc#hypertext#ausosave_on_edit_open_link=1
let g:pandoc#hypertext#create_if_no_alternates_exists=1
let g:pandoc#syntax#conceal#use = 1
let g:pandoc#syntax#conceal#urls = 1
" PLUGIN: wiki.vim
if $WIKIROOT ==? ""
let g:wiki_root = '~/Nextcloud/Notes/'
else
let g:wiki_root = $WIKIROOT
endif
" filetypes to automatically enable the plugin for, seems to take file endings
" rather than vim ft
let g:wiki_filetypes = ['md', 'mkd', 'markdown', 'wiki']
let g:wiki_link_extension = '.md'
let g:wiki_link_target_type = 'md'
let g:wiki_mappings_use_defaults = 1
" PLUGIN: vim-pencil
" set default wrap mode to hard - TODO test which mode works better for
" me, it seems hardmode has trouble with markdown lists (see issue #31)
let g:pencil#wrapModeDefault = 'soft' " default is 'hard'
" PLUGIN: goyo
" set up functions for entering/exiting distraction free mode, or leaving it
function! s:goyo_enter()
" remove the tmux status bar for actual distraction free environment
silent !tmux set status off
" maximize the tmux pane that vim is in if any (usually I have vim open as the only pane)
silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
" disable line highlighting, we really don't need it for prose
set nocursorline
" enable limelight which highlights whatever paragraph you are in and lowlights the rest
Limelight
endfunction
function! s:goyo_leave()
silent !tmux set status on
silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
set cursorline
Limelight!
endfunction
" actually call the functions on entering/leaving goyo
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
" FZF Fuzzy Finding
" set some fzf defaults
let g:fzf_layout = { 'up': '~40%' }
let g:fzf_command_prefix = 'Fzf'
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
" set up fzf-bibtex
let g:fzf_bibtex_cache = '~/.cache/'
let g:fzf_bibtex_sources = g:pandoc#biblio#bibs
" prepare bibtex_ls function to look for bib files in cwd/parent/subdirs,
" attach the standard bibtex source file
" return the command with standard cache directory filled
function! s:bibtex_ls(...)
let bibfiles = (
\ globpath('.', '*.bib', v:true, v:true) +
\ globpath('..', '*.bib', v:true, v:true) +
\ globpath('*/', '*.bib', v:true, v:true)
\ )
let bibfiles = join(bibfiles, ' ')
let source_cmd = 'bibtex-ls -cache ' . g:fzf_bibtex_cache . ' ' .bibfiles . ' ' . join(g:fzf_bibtex_sources)
return source_cmd
endfunction
" insert citation from normal mode at cursor (with brackets)
function! s:bibtex_cite_sink(lines)
let r=system("bibtex-cite ", a:lines)
execute ':normal! i[' . r . ']'
endfunction
command! -bang -nargs=* CiteRef call fzf#run(fzf#wrap({
\ 'source': <sid>bibtex_ls(<q-args>),
\ 'sink*': function('<sid>bibtex_cite_sink'),
\ 'up': '25%',
\ 'options': '--ansi --multi --prompt "Cite> "'
\ }))
" insert citation from insert mode at cursor (no brackets inserted)
function! s:bibtex_cite_sink_insert(lines)
let r=system("bibtex-cite ", a:lines)
execute ':normal! i' . r
call feedkeys('a', 'n')
endfunction
" insert markdown formatted reference
function! s:bibtex_markdown_sink(lines)
let r=system("bibtex-markdown -cache " . g:fzf_bibtex_cache . ' ' . join(g:fzf_bibtex_sources), a:lines)
echo join(a:lines, '; ')
execute ':normal! i' . r
endfunction
command! -bang -nargs=* CiteMarkdown call fzf#run(fzf#wrap({
\ 'source': <sid>bibtex_ls(),
\ 'sink*': function('<sid>bibtex_markdown_sink'),
\ 'up': '25%',
\ 'options': '--ansi --multi --prompt "Markdown> "'
\ }))
" PLUGIN: vim-go
" change the tabstops for go to use tabs and a width of 4
" this conforms with the gofmt expectations
au FileType go set noexpandtab
au FileType go set shiftwidth=4
au FileType go set softtabstop=4
au FileType go set tabstop=4
" enable all sorts of highlighting options for
" variables/functions/arguments...
let g:go_highlight_build_constraints = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_structs = 1
let g:go_highlight_types = 1
" enable highlighting of other uses of the same variable
let g:go_auto_sameids = 1
" automatically import needed dependencies
" TODO do I need this? not doing it automatically does lead to more conscious
" decision making on imports
let g:go_fmt_command = "goimports"
" show type information for variables in the status line
let g:go_auto_type_info = 1
" PLUGIN: DEOPLETE
" enable deoplete at startup
let g:deoplete#enable_at_startup = 0
let g:deoplete#enable_ignore_case = 1
let g:deoplete#enable_smart_case = 1
let g:deoplete#enable_camel_case = 1
let g:deoplete#enable_refresh_always = 1
let g:deoplete#max_abbr_width = 0
let g:deoplete#max_menu_width = 0
let g:deoplete#omni#input_patterns = get(g:,'deoplete#omni#input_patterns',{})
" PLUGIN: ECHODOC
let g:echodoc#type="virtual"
set splitbelow
set completeopt+=menuone,noinsert,noselect
set completeopt-=preview
autocmd CompleteDone * pclose
" PLUGIN: ALE
" clearer Error and warning signs for the gutter
let g:ale_sign_error = ''
let g:ale_sign_warning = '⚠'
" Enable integration with airline.
let g:airline#extensions#ale#enabled = 1
let g:ale_fix_on_save = 1
let g:ale_fixers = {
\'javascipt': ['eslint', 'prettier'],
\'html': ['tidy','prettier'],
\'typescript': ['prettier','tslint'],
\'*': ['remove_trailing_lines', 'trim_whitespace'],
\'go': ['gofmt'],
\'sh': ['shfmt'],
\'zsh': ['shfmt'],
\}
let g:ale_linters = {
\ 'go': ['gopls'],
\ 'sh': ['language_server','shellcheck'],
\ 'zsh': ['language_server','shellcheck'],
\}
" PLUGIN: AIRLINE
" PLUGIN: TMUXLINE
let g:airline_powerline_fonts=1
" let g:airline_theme='raven'
" Enable italics for colorschemes that support them
let g:gruvbox_italic=1
let g:one_allow_italics=1
let g:pencil_terminal_italics=1
colorscheme one
" disable automatically refreshing the mux statusbar since it breaks tmux
" prefix highlighting. Instead, when changing vim statusbar just create
" snapshot with :TmuxlineSnapshot file and stick it into tmux config manually
let g:airline#extensions#tmuxline#enabled = 1
" custom preset with left-justified window list
let g:tmuxline_preset = {
\'a' : '#S',
\'b' : '#(whoami)',
\'c' : '#I:#P',
\'win' : '#I #W',
\'cwin' : [' ', '#I #W'],
\'x' : '#{?client_prefix,#[fg=colour232]#[bg=brightblue],} %H:%M:%S',
\'y' : '%d-%b-%y',
\'z' : '#H',
\'options' : {}}
" automatically save the current buffer when navigating away from vim
let g:tmux_navigator_save_on_switch = 1
" }}}
" VIM SETTINGS {{{
" ================================================================================
"
" set truecolor (neovim)
set termguicolors
" sets tabs to be 2 characters, expanded into spaces, but still removable with
" one press of backspace.
" great explanation: http://vimcasts.org/transcripts/2/en/
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
" set cursor line highlighting, esp useful when using with bracket
" highlighting and you don't know which side of the brace the cursor is on
set cursorline
" shows linenumbers relative to the one you are on, for easy movement and
" dNUMBERd deletions
set number relativenumber
" keeps an undofile next to files so that you can even undo if vim is closed
" in between
set undofile
" ignores case by default but will use case when search is specifically not
" all lowercased
set ignorecase
set smartcase
" whenever vim loses focus, save
au FocusLost * :wa
" disables showing us the current mode in the command line since airline takes
" care of it
set noshowmode
" highlight everything that goes over 80 columns
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
" Special setting for editing gopass files - make sure nothing leaks outside
" the directories it is supposed to
au BufNewFile,BufRead /dev/shm/gopass.* setlocal noswapfile nobackup noundofile
function! SearchWiki()
let l:curpath=getcwd()
:execute(":cd " . g:wiki_root)
let l:texttofind=input("Search in Notes: ")
:execute(":CtrlSF " . l:texttofind)
:CtrlSFFocus
:execute(":cd " . l:curpath)
endfunction
" Configure notational-fzf-vim
let g:nv_search_paths = [ g:wiki_root ]
let g:nv_wrap_preview_text=1
" }}}
" KEYBINDINGS {{{
" ================================================================================
"
" Show all mapped keys in a list - from https://stackoverflow.com/questions/13990136/display-a-ordered-vim-keyboard-mapping
function! s:ShowMaps()
let old_reg = getreg("a") " save the current content of register a
let old_reg_type = getregtype("a") " save the type of the register as well
try
redir @a " redirect output to register a
" Get the list of all key mappings silently, satisfy "Press ENTER to continue"
silent map | call feedkeys("\<CR>")
redir END " end output redirection
vnew " new buffer in vertical window
put a " put content of register
" Sort on 4th character column which is the key(s)
%!sort -k1.4,1.4
finally " Execute even if exception is raised
call setreg("a", old_reg, old_reg_type) " restore register a
endtry
endfunction
" use :ShowMaps to call the function
com! ShowMaps call s:ShowMaps() " Enable :ShowMaps to call the function
" Begin mapping definitions
runtime! **/maps.vim
" }}}
" ABBREVIATIONS {{{
" Typos
iabbrev adn and
iabbrev waht what
iabbrev tehn then
iabbrev whit with
iabbrev whith with
" Text expansion
iabbrev mo@ marty.oehme@gmail.com
iabbrev mo.me@ <https://martyoeh.me/>
iabbrev mcc@ Copyright 2019 Marty Oehme, all rights reserved.
"
" }}}
" END
" ================================================================================