Im very new to vim scripting. I have the following script in my .vimrc:
- If there is no user input aka I press
<CR>=> go to recent buffer
- If input is 'd' => delete all buffers except for the current one
- Else go to inputted buffer.
"Fast buffer switch function Warp() ls call inputsave() let bufname = input('warp: ') call inputrestore() if bufname == "" b# elseif bufname == "d" %bd|e#|bd# else exe "b " . bufname endif endfunction nnoremap <silent> <C-f> :call Warp()<CR>
:bcommand works so that I dont have to write the full filepath but only a substring of the file name. For example I can navigate to
However, sometimes file names can overlap which causes
:b to error out. An intuitive solution to this is to use tab-completion to select the correct file when using
:b on the command line. However, I dont know how this could be integrated into my function or even if it is possible.
Somethings I noticed:
nnoremap <C-f> :ballows me to use tab-completion
getchar() == 13allows me to detect
- Maybe something with feedkeys but I dont know if that works with cmdline. Some further ideas I have but dont think is possible in simple vim scripting is catching the error so that the user can revise or use tab-completion the file name inputted clashes.
Thank you in advance. Any advice is greatly appreciated.