summary refs log blame commit diff stats
path: root/examples/vim_file_chooser.vim
blob: a44ab2b73161bf2acb2e1278c65fd996a24ba8dd (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                           
" Add ranger as a file chooser in vim
" 
" If you add this function and the key binding to the .vimrc, ranger can be
" started using the keybinding ",r".  Once you select a file by pressing
" enter, ranger will quit again and vim will open the selected file.

fun! RangerChooser()
    exec "silent !ranger --choosefile=/tmp/chosenfile " . expand("%:p:h")
    if filereadable('/tmp/chosenfile')
        exec 'edit ' . system('cat /tmp/chosenfile')
        call system('rm /tmp/chosenfile')
    endif
    redraw!
endfun
map ,r :call RangerChooser()<CR>
an> stdscr = curses.initscr() curses.noecho() curses.cbreak() curses.halfdelay(3) stdscr.keypad(1) #curses.curs_set(0) stdscr.addstr(4, 0, stringy) stdscr.refresh() class ThreadTest(threading.Thread): def __init__(self, *a, **b): threading.Thread.__init__(self, *a, **b) self.killed = False def run(self): global stdscr global blocked for i in range(1,50): while blocked: time.sleep(0.1) blocked = True stdscr.addstr(1, 0, str(i)) stdscr.refresh() blocked = False time.sleep(0.1) if self.killed: raise SystemExit() def kill(self): self.killed = True thr = ThreadTest() thr.start() try: while 1: c = stdscr.getch() if c == ord('q'): raise while blocked: time.sleep(0.1) blocked = True stdscr.addstr(0, 0, str(c)) stdscr.refresh() blocked = False except Exception: thr.kill() raise finally: curses.nocbreak() stdscr.keypad(1) curses.echo() curses.endwin() # curses.curs_set(1)