Add fuzzy tools to vim and shell
In vim: Use <leader>c to insert a bibtex reference in your text. By default it is a pandoc reference (@bibref), but it can be changed to latex style (\cite(bibref)). <leader>CM inserts a pretty-printed reference to the selected work, using markdown styling. If you want to insert a citation while writing, use @@ from insertmode to insert the bibref instead. The settings add two commands: :CiteRef and :CitePretty which call the respective functions. You can pass any amount of .bibtex libraries to the commands and they will be available to fuzzy search through. :CiteEdit also added to fuzzy find a source and open it in vim for editing. The function is not working yet, I have to find a way to go from the fuzzy finder to papis, select the correct file and edit it in vim. In Shell: Can cd directories (d, D), open files (f, F), open most recently used (ru), and edit bibtex references (ref). lowercase is a weighted view over previously used directories/files, Uppercase is a search of the whole file structure. Still outstanding: Needs the same comfort function additions as vim search, especially reference search. (i.e., open corresponding document, yank path, open editor,...)
This commit is contained in:
parent
b5e979189b
commit
7e45d94997
2 changed files with 166 additions and 23 deletions
|
@ -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 <SID>goyo_enter()
|
||||
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
|
||||
" 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 <F9> :GoCoverageToggle -short<cr>
|
|||
" go to the definition of whatever you hover over
|
||||
au FileType go nnoremap <F12> <Plug>(go-def)
|
||||
|
||||
" Call leaderf with <leader-f> (necessary to enable leaderf lazyloading)
|
||||
nnoremap <leader>F :LeaderfFile<cr>
|
||||
nnoremap <leader>f :LeaderfBuffer<cr>
|
||||
" 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(<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()
|
||||
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 <leader>wF :execute(":call SearchWiki()")<cr>
|
||||
" fuzzy search wiki with leaderf
|
||||
nnoremap <leader>wf :execute(":call RgWiki()")<cr>
|
||||
" fuzzy search current working dir
|
||||
nnoremap <C-F> :execute(":Leaderf rg")<cr>
|
||||
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
|
||||
" Format current Paragraph (esp useful in prose writing)
|
||||
nnoremap <silent> <leader>q gqap
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue