Coder Social home page Coder Social logo

linearf's Introduction

linearf

A fast and extensible fuzzy finder for vimmers

Concept

  • Show the first view faster
  • Find as fast as if they were in linear time
  • High modularity and extensibility

Requirements

  • cargo nightly
  • vim and +lua/dyn, or neovim and luajit

Usage

First, install the plugins and sources locally. If you use dein as your package manager, it will look like this.

call dein#add('octaltree/linearf', {'merged': 0})
call dein#add('octaltree/linearf-my-flavors') # optional

Paste config

--lua<<EOF
-- If you paste in vimrc, surround with EOF

local linearf = require('linearf')
local flavors = require('linearf-my-flavors')

-- Initialize with a view module
linearf.init(require('linearf-vanilla').new())

-- Specify the sources to include in the build
linearf.recipe.sources = {
    {name = "identity", path = "flavors_plain::Identity"},
    {name = "command", path = "flavors_tokio::Command"}
}
linearf.recipe.converters = {
    {name = "format_line", path = "flavors_plain::FormatLine"}
}
linearf.recipe.matchers = {
    {name = "identity", path = "flavors_plain::Identity"},
    {name = "substring", path = "flavors_plain::Substring"},
    {name = "clap", path = "flavors_clap::Clap"}
}
-- Auto-build if you want
linearf.bridge.try_build_if_not_exist = true
linearf.bridge.try_build_on_error = true

-- Define your scenario. flavors provides you with several presets
local function set(target, context_manager, scenario)
    linearf.context_managers[target] = context_manager
    linearf.scenarios[target] = scenario
end
set('line', flavors.context_managers['line'], flavors.merge {
    flavors.scenarios['line'],
    flavors.scenarios.quit,
    flavors.scenarios.no_list_insert,
    flavors.scenarios.no_querier_normal,
    {
        linearf = {
            list_nnoremap = {
                ["<CR>"] = flavors.hide_and(flavors.actions.line.jump)
            },
            querier_inoremap = {
                ["<CR>"] = flavors.normal_and(
                    flavors.hide_and(flavors.actions.line.jump))
            }
        },
        view = {querier_on_start = 'insert'}
    }
})
local use_rg = false
set('file', flavors.context_managers[use_rg and 'file_rg' or 'file_find'],
    flavors.merge {
    flavors.scenarios[use_rg and 'file_rg' or 'file_find'],
    flavors.scenarios.quit,
    flavors.scenarios.no_list_insert,
    flavors.scenarios.no_querier_normal,
    {
        linearf = {
            list_nnoremap = {
                ["<CR>"] = flavors.hide_and(flavors.actions.file.open),
                ["<nowait>s"] = flavors.hide_and(flavors.actions.file.split),
                ["t"] = flavors.hide_and(flavors.actions.file.tabopen),
                ["v"] = flavors.hide_and(flavors.actions.file.vsplit)
            },
            querier_inoremap = {
                ["<CR>"] = flavors.normal_and(
                    flavors.hide_and(flavors.actions.file.open))
            }
        }
    }
})
set('grep', flavors.context_managers[use_rg and 'grep_rg' or 'grep_grep'],
    flavors.merge {
    flavors.scenarios[use_rg and 'grep_rg' or 'grep_grep'],
    flavors.scenarios.quit,
    flavors.scenarios.no_list_insert,
    flavors.scenarios.enter_list,
    {
        linearf = {
            list_nnoremap = {
                ["<CR>"] = flavors.hide_and(flavors.actions.grep.open),
                ["<nowait>s"] = flavors.hide_and(flavors.actions.grep.split),
                ["t"] = flavors.hide_and(flavors.actions.grep.tabopen),
                ["v"] = flavors.hide_and(flavors.actions.grep.vsplit)
            },
            querier_inoremap = {},
            querier_nnoremap = {
                ["<nowait><ESC>"] = flavors.actions.view.goto_list
            }
        }
    }
})

-- optional
linearf.utils.command(
    "nnoremap <silent><space>/ :<c-u>lua linearf.run('line')<CR>")
linearf.utils.command(
    "nnoremap <silent><space>f :<c-u>lua linearf.run('file')<CR>")
linearf.utils.command(
    "nnoremap <silent><space>g :<c-u>lua linearf.run('grep')<CR>")
linearf.utils.command(
    "nnoremap <silent><space>l :<c-u>lua linearf.resume_last()<CR>")


-- for vimrc
--EOF

Then run with the pre-defined scenario and its difference.

lua lnf('line')
lua lnf('line', {})

For more information, see :help linearf

TODO

  • implement logic
  • runtime reloading and auto building
  • implement view
  • implement action
  • implement linearf-my-flavors
  • use vim as a fuzzy finder from CLI
  • implement preview

linearf's People

Contributors

octaltree avatar

Watchers

 avatar

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.