fzf
While creating the my custom search commands, I learned a lot about Vimscript and how fzf works. Here are a couple of important notes:
fzf#vim#filesis the function that kicks off anfzfsearch over file names. It takes a path string as input.fzf#vim#grepis the functions that executes some search command likegreporrgand kicks of a fzf session on the output. It takes as input a command to execute (i.e. one involvingrgand a few other commands.- To enable fzf preview on searches, you need to pass the
fzf#vim#with_previewfunction into the files or grep functions. Inside of this function you can pass an options dictionary, which specifies how fzf will be run and with what parameters. These parameters simply must be wrapped by the preview function if you end up using it.- Note that
fzf#vim#with_previewtakes anfzfspec dictionary like every normalfzffunction, because internally everything usesfzf#wrapto extend a given spec dict with global user options and whatever else. So thewith_previewfunction takes a given spec dict so that it can extend it in its own way using proper preview options. Sowith_previewreturns a new spec dictionary with properly configured preview options, which is usually then passed immediately to a corefzffunction that uses the spec to initialize a search session.
- Note that
rgis fine to search all lines with a basic regex like.*. I was running into some problems here with thenthandwith-nthoptions in fzf, which were ruining my output. The important thing here is thatwith-nthactually modifies the line according to the set delimiter. Sonthneeds to accomodate for this. For example, ifwith-nth=4.., then fzf is going to cut out all but the 4th delimited section from each line. Then anth=1..will restrict the search scope to that remaining section previously cut out. Sowith-nth1does not just affect the displayed lines, it actually affects the lines content and ultimately what can be searched.- One thing I realized from this was that my file with a colon in it (Roam: How to… something) was actually being affected by this. So I need to figure a better pipeline for naming files, which is on the list anyway.
fzfhas a-qoption which allows you to fill the search with a query before entering interactive mode. This was useful for my unlinked references where I wanted to prepopulate the search field, but leave room for the fuzzy interactive session.- In order to get the preview working with color, you need to install
bat. I didn’t realize until seeing it was used as a dependency, and now it works. Note that you’ll have to customize bat to work with whatever color scheme you prefer. fzfwill search command history when<ctrl-r>is pressedbangis a command argument specified by a “!” after the command. If used, an “!” populates thebangargument and can be accessed in the command with<bang>. In the context offzf, this tells the command whether or not to open up in fullscreen mode, i.e. act like a real shell command, since<bang>0is used to negate 0 to a boolean value of 1 for fullscreen.
Was toying around with modifying autocomplete results so I can define my own “omnicomplete” pipeline for wiki file names. Using Vim’s <expr>, you can map a key sequence to execute a function and use it’s output in the current location. For example,
inoremap <expr> [[ fzf#vim#complete('cat /usr/share/dict/word')will start an interactive fzf session when I type “[[” and place the output in the current cursor location. Basically I want this with fzf file completion, but I need to modify the output so that the result is wrapped in proper link syntax. After digging around a little, I found that fzf#vim#complete calls an “fzf trigger,” which triggers an interactive fzf session. It then writes the results of this session using a function called feedkeys(), which I believe gets used in conjunction with the <expr> to write text the current cursor location. So I can manually inject text before and after this result using feedkeys myself, but the current problem is how I might actually get the result text, modify it, and place it in multiple locations.