I have 2 ways to open a file for editing:
:b <filename>to switch to an opened buffer -- imagine that I have a lot of folders containingindex.htmlso by using:bI know I am working on the one that I should be working on.Fuzzy File Search (
:FZF) just in case I haven't opened the file or I have killed the buffer with:bd.
My question: Is there a way to automate, such that if :b <filename> fails (E94: No matching buffer), nvim will call :FZF and use <filename> to search?
P.S. It'd be best if I used :b107 and I mistyped the number, FZF will not be triggered. (distinguishing cases whether I use :b with string or number)
-complete=bufferand/or-complete=fileto thecommand!command to allow some autocompletion like the original:bdoes. – statox Apr 18 '18 at 09:20index.php, even after I:bdand:lsto verify that the buffer is deleted,:B indexwill not go to the else case.. while:b indexreturns E94. By the way, forfzfit isexecute 'FZF -q '.a:buffer_name. Spent time finding ways to type in Terminal Emulator and in vain.. – Sunny Pun Apr 19 '18 at 04:24blockand keep only the contents of the elseblock. Thanks for confirming thefzfcommand. I'll add that into the answer. – Rich Apr 19 '18 at 08:29:bd. However if I used:b index.phpit won’t open the deleted buffer. And I want:Bto resort to FZF when there is no opened buffer corresponding to the partial name. – Sunny Pun Apr 19 '18 at 11:03:bd, it closes the buffer, but doesn't remove all knowledge of it. The command:ls!will show all buffers, even deleted ones. Thus,:b partialnamestill opens the buffer. (However,:b fullnamewill also still open it: I don't know why Vim doesn't exhibit that behaviour for you.) This is Vim's default behaviour. If you don't want this to occur, you'll need to use:bwipeoutto remove the buffer completely, but be aware of what this actually does before doing so. – Rich Apr 19 '18 at 11:18