Skip to content

Commit

Permalink
perf: reduce ESC keys & better multi keys (#61)
Browse files Browse the repository at this point in the history
* perf: reduce ESC key

* break: change default multi keys

* doc: builtin keys
  • Loading branch information
linrongbin16 committed Aug 15, 2023
1 parent 8c419e5 commit e159895
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 49 deletions.
67 changes: 39 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This is the next generation of [fzfx.vim](https://github.com/linrongbin16/fzfx.v
## Feature

- Windows support.
- Icons.
- Icons & Colors (todo).
- Multiple variants to avoid manual input:
- Search by visual select.
- Search by cursor word.
Expand Down Expand Up @@ -157,7 +157,7 @@ require("lazy").setup({
## Commands
Command Naming Rules:
Commands are named following below rules:
- All commands are named with prefix `Fzfx`.
- The main command name has no suffix.
Expand All @@ -166,80 +166,91 @@ Command Naming Rules:
- The cursor word variant is named with `W` suffix.
- The yank text variant is named with `P` suffix (just like press the `p` key).
> Command names can be configured, see [Configuration](#configuration).
> Note: command names can be configured, see [Configuration](#configuration).
Here're some most useful builtin keys inside fzf terminal:
- Preview keys
- `ctrl-l`: toggle preview.
- Multi keys
- `ctrl-e`: select.
- `ctrl-d`: deselect.
- `ctrl-a`: select all.
- `alt-a`: deselect all.
> Note: builtin keys can be configured, see [Configuration](#configuration).
<table>
<thead>
<tr>
<th>Group</th>
<th>Command</th>
<th>Mode</th>
<th>Description</th>
<th>Multi Key?</th>
<th>Preview Key?</th>
<th>Special Feature</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="4">Files</td>
<td>FzfxFiles(U)</td>
<td>Normal</td>
<td>Find files (unrestricted)</td>
<td>N</td>
<td rowspan="4">Yes</td>
<td rowspan="4">Yes</td>
<td rowspan="4"></td>
</tr>
<tr>
<td>FzfxFiles(U)V</td>
<td>Visual</td>
<td>Find files (unrestricted) by visual select</td>
<td>V</td>
</tr>
<tr>
<td>FzfxFiles(U)W</td>
<td>Normal</td>
<td>Find files (unrestricted) by cursor word</td>
<td>N</td>
</tr>
<tr>
<td>FzfxFiles(U)P</td>
<td>Normal</td>
<td>Find files (unrestricted) by yank text</td>
<td>N</td>
</tr>
<tr>
<td rowspan="4">Live Grep</td>
<td>FzfxLiveGrep(U)</td>
<td>Normal</td>
<td>Live grep (unrestricted)</td>
<td>N</td>
<td rowspan="4">Yes</td>
<td rowspan="4">Yes</td>
<td rowspan="4">1. Use `--` to pass raw options to search command (grep, rg)</td>
</tr>
<tr>
<td>FzfxLiveGrep(U)V</td>
<td>Visual</td>
<td>Live grep (unrestricted) by visual select</td>
<td>V</td>
</tr>
<tr>
<td>FzfxLiveGrep(U)W</td>
<td>Normal</td>
<td>Live grep (unrestricted) by cursor word</td>
<td>N</td>
</tr>
<tr>
<td>FzfxLiveGrep(U)P</td>
<td>Normal</td>
<td>Live grep (unrestricted) by yank text</td>
<td>N</td>
</tr>
<tr>
<td rowspan="4">Buffers</td>
<td>FzfxBuffers</td>
<td>Normal</td>
<td>Find buffers</td>
<td>N</td>
<td rowspan="4">Yes</td>
<td rowspan="4">Yes</td>
<td rowspan="4"></td>
</tr>
<tr>
<td>FzfxBuffersV</td>
<td>Visual</td>
<td>Find buffers by visual select</td>
<td>V</td>
</tr>
<tr>
<td>FzfxBuffersW</td>
<td>Normal</td>
<td>Find buffers by cursor word</td>
<td>N</td>
</tr>
<tr>
<td>FzfxBuffersP</td>
<td>Normal</td>
<td>Find buffers by yank text</td>
<td>N</td>
</tr>
</tbody>
</table>
Expand Down
47 changes: 28 additions & 19 deletions lua/fzfx/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ local default_fd_command =
string.format("%s -cnever -tf -tl -L -i", constants.fd)
local default_rg_command =
string.format("%s --column -n --no-heading --color=always -S", constants.rg)
--- @type table<string, string|string[]>
local default_fzf_opts = {
multi = "--multi",
select = { "--bind", "ctrl-e:select" },
deselect = { "--bind", "ctrl-d:deselect" },
select_all = { "--bind", "ctrl-a:select-all" },
deselect_all = { "--bind", "alt-a:deselect-all" },
toggle_preview = { "--bind", "ctrl-l:toggle-preview" },
}

--- @alias Config table<string, any>

Expand Down Expand Up @@ -107,12 +116,12 @@ local Defaults = {
},
},
fzf_opts = {
"--multi",
{ "--bind", "ctrl-s:select" },
{ "--bind", "ctrl-alt-s:deselect" },
{ "--bind", "ctrl-a:select-all" },
{ "--bind", "ctrl-alt-a:deselect-all" },
{ "--bind", "ctrl-l:toggle-preview" },
default_fzf_opts.multi,
default_fzf_opts.select,
default_fzf_opts.deselect,
default_fzf_opts.select_all,
default_fzf_opts.deselect_all,
default_fzf_opts.toggle_preview,
},
},

Expand Down Expand Up @@ -212,12 +221,12 @@ local Defaults = {
},
},
fzf_opts = {
"--multi",
{ "--bind", "ctrl-s:select" },
{ "--bind", "ctrl-alt-s:deselect" },
{ "--bind", "ctrl-a:select-all" },
{ "--bind", "ctrl-alt-a:deselect-all" },
{ "--bind", "ctrl-l:toggle-preview" },
default_fzf_opts.multi,
default_fzf_opts.select,
default_fzf_opts.deselect,
default_fzf_opts.select_all,
default_fzf_opts.deselect_all,
default_fzf_opts.toggle_preview,
},
other_opts = {
onchange_reload_delay = "sleep 0.1 && ",
Expand Down Expand Up @@ -270,7 +279,7 @@ local Defaults = {
actions = {
builtin = {
delete_buffer = {
"ctrl-d",
"ctrl-x",
require("fzfx.action").bdelete,
},
},
Expand All @@ -281,12 +290,12 @@ local Defaults = {
},
},
fzf_opts = {
"--multi",
{ "--bind", "ctrl-s:select" },
{ "--bind", "ctrl-alt-s:deselect" },
{ "--bind", "ctrl-a:select-all" },
{ "--bind", "ctrl-alt-a:deselect-all" },
{ "--bind", "ctrl-l:toggle-preview" },
default_fzf_opts.multi,
default_fzf_opts.select,
default_fzf_opts.deselect,
default_fzf_opts.select_all,
default_fzf_opts.deselect_all,
default_fzf_opts.toggle_preview,
},
other_opts = {
exclude_filetypes = { "qf", "neo-tree" },
Expand Down
4 changes: 2 additions & 2 deletions lua/fzfx/launch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ function Launch:new(popup, source, fzf_opts, actions, on_launch_exit)
-- close popup window and restore old window
popup:close()

-- press <ESC> if in insert mode
vim.api.nvim_feedkeys(esc_key, "x", false)
-- -- press <ESC> if in insert mode
-- vim.api.nvim_feedkeys(esc_key, "x", false)

log.ensure(
vim.fn.filereadable(result) > 0,
Expand Down

0 comments on commit e159895

Please sign in to comment.