Git Product home page Git Product logo

fzf-vi-mode's Introduction

easy fzf vi-mode

automates configuration for a pseudo-modal vim-like fzf (insert and normal modes).

wonderful software fzf can be configured (with --bind option) to have something like a vim-like 'normal mode':

fzf --bind=j:down,k:up \
    --bind=start:unbind(i,j,k) \
    --bind=esc:disable-search+rebind(i,j,k) \
    --bind=i:enable-search+unbind(i,j,k)

with the options above, pressing esc will rebind j to up and k to down, just like in vim: it's a pseudo-normal-mode. then, pressing i will unbind them so they will just be put in query, as they should (pseudo-insert-mode).

but it can quickly become messy, and very unfun to write. as here:

    --bind=j:down,k:up,s:jump,p:toggle-preview \
    --bind=h:backward-char,l:forward-char,e:forward-word,b:backward-word \
    --bind=d:clear-query \
    --bind='y:execute(echo {} | xsel -b)' \
    --bind=E:preview-half-page-down,U:preview-half-page-up \
    --bind=c:cancel,x:forward-char+backward-delete-char \
    --bind=X:backward-delete-char \
    --bind=start:enable-search+unbind(e,j,s,p,h,l,é,b,d,y,E,U,c,x,X,i,a,A,I)  \
    --bind=i:enable-search+unbind(j,k,s,p,h,l,e,b,d,y,E,U,c,x,X,i,a,A,I) \
    --bind=a:enable-search+unbind(j,k,s,p,h,l,e,b,d,y,E,U,c,x,X,i,a,A,I)+forward-char \
    --bind=A:enable-search+unbind(j,k,s,p,h,l,e,b,d,y,E,U,c,x,X,i,a,A,I)+end-of-line \
    --bind=I:enable-search+unbind(j,k,s,p,h,l,e,b,d,y,E,U,c,x,X,i,a,A,I)+beginning-of-line \
    --bind=esc:disable-search+rebind(j,k,s,p,h,l,e,b,d,y,E,U,c,x,X,i,a,A,I) \
    --bind=®:backward-kill-word,change:top,backward-eof:abort

same patterns again and again, plus it is required to be consistent: worth to script it. the simple python script provided here is based on a simple configuration file, which will export a single line option for fzf (that i personally just copy-paste and append it to FZF_DEFAULT_OPTS in my .bashrc). here is the configuration which will generate options above:

[mode]
escape = esc
insert_before = i
insert_after = a 
insert_end_line = A
insert_beginning_line = I

[normal]
j = down
k = up
s = jump
p = toggle-preview
h = backward-char
l = forward-char
e = forward-word
b = backward-word
d = clear-query
y = execute(echo {} | xsel -b)
E = preview-half-page-down
U = preview-half-page-up
c = cancel
x = forward-char+backward-delete-char
X = backward-delete-char

[insert]
® = backward-kill-word
change = top
backward-eof = abort

dependancies

no dependancies, it uses the configparser standard library.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.