Skip to content

Commit

Permalink
perf(config): clean old configs (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 authored Dec 6, 2023
1 parent dae8b9d commit 01a27ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3,960 deletions.
213 changes: 1 addition & 212 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ https://github.com/linrongbin16/fzfx.nvim/assets/6496887/47b03150-14e3-479a-b1af
- [Commands](#-commands)
- [Recommended Key Mappings](#-recommended-key-mappings)
- [Configuration](#-configuration)
- [Defaults](#defaults)
- [Create Your Own Command](#create-your-own-command)
- [API References](#api-references)
- [Credit](#-credit)
Expand Down Expand Up @@ -1264,220 +1263,10 @@ require('fzfx').setup(option)

The `option` is an optional lua table that override the default options.

### Defaults

<details>
<summary><i>Click here to see default options</i></summary>

````lua
local Defaults = {
-- commands group
files = ...,
live_grep = ...,
buffers = ...,
git_files = ...,
git_status = ...,
lsp_diagnostics = ...,
...

yank_history = {
other_opts = {
-- max size of saved yank history.
-- yank history internally is saved in a ring buffer, which can not grow indefinitely
maxsize = 100,
},
},

-- define your own commands group here,
-- please check [Create Your Own Command](#create-your-own-command).
users = nil,

-- fzf options for all commands.
-- each commands group also has a 'fzf_opts' field that can overwrite this.
fzf_opts = {
"--ansi",
"--info=inline",
"--layout=reverse",
"--border=rounded",
"--height=100%",
"--bind=ctrl-e:toggle",
"--bind=ctrl-a:toggle-all",
"--bind=alt-p:toggle-preview",
"--bind=ctrl-f:preview-half-page-down",
"--bind=ctrl-b:preview-half-page-up",
},

-- global fzf opts with highest priority.
--
-- there're two 'fzf_opts' configs: root level, commands level, for example if the configs is:
--
-- ```lua
-- require('fzfx').setup({
-- live_grep = {
-- fzf_opts = {
-- '--disabled',
-- { '--prompt', 'Live Grep > ' },
-- { '--preview-window', '+{2}-/2' },
-- },
-- },
-- fzf_opts = {
-- '--no-multi',
-- { '--preview-window', 'top,70%' },
-- },
-- })
-- ```
--
-- finally the engine will emit below options to the 'fzf' binary:
--
-- ```bash
-- fzf --no-multi --disabled --prompt 'Live Grep > ' --preview-window '+{2}-/2'
-- ```
--
-- note: the '--preview-window' option in root level will be override by command level (live_grep).
--
-- now 'override_fzf_opts' provide the highest priority global options that can override command level 'fzf_opts',
-- so help users to easier config the fzf opts such as '--preview-window'.
override_fzf_opts = {},

-- fzf colors extract from vim colorscheme's syntax to RGB color code (e.g., #728174),
-- and pass to fzf '--color' option.
-- see: https://github.com/junegunn/fzf/blob/master/README-VIM.md#explanation-of-gfzf_colors
fzf_color_opts = {
fg = { "fg", "Normal" },
bg = { "bg", "Normal" },
hl = { "fg", "Comment" },
["fg+"] = { "fg", "CursorLine", "CursorColumn", "Normal" },
["bg+"] = { "bg", "CursorLine", "CursorColumn" },
["hl+"] = { "fg", "Statement" },
info = { "fg", "PreProc" },
border = { "fg", "Ignore" },
prompt = { "fg", "Conditional" },
pointer = { "fg", "Exception" },
marker = { "fg", "Keyword" },
spinner = { "fg", "Label" },
header = { "fg", "Comment" },
preview_label = { "fg", "Label" },
},

-- icons
-- nerd fonts: https://www.nerdfonts.com/cheat-sheet
-- unicode: https://symbl.cc/en/
icons = {
unknown_file = ""
folder = "",
folder_open = "",

fzf_pointer = "",
fzf_marker = "",
},

-- popup window options for all commands.
-- each commands group also has a 'win_opts' field that can overwrite this.
popup = {
-- float window options pass to 'vim.api.nvim_open_win()' API.
win_opts = {
-- by default popup window is in the centor of editor.
-- you can also place it relative to
-- 1. editor: whole vim.
-- 2. win: current window.
-- 3. cursor: cursor in current window.
relative = 'editor',

-- height/width.
--
-- 1. if 0 <= h/w <= 1, evaluate proportionally according to editor's lines and columns,
-- or window's height and width, e.g. popup height = h * lines, width = w * columns.
--
-- 2. if h/w > 1, evaluate as absolute height and width,
-- directly pass to `vim.api.nvim_open_win` api.
--
height = 0.85,
width = 0.85,

-- when relative is 'editor' or 'win', the anchor is the center position,
-- not default 'NW' (north west).
-- because 'NW' is a little bit complicated for users to calculate the position,
-- usually we just put the popup window in the center of editor.
--
-- 1. if -0.5 <= r/c <= 0.5, evaluate proportionally according to editor's lines and columns.
-- e.g. shift rows = r * lines, shift columns = c * columns.
--
-- 2. if r/c <= -1 or r/c >= 1, evaluate as absolute rows/columns to be shift.
-- e.g. you can easily set 'row = -vim.o.cmdheight' to move popup window up 1~2 lines
-- (based on your 'cmdheight' option).
-- this is especially useful when popup window is too big and conflicts with status line at bottom.
--
-- 3. r/c cannot be in range (-1, -0.5) or (0.5, 1), it makes no sense.
--
-- when relative is 'cursor', the anchor is 'NW' (north west).
-- because we just want to put the popup window relative to the cursor.
-- so 'row' and 'col' will be directly passed to `vim.api.nvim_open_win` API without any pre-processing.
--
row = 0,
col = 0,

border = "none",
zindex = 51,
},
},

-- environment variables
env = {
-- by default use `vim.env.VIM` (e.g., `/usr/local/bin/nvim`) as the lua script interpreter,
-- you can overwrite by set this option.
nvim = nil,

-- by default use `vim.fn['fzf#exec']` function as the fzf binary,
-- you can overwrite by set this option.
fzf = nil,
},

-- cache
cache = {
-- for macOS/linux: ~/.local/share/nvim/fzfx.nvim
-- for Windows: ~/AppData/Local/nvim-data/fzfx.nvim
dir = require("fzfx.path").join(vim.fn.stdpath("data"), "fzfx.nvim"),
},

-- debug
debug = {
-- enable debug
enable = false,

-- print logs to console (command line).
console_log = true,

-- write logs to file.
-- for macOS/linux: ~/.local/share/nvim/fzfx.log
-- for Windows: ~/AppData/Local/nvim-data/fzfx.log
file_log = false,
},
}
````

Each commands group (e.g., `files`, `live_grep`, `git_files`, `lsp_diagnostics`, etc) share the same schema:

1. `commands`: a user command, or more variants feed with different types of input queries, each command is binding with a provider.
2. `providers`: one or more data sources, that provide lines for fzf binary (e.g., on the left side). A provider can be:
1. A plain shell command, e.g., `fd . -cnever -tf`.
2. A lua function that returns shell command, e.g., `rg --column -n --no-heading -H 'fzfx'` (here user's input `'fzfx'` is dynamically passing to the provider on every keystroke).
3. A lua function that directly returns the lines for fzf binary. Some data sources are not from shell commands, for example buffers, lsp diagnostics, thus we need to directly generate the lines.
3. `previewers`: one or more lua function that can generate the preview content for the fzf binary (e.g., on the right side). A previewer can be:
1. A lua function that returns shell command, e.g., `bat --color=always --highlight-line=17 lua/fzfx/config.lua`.
2. A lua function that directly returns the preview contents for fzf binary.
3. A nvim buffer that shows the preview content (todo).
4. `actions`: allow user press key and exit fzf popup, and invoke callback function with selected lines.
5. (Optional) `interactions`: allow user press key and invoke callback function on current line, without exiting fzf popup.
6. (Optional) `fzf_opts`, `win_opts` and `other_opts`: specific options overwrite the common defaults, or provide other abilities.

</details>

For complete defaults, please see [config.lua](https://github.com/linrongbin16/fzfx.nvim/blob/main/lua/fzfx/config.lua) (start from `local Defaults`).
For complete default options, please see [config.lua](https://github.com/linrongbin16/fzfx.nvim/blob/main/lua/fzfx/config.lua).

For advanced configurations, please check [Advanced Configuration](https://github.com/linrongbin16/fzfx.nvim/wiki/Advanced-Configuration).

If you have encounter some breaks on configuration, please see [CHANGELOG.md](https://github.com/linrongbin16/fzfx.nvim/blob/main/CHANGELOG.md).

### Create Your Own Command

Here's a minimal commands group example that implement the `ls -1` like command `FzfxLs`:
Expand Down
Loading

0 comments on commit 01a27ce

Please sign in to comment.