diff --git a/.vimrc b/.vimrc index b6cc73a..f21be6d 100644 --- a/.vimrc +++ b/.vimrc @@ -68,7 +68,7 @@ set omnifunc=syntaxcomplete#Complete " Personal Notes settings " export NOTES_DIR= before use " Go to index of notes and set working directory -nnoremap nn :e $NOTES_DIR/Index.md:cd $NOTES_DIR +nnoremap nn :e $NOTES_DIR/index.md:cd $NOTES_DIR " [ 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 -" to open FZF result in a split -" to open FZF result in a vsplit -" 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 . "\", '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 . "\", '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