@prevent_invalid_dir
    def global_incremental_search(self, should_open=True):#{{{2
        """
        Incremental search.
        """
        query = ""
        should_create_on_enter = False

        V + "echohl None"
        V + 'echo ">> "'
        while True:
            raw_char = vim.eval("getchar()")
            if raw_char in ("13", "27"):
                if raw_char == "13":
                    if should_create_on_enter:
                        if should_open == True:
                            self.open(first_line=query)
                        else:
                            path = join(get_save_dir(), \
                                    PadInfo([query]).id + \
                                    get_setting("default_file_extension"))
                            with open(path, 'w') as new_note:
                                new_note.write(query)
                        V + "echohl None"
                    else:
                        self.display(query, True)
                V + "redraw!"
                break
            else:
                try:   # if we can convert to an int, we have a regular key
                    int(raw_char)   # we bring up an error on nr2char
                    last_char = vim.eval("nr2char(" + raw_char + ")")
                    query = query + last_char
                except:  # if we don't, we have some special key
                    keycode = unicode(raw_char, errors="ignore")
                    if keycode == "kb":  # backspace
                        query = query[:-len(last_char)]
            pad_files = self.collator.get_filelist(query)
            if pad_files != []:
                info = ""
                V + "echohl None"
                should_create_on_enter = False
            else:  # we will create a new pad
                info = "[NEW] "
                V + "echohl WarningMsg"
                should_create_on_enter = True
            V + "redraw"
            V + ('echo ">> ' + info + query + '"')

# vim: set fdm=marker :
dataset/ETHPy150Open fmoralesc/vim-pad/pythonx/pad/plugin.py/PadPlugin.global_incremental_search/original