I’m a beginner in vimscript and even if I search the web for hours I haven’t be able to find how to do the following thing :
I want to create a vimscript who will allow to open a file by typing just some letters :
Assuming
- I only search in the current working directory
- I have a python script that could look recursively through the folders and store the files with the given letters in an array
What I want
<leader><leader>p call a function that will do what is necessary (I don’t know what exactly for the moment…)
This function will ask the user to enter the desired letters. While he enter letters, a menu will display the available results (so, this menu needs to be refreshed automaticaly).
I wish that the user could end to type and just move to the desired file by highlighting it.
For exemple :

What I currently have
if !has('python')
echo "Error: Sublime Search require vim compiled with +python"
finish
endif
let s:current_file=expand("<sfile>:r")
let s:script_path = s:current_file . '.py'
exec 'pyfile ' . s:script_path
function SublimeSearchTrigger()
python lookFor()
endfun
if !exists('g:sublimesearch_keys')
let g:sublimesearch_keys = 1
endif
if g:sublimesearch_keys
inoremap <leader><leader>p :call SublimeSearchTrigger()<cr>
nnoremap <leader><leader>p :call SublimeSearchTrigger()<cr>
endif
And the python file
# -*- encoding: utf-8 -*-
import vim
import sys
def lookFor():
# Ask user to type something to find
vim.command("let user_input = input('Sublime search : ')")
vim.command("call inputrestore()")
# Visual return of what we typed
vim.current.buffer.append( vim.eval( 'user_input' ) )
How to start ?
As you can see I’m not sure how to start but I’m really motivated (I’m planning more complex functionalities but there will be implemented with python).
Could someone help me to start ?
Thanks,
Damien
What you show in your screenshot is the wildmenu of the command-line. You can add custom completion to your own commands, see
:help :command-completion-custom. Unfortunately, you cannot change the completion behavior of built-in commands like:edit(but you could define your own wrapper command:Editand make that use your complete function).The second mechanism is the insert mode completion (
:help ins-completion-menu). This is used for autocompletion, snippets, any text entered into the buffer. Unless you want to insert your file names into the buffer (e.g. for completion ofimportstatements), this isn’t the right thing for you.Many plugins implement their own completion mechanism, as this offers the most control. They create a new, split scratch buffer, and use that for displaying the matches, often in combination with the insert-mode completion menu (but not for inserting the chosen text, but acting on it). Have a look at the FuzzyFinder plugin, it employs this very well, and even allows to plug in custom data providers (that could be your Python script!)