diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index cebfcf9..5fcae94 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -55,7 +55,10 @@ Plug 'reedes/vim-textobj-sentence' " extends the capabilities of sentence detect " " Plug 'tpope/vim-fugitive' - Will have to take a closer look some other time Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " show a directory listing within vim Plug 'Xuyuanp/nerdtree-git-plugin', { 'on': 'NERDTreeToggle' } " show git status in nerdtree for files and dirs -Plug 'Yggdroot/LeaderF', { 'on': ['Leaderf', 'LeaderfFile', 'LeaderfBuffer'], 'do': './install.sh' } " fuzzy matcher, apparently faster than fzf, ctrlp, unit, denite + +" Fuzzy matching +Plug 'lotabout/skim.vim' +Plug 'marty-oehme/notational-fzf-vim' Plug 'dyng/ctrlsf.vim' " Language Integration @@ -216,6 +219,77 @@ endfunction autocmd! User GoyoEnter nested call goyo_enter() autocmd! User GoyoLeave nested call goyo_leave() +" PLUGIN: fzf-bibtex +" Citation and Bibtex utilities +let g:bibtex_cache = '/home/marty/.cache/' +let g:bibtex_source = '/home/marty/Nextcloud/Library/academia/academia.bib' + +function! Bibtex_ls(...) + return 'bibtex-ls -cache ' . g:bibtex_cache . ' ' . g:bibtex_source . ' ' . join(a:000, ' ') +endfunction + +" insert citation from insert mode at cursor +function! s:bibtex_cite_sink_insert(lines) + let r=system("bibtex-cite ", a:lines) + execute ':normal! i' . r + call feedkeys('a', 'n') +endfunction +inoremap @@ u:call skim#run({ + \ 'source': Bibtex_ls(), + \ 'sink*': function('bibtex_cite_sink_insert'), + \ 'up': '25%', + \ 'options': '--ansi --multi --prompt "Cite> "'}) + +" insert citation from normal mode at cursor +function! s:bibtex_cite_sink(lines) + let r=system("bibtex-cite ", a:lines) + execute ':normal! i' . r +endfunction +command! -bang -nargs=* CiteRef call skim#run({ + \ 'source': Bibtex_ls(), + \ 'sink*': function('bibtex_cite_sink'), + \ 'up': '25%', + \ 'options': '--ansi --multi --prompt "Cite> "' + \ }) + +" insert pretty formatted markdown reference +function! s:bibtex_markdown_sink(lines) + let r=system("bibtex-markdown " . g:bibtex_source, a:lines) + echo join(a:lines, '; ') + execute ':normal! i' . r +endfunction +command! -bang -nargs=* CitePretty call skim#run({ + \ 'source': Bibtex_ls(), + \ 'sink*': function('bibtex_markdown_sink'), + \ 'up': '25%', + \ 'options': '--ansi --multi --prompt "Markdown> "' + \ }) + +" edit the document info.yaml +" needs papis to function +" could be abstracted out to work with .bib file or the papis .yaml +" TODO THESE FUNCTIONS DO NOT WORK YET. NEED TO FIND A WAY TO GO FROM fzf -> +" papis -> editor +function! s:bibtex_edit_info_sink(lines) + echom "edit info sink: " . join(a:lines, ",") + let r=system("bibtex-cite ", a:lines) + let s=system("papis edit ref=\"" . join(a:lines,"") . "\"") + " execute ':e s' + echo s +endfunction +command! -bang -nargs=* CiteEdit call skim#run({ + \ 'source': Bibtex_ls(), + \ 'sink*': function('bibtex_edit_info_sink'), + \ 'up': '25%', + \ 'options': join([ + \ '--ansi', + \ '--with-nth=..', + \ '--preview-window=:wrap', + \ '--prompt "Edit> "', + \ '--preview=''papis edit -e cat ref="echo {} | bibtex-cite" '' ', + \ ]) + \}) + " PLUGIN: vim-go " change the tabstops for go to use tabs and a width of 4 " this conforms with the gofmt expectations @@ -445,9 +519,44 @@ au FileType go nnoremap :GoCoverageToggle -short " go to the definition of whatever you hover over au FileType go nnoremap (go-def) -" Call leaderf with (necessary to enable leaderf lazyloading) -nnoremap F :LeaderfFile -nnoremap f :LeaderfBuffer +" skim.vim (fzf alternative) fuzzy finding configuration +" extra key bindings in skim window +let g:skim_action = { + \ 'ctrl-t': 'tab split', + \ 'ctrl-h': 'split', + \ 'ctrl-v': 'vsplit' } + +command! -bang -nargs=* Rg call fzf#vim#rg_interactive(, fzf#vim#with_preview('right:50%:hidden', 'alt-h')) + +" FZF buffers and files in current workdir +noremap s :Buffers +" FZF most recently used / MRU, bound to S since it is essentially a larger +" go-back intention than just buffers +noremap S :History +noremap f :Files + +" FZF general full-text search in cwd with rg +noremap :Rg +" FZF note full-text search with notational-velocity like functions +noremap n :NV +noremap N :NV! + +" FZF git diff +noremap gd :GFiles? + +" Configure notational-fzf-vim +let g:nv_search_paths = [ g:wiki_root ] +let g:nv_wrap_preview_text=1 +" Dictionary with string keys and values. Must be in the form 'ctrl-KEY': +" 'command' or 'alt-KEY' : 'command'. See examples below. +let g:nv_fzf_binds = [ + \ 'alt-a:select-all', + \ 'alt-q:deselect-all', + \ 'alt-p:toggle-preview', + \ 'alt-u:page-up', + \ 'alt-d:page-down', + \ 'ctrl-w:backward-kill-word', + \ ] function! SearchWiki() let l:curpath=getcwd() @@ -458,26 +567,17 @@ function! SearchWiki() :execute(":cd " . l:curpath) endfunction -function! RgWiki() - let l:curpath=getcwd() - :execute(":cd " . g:wiki_root) - let l:texttofind=input("Search Notes: ") - if l:texttofind ==? "" - :execute(":Leaderf rg") - else - :execute(":Leaderf rg -e " . l:texttofind ) - endif - :execute(":cd " . l:curpath) -endfunction - " search in wiki with ctrlsf, in fullscreen window nnoremap wF :execute(":call SearchWiki()") " fuzzy search wiki with leaderf nnoremap wf :execute(":call RgWiki()") -" fuzzy search current working dir -nnoremap :execute(":Leaderf rg") vnoremap CtrlSFVwordPath +" insert a citation of a source using bib ref (uses academia library) +nnoremap c :CiteRef +" insert a pretty printed Markdown version of a reference +nnoremap CM :CitePretty + " Mostly dealing with Prose writing from here on out " Format current Paragraph (esp useful in prose writing) nnoremap q gqap diff --git a/.config/shell/rc.d/alias-fuzzy-finding.sh b/.config/shell/rc.d/alias-fuzzy-finding.sh index 988f5b5..4ff5946 100644 --- a/.config/shell/rc.d/alias-fuzzy-finding.sh +++ b/.config/shell/rc.d/alias-fuzzy-finding.sh @@ -26,12 +26,55 @@ else echo "[WARNING]: No grep-like found - install ripgrep/the silver surfer (ag)/ack to enable functionality" fi -# set up fuzzy file and directory search -alias f="fzf -c 'find . -type f' --preview='"'head -$LINES {}'"' | xargs -0 xdg-open" -alias F="fzf -c 'find ~ -type f' --preview='"'head -$LINES {}'"' | xargs -0 xdg-open" +# TODO Allow yanking of urls, c-e to open in editor, preview window with a-p and more +# FZF FILES AND FOLDERS +fzf_cd_weighted() { + cd "$(fasd -d | sk --nth=1 --with-nth=2 --tac | cut -d' ' -f2- | sed 's/^[ \t]*//;s/[\t]*$//')" || echo "cd not successful" +} -alias d="fzf -c 'find . -type d' --preview='ls --color='always' {}' | cd" -alias D="fzf -c 'find ~ -type d' --preview='ls --color='always' {}' --color=dark --ansi | cd" +fzf_cd_all() { + cd "$(sk --cmd 'find / -type d -not \( -path /proc -prune \)')" || echo "cd not successful" +} + +fzf_files_weighted() { + xdg-open "$(fasd -f | sk --nth=1 --with-nth=2 --tac | cut -d' ' -f2- | sed 's/^[ \t]*//;s/[\t]*$//')" || echo "xdg-open not successful" +} + +fzf_files_all() { + xdg-open "$(sk --cmd 'find / -type d -not \( -path /proc -prune \)')" || echo "xdg-open not successful" +} + +fzf_mru_weighted() { + target="$(fasd -t | sk --nth=1 --with-nth=2 --tac | cut -d' ' -f2- | sed 's/^[ \t]*//;s/[\t]*$//')" + if [ -f "$target" ]; then + xdg-open "$target" || echo "xdg-open not successful" + elif [ -d "$target" ]; then + cd "$target" || echo "cd not successful" + fi +} + +# FZF NOTES +fzf_notes() { + sk --cmd "command rg --follow --ignore-case --line-number --color never --no-messages --no-heading --with-filename '' /home/marty/Nextcloud/Notes" --ansi --multi --tiebreak='length,begin' --delimiter=':' --with-nth=3.. --preview='cat {1}' --preview-window=:wrap +} + +# FZF BIBTEX REFERENCES +fzf_bibtex() { + target=$(sk --cmd "bibtex-ls -cache $XDG_CACHE_HOME ~/Nextcloud/Library/academia/academia.bib" --ansi --with-nth=.. --preview-window=:wrap --prompt "Citation> " --preview="papis edit -e cat ref=$(echo {} | bibtex-cite | sed 's/^@//')") + papis edit ref="$(echo "$target" | bibtex-cite | sed 's/^@//')" +} + +# set up fuzzy file and directory search +alias f=fzf_files_weighted +alias F=fzf_files_all + +alias d=fzf_cd_weighted +alias D=fzf_cd_all + +alias ru=fzf_mru_weighted + +# set up fuzzy bibtex reference search +alias ref=fzf_bibtex # Display fuzzy-searchable history alias zhfind="history | fzf --tac --height 20"