FZF wiki links

Added functions to use FZF to insert file links into current buffer.
- `<ctrl>-p` for wiki link
- `<ctrl>-l` for file name
This commit is contained in:
2025-04-29 18:00:56 -04:00
parent 08bf9e7354
commit fdc6ea1ef3

61
.vimrc
View File

@@ -68,7 +68,7 @@ set omnifunc=syntaxcomplete#Complete
" Personal Notes settings
" export NOTES_DIR=<your notes directory> before use
" Go to index of notes and set working directory
nnoremap <leader>nn :e $NOTES_DIR/Index.md<CR>:cd $NOTES_DIR<CR>
nnoremap <leader>nn :e $NOTES_DIR/index.md<CR>:cd $NOTES_DIR<CR>
" <leader>[ to grep inside Notes files
" I got the idea from here [step 6: search contents of your notes](https://www.edwinwenink.xyz/posts/42-vim_notetaking/#step-6-search-contents-of-your-notes)
@@ -167,14 +167,63 @@ let g:bullets_outline_levels = ['num', 'abc', 'std*', 'std+', 'std-']
let g:airline#extensions#tabline#enabled = 1
let g:airline_detect_theme_from_guicolors = 1
" FZF Actions
" <c-x> to open FZF result in a split
" <c-v> to open FZF result in a vsplit
" <c-o> to copy FZF result as text into current buffer
" ---------------------------------------------------------------------------------------------------------------------
" ==> FZF Helper Functions
"
" Configure FZF default key bindings (actions) within the FZF window
" 'ctrl-x': Open in horizontal split
" 'ctrl-v': Open in vertical split
" 'ctrl-t': Open in new tab (optional, common)
" 'ctrl-p': Paste raw filename(s) at cursor
" 'ctrl-l': Paste formatted [[wiki link]] at cursor
" NOTE: Define these functions BEFORE they are used in g:fzf_action below.
" Function to paste FZF selection(s) at the current cursor position
function! PasteFzfSelection(lines)
if type(a:lines) != type([]) || empty(a:lines)
echoerr "FZF Paste Error: No selection passed to function PasteFzfSelection."
return
endif
" Join multiple selections with a space
let text_to_paste = join(a:lines, ' ')
" Insert the text
call feedkeys('i' . text_to_paste . "\<esc>", 'ni')
endfunction
" Function to paste FZF selection as a formatted wiki link
function! PasteFzfWikiLink(lines)
if type(a:lines) != type([]) || empty(a:lines)
echoerr "FZF Paste Error: No selection passed to function PasteFzfWikiLink."
return
endif
" Typically you only link one file at a time
let filename = a:lines[0]
" --- CHOOSE YOUR LINK FORMAT ---
" Option 1: Wiki format [[filename_without_extension]]
"let filename_base = fnamemodify(filename, ':r') " Removes the extension
"let link_text = '[[' . filename_base . ']]'
" Option 2: Wiki format [[filename_with_extension]]
let link_text = '[[' . filename . ']]'
" Option 3: Markdown format [filename](filename)
" let link_text = '[' . filename . '](' . filename . ')'
" --- End Formatting Options ---
" Insert the formatted link
call feedkeys('i' . link_text . "\<esc>", 'ni')
endfunction
let g:fzf_action = {
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit',
\ 'ctrl-p': ':r !echo'}
\ 'ctrl-t': 'tab split',
\ 'ctrl-p': function('PasteFzfSelection'),
\ 'ctrl-l': function('PasteFzfWikiLink')
\ }
" ---------------------------------------------------------------------------------------------------------------------
" ==> Colors