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:
61
.vimrc
61
.vimrc
@@ -68,7 +68,7 @@ set omnifunc=syntaxcomplete#Complete
|
|||||||
" Personal Notes settings
|
" Personal Notes settings
|
||||||
" export NOTES_DIR=<your notes directory> before use
|
" export NOTES_DIR=<your notes directory> before use
|
||||||
" Go to index of notes and set working directory
|
" 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
|
" <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)
|
" 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#extensions#tabline#enabled = 1
|
||||||
let g:airline_detect_theme_from_guicolors = 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
|
" ==> FZF Helper Functions
|
||||||
" <c-o> to copy FZF result as text into current buffer
|
"
|
||||||
|
" 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 = {
|
let g:fzf_action = {
|
||||||
\ 'ctrl-x': 'split',
|
\ 'ctrl-x': 'split',
|
||||||
\ 'ctrl-v': 'vsplit',
|
\ 'ctrl-v': 'vsplit',
|
||||||
\ 'ctrl-p': ':r !echo'}
|
\ 'ctrl-t': 'tab split',
|
||||||
|
\ 'ctrl-p': function('PasteFzfSelection'),
|
||||||
|
\ 'ctrl-l': function('PasteFzfWikiLink')
|
||||||
|
\ }
|
||||||
|
|
||||||
" ---------------------------------------------------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------------------------------------------------
|
||||||
" ==> Colors
|
" ==> Colors
|
||||||
|
|||||||
Reference in New Issue
Block a user