Merge branch '57-unify-fuzzy-finding-in-vim-and-the-commandline' into 'master'

Resolve "Unify fuzzy finding in vim and the commandline"

Closes #57

See merge request marty-oehme/dotfiles!21
This commit is contained in:
Marty Oehme 2019-09-04 17:32:11 +00:00
commit a6c133feb9
2 changed files with 166 additions and 23 deletions

View file

@ -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 '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 '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 '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' Plug 'dyng/ctrlsf.vim'
" Language Integration " Language Integration
@ -216,6 +219,77 @@ endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter() autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave() autocmd! User GoyoLeave nested call <SID>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 <silent> @@ <c-g>u<c-o>:call skim#run({
\ 'source': Bibtex_ls(),
\ 'sink*': function('<sid>bibtex_cite_sink_insert'),
\ 'up': '25%',
\ 'options': '--ansi --multi --prompt "Cite> "'})<CR>
" 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(<q-args>),
\ 'sink*': function('<sid>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(<q-args>),
\ 'sink*': function('<sid>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(<q-args>),
\ 'sink*': function('<sid>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 " PLUGIN: vim-go
" change the tabstops for go to use tabs and a width of 4 " change the tabstops for go to use tabs and a width of 4
" this conforms with the gofmt expectations " this conforms with the gofmt expectations
@ -445,9 +519,44 @@ au FileType go nnoremap <F9> :GoCoverageToggle -short<cr>
" go to the definition of whatever you hover over " go to the definition of whatever you hover over
au FileType go nnoremap <F12> <Plug>(go-def) au FileType go nnoremap <F12> <Plug>(go-def)
" Call leaderf with <leader-f> (necessary to enable leaderf lazyloading) " skim.vim (fzf alternative) fuzzy finding configuration
nnoremap <leader>F :LeaderfFile<cr> " extra key bindings in skim window
nnoremap <leader>f :LeaderfBuffer<cr> let g:skim_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-h': 'split',
\ 'ctrl-v': 'vsplit' }
command! -bang -nargs=* Rg call fzf#vim#rg_interactive(<q-args>, fzf#vim#with_preview('right:50%:hidden', 'alt-h'))
" FZF buffers and files in current workdir
noremap <leader>s :Buffers<cr>
" FZF most recently used / MRU, bound to S since it is essentially a larger
" go-back intention than just buffers
noremap <leader>S :History<cr>
noremap <leader>f :Files<cr>
" FZF general full-text search in cwd with rg
noremap <C-F> :Rg<cr>
" FZF note full-text search with notational-velocity like functions
noremap <leader>n :NV<cr>
noremap <leader>N :NV!<cr>
" FZF git diff
noremap <leader>gd :GFiles?<cr>
" 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() function! SearchWiki()
let l:curpath=getcwd() let l:curpath=getcwd()
@ -458,26 +567,17 @@ function! SearchWiki()
:execute(":cd " . l:curpath) :execute(":cd " . l:curpath)
endfunction 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 " search in wiki with ctrlsf, in fullscreen window
nnoremap <leader>wF :execute(":call SearchWiki()")<cr> nnoremap <leader>wF :execute(":call SearchWiki()")<cr>
" fuzzy search wiki with leaderf " fuzzy search wiki with leaderf
nnoremap <leader>wf :execute(":call RgWiki()")<cr> nnoremap <leader>wf :execute(":call RgWiki()")<cr>
" fuzzy search current working dir
nnoremap <C-F> :execute(":Leaderf rg")<cr>
vnoremap <C-F> <Plug>CtrlSFVwordPath vnoremap <C-F> <Plug>CtrlSFVwordPath
" insert a citation of a source using bib ref (uses academia library)
nnoremap <leader>c :CiteRef<cr>
" insert a pretty printed Markdown version of a reference
nnoremap <leader>CM :CitePretty<cr>
" Mostly dealing with Prose writing from here on out " Mostly dealing with Prose writing from here on out
" Format current Paragraph (esp useful in prose writing) " Format current Paragraph (esp useful in prose writing)
nnoremap <silent> <leader>q gqap nnoremap <silent> <leader>q gqap

View file

@ -26,12 +26,55 @@ else
echo "[WARNING]: No grep-like found - install ripgrep/the silver surfer (ag)/ack to enable functionality" echo "[WARNING]: No grep-like found - install ripgrep/the silver surfer (ag)/ack to enable functionality"
fi fi
# set up fuzzy file and directory search # TODO Allow yanking of urls, c-e to open in editor, preview window with a-p and more
alias f="fzf -c 'find . -type f' --preview='"'head -$LINES {}'"' | xargs -0 xdg-open" # FZF FILES AND FOLDERS
alias F="fzf -c 'find ~ -type f' --preview='"'head -$LINES {}'"' | xargs -0 xdg-open" 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" fzf_cd_all() {
alias D="fzf -c 'find ~ -type d' --preview='ls --color='always' {}' --color=dark --ansi | cd" 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 # Display fuzzy-searchable history
alias zhfind="history | fzf --tac --height 20" alias zhfind="history | fzf --tac --height 20"