1
0
Fork 0
fzf.kak/README.md

308 lines
12 KiB
Markdown
Raw Permalink Normal View History

2018-09-22 10:59:28 +00:00
# fzf.kak
2018-09-22 11:15:53 +00:00
2019-03-27 10:31:42 +00:00
[![GitHub release][1]][2] [![GitHub Release Date][3]][4]
![Github commits (since latest release)][5] ![license][6]
2018-09-24 14:42:50 +00:00
2022-01-08 07:55:23 +00:00
fzf.kak is a plugin for [Kakoune][7] editor, that provides integration with the [fzf][8] tool.
There's also limited support for [skim][9], which can be enabled by changing the `fzf_implementation` option.
2018-09-22 11:15:53 +00:00
2019-03-27 10:31:42 +00:00
![showcase][10]
2018-10-11 14:53:25 +00:00
2021-03-19 19:38:01 +00:00
2018-09-22 11:15:53 +00:00
## Installation
2021-03-19 19:38:01 +00:00
### With [plug.kak][11]
2018-09-24 08:54:05 +00:00
2022-01-08 07:55:23 +00:00
The recommended way to install fzf.kak is to use a plug.kak plugin manager.
To install fzf.kak add this to the `kakrc`:
2021-03-19 19:38:01 +00:00
``` kak
plug "andreyorst/fzf.kak"
```
2021-03-19 19:38:01 +00:00
Then reload the configuration file or restart Kakoune and run `:plug-install`.
2021-03-19 19:38:01 +00:00
### Without plugin manager
2022-01-08 07:55:23 +00:00
This plugin consists of several parts which are referred to as "modules".
So, for the plugin to work the base module must be loaded:
2021-03-19 19:38:01 +00:00
``` sh
source "/path/to/fzf.kak/rc/fzf.kak" # loading base fzf module
```
2022-01-08 07:55:23 +00:00
This module doesn't do anything on its own.
Each module in the `modules` directory provides features that extend the base `fzf` module with new commands and mappings.
2021-03-19 19:38:01 +00:00
Those can be loaded manually one by one the same way as the base module, or with the use of the `find` command:
2021-03-19 19:38:01 +00:00
``` sh
evaluate-commands %sh{
find -L "path/to/fzf.kak/modules/" -type f -name '*.kak' -exec printf 'source "%s"\n' {} \;
}
```
2018-09-22 11:15:53 +00:00
## Usage
2021-03-19 19:38:01 +00:00
2022-01-08 07:55:23 +00:00
fzf.kak provides a `fzf-mode` command that can be mapped to preferred key:
2018-11-24 12:44:18 +00:00
```kak
map global normal <c-p> ': fzf-mode<ret>'
```
2018-11-24 12:44:18 +00:00
2021-03-19 19:38:01 +00:00
This will invoke the user mode, which contains mnemonic keybindings for each sub-module.
If all modules were loaded, the following mappings are available:
2019-03-28 06:05:17 +00:00
- <kbd>b</kbd> - Select buffer.
- <kbd>c</kbd> - Switch server's working directory.
- <kbd>f</kbd> - Search for file and open it.
- <kbd>v</kbd> - Edit file in version control system tree.
- <kbd>Alt</kbd>+<kbd>v</kbd> - Explicitly select which VCS command to run.
- <kbd>s</kbd> - Search over buffer contents and jump to result line.
- <kbd>t</kbd> - Browse ctags tags.
- <kbd>Alt</kbd>+<kbd>t</kbd> - Select tag kind filter on per language basis.
2019-03-28 09:53:41 +00:00
- <kbd>g</kbd> - Interactive grep.
2019-03-30 16:31:11 +00:00
- <kbd>p</kbd> - Project selector.
- <kbd>Alt</kbd>+<kbd>p</kbd> - Project related commands.
2019-03-28 06:05:17 +00:00
2022-01-08 07:55:23 +00:00
When Kakoune runs inside Tmux, fzf.kak will use the bottom split to display the `fzf` window.
Additional keybindings are also made available to open files in a vertical or horizontal split.
2021-03-19 19:38:01 +00:00
Otherwise, the `terminal` command is being used to create new windows.
2019-03-28 06:05:17 +00:00
2019-03-28 09:53:41 +00:00
## Configuration
2021-03-19 19:38:01 +00:00
2022-01-08 07:55:23 +00:00
fzf.kak features a lot of settings via options that can be altered to change how fzf.kak behaves.
Each `.kak` file provides a Kakoune module, so any settings which alter variable values should be wrapped in the `ModuleLoaded` hook.
See [plug.kak manual section for `defer`](https://github.com/andreyorst/plug.kak/tree/master#deferring-plugin-configuration) that explains how to do this when using the plug.kak.
### Default query
2021-03-19 19:38:01 +00:00
2021-03-19 19:48:55 +00:00
| module |
|--------|
| `fzf` |
2021-03-19 19:38:01 +00:00
2022-01-08 07:55:23 +00:00
By default main selection is used as the default query for `fzf`, but only if the selection is more than 1 character long.
2021-03-19 19:38:01 +00:00
This can be disabled by setting `fzf_use_main_selection` to `false`.
### Windowing
2021-03-19 19:38:01 +00:00
2021-03-19 19:48:55 +00:00
| module |
|--------|
| `fzf` |
2021-03-19 19:38:01 +00:00
When using Tmux fzf.kak automatically creates all needed Tmux splits and panes for you.
2022-01-08 07:55:23 +00:00
In other cases fzf.kak uses the `fzf_terminal_command` option to call the windowing command to create new windows.
2021-03-19 18:36:37 +00:00
By default it is set to use `terminal` alias: `terminal kak -c %val{session} -e "%arg{@}"`, but some terminals can provide other aliases or commands, like `terminal-tab` in Kitty.
2021-03-19 19:38:01 +00:00
2019-05-13 18:34:46 +00:00
### Mappings
2021-03-19 19:38:01 +00:00
2021-03-19 19:48:55 +00:00
| module |
|--------|
| `fzf` |
2021-03-19 19:38:01 +00:00
Keys that are used in the `fzf` window can be configured with these options:
2019-05-13 18:34:46 +00:00
2022-01-08 07:55:23 +00:00
- `fzf_window_map` - mapping to perform an action in a new window,
2021-03-19 18:36:37 +00:00
- `fzf_vertical_map` - mapping to perform an action in new vertical split (Tmux),
2019-05-13 18:34:46 +00:00
- `fzf_horizontal_map` - mapping to perform an action in new horizontal split.
2021-03-19 18:36:37 +00:00
These options should be set to work with fzf `--expect` parameter, so check out fzf documentation on this.
2019-05-13 18:34:46 +00:00
2021-03-19 19:38:01 +00:00
2019-03-28 09:53:41 +00:00
### File command
2021-03-19 19:38:01 +00:00
2021-03-19 19:48:55 +00:00
| module |
|------------|
| `fzf-file` |
2021-03-19 19:38:01 +00:00
2022-01-08 07:55:23 +00:00
A command that is used to search for files and their arguments can be configured by changing the value of the `fzf_file_command` variable, which is available in the `fzf-file` module.
2021-03-19 19:38:01 +00:00
2021-03-19 18:36:37 +00:00
Supported tools are [GNU Find][12], [The Silver Searcher][13], [ripgrep][14], [fd][15].
2022-01-08 07:55:23 +00:00
A default set of arguments is provided for each of these searchers, only the name of the tool can be assigned to the `fzf_file_command` variable:
2018-09-22 17:25:20 +00:00
```kak
2019-03-28 06:05:17 +00:00
set-option global fzf_file_command 'rg' # 'ag', 'fd', or 'find'
2018-09-22 17:25:20 +00:00
```
2022-01-08 07:55:23 +00:00
Default arguments can be changed by setting the complete command to execute:
2018-09-22 17:25:20 +00:00
```kak
set-option global fzf_file_command "find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type f -print"
```
2019-03-28 09:53:41 +00:00
### Preview
2021-03-19 19:38:01 +00:00
2021-03-19 19:48:55 +00:00
| module |
|------------|
| `fzf-file` |
2021-03-19 19:38:01 +00:00
2022-01-08 07:55:23 +00:00
fzf.kak tries to automatically detect where to show preview window, depending on the aspect ratio of the new terminal window.
By default, if the doubled height is bigger than the width, preview occupies the upper 60% of space.
If the height is smaller than the width, a preview is shown on the right side.
2021-03-19 19:38:01 +00:00
These amounts can be configured with `fzf_preview_height` and `fzf_preview_width` options.
2019-03-28 09:53:41 +00:00
2022-01-08 07:55:23 +00:00
When using fzf.kak inside `tmux`, the bottom pane is used for all `fzf` commands, and the preview window is displayed on the right side.
When the preview is turned on, the height of the `tmux` split is increased to provide more space.
2021-03-19 19:38:01 +00:00
Split height can be configured with the `fzf_preview_tmux_height` variable.
2019-03-28 09:53:41 +00:00
2022-01-08 07:55:23 +00:00
Amount of lines in the preview window can be changed with the `fzf_preview_lines` option.
2019-03-28 09:53:41 +00:00
2022-01-08 07:55:23 +00:00
The preview feature can be disabled entirely by setting the `fzf_preview` option to `false`.
2021-03-19 19:38:01 +00:00
2019-03-28 09:53:41 +00:00
#### Highlighting preview window
2021-03-19 19:38:01 +00:00
2021-03-19 19:48:55 +00:00
| module |
|------------|
| `fzf-file` |
2021-03-19 19:38:01 +00:00
2022-01-08 07:55:23 +00:00
Contents of the file displayed within the preview window can be syntax highlighted.
This can be enabled by specifying a highlighter to use with the `fzf_highlight_command` option.
2021-03-19 19:38:01 +00:00
These highlighters are are supported out of the box:
2019-03-28 09:53:41 +00:00
* [Bat][16]
* [Coderay][17]
* [Highlight][18]
* [Rouge][19]
2022-01-08 07:55:23 +00:00
Although other tools are not supported by the script, they should work fine as long as they work with `fzf`.
2019-03-28 09:53:41 +00:00
2021-03-19 19:38:01 +00:00
2019-03-28 09:53:41 +00:00
### VCS
2021-03-19 19:38:01 +00:00
2021-03-19 19:48:55 +00:00
| module |
|-----------|
| `fzf-vcs` |
2021-03-19 19:38:01 +00:00
2021-03-19 18:36:37 +00:00
This script supports these version control systems: Git, Subversion, GNU Bazaar, and Mercurial.
2021-03-19 19:38:01 +00:00
By default <kbd>v</kbd> mapping from `fzf` mode will detect your version control system automatically.
To explicitly use some particular VCS command, the <kbd>Alt</kbd>+<kbd>v</kbd> mapping can be used, which includes all supported VCS shortcuts.
2021-03-19 19:38:01 +00:00
To set parameters to VCS command used to provide project files the following options can be used:
2018-10-11 12:01:55 +00:00
* `fzf_git_command`
* `fzf_svn_command`
* `fzf_bzr_command`
* `fzf_hg_command`
2021-03-19 18:36:37 +00:00
Other VCS are not supported officially.
2021-03-19 19:38:01 +00:00
Feature requests and merge requests are welcome.
2019-03-28 09:53:41 +00:00
### Tmux
2021-03-19 19:38:01 +00:00
2021-03-19 19:48:55 +00:00
| module |
|--------|
| `fzf` |
2021-03-19 19:38:01 +00:00
When running inside Tmux, `fzf` will use bottom split.
2022-01-08 07:55:23 +00:00
The height of this split can be changed with the `fzf_tmux_height` option.
`fzf_tmux_height_file_preview` option is used to control the height of the split when file-preview is turned on.
2021-03-19 19:38:01 +00:00
2018-11-24 15:45:03 +00:00
### Projects
2021-03-19 19:38:01 +00:00
2021-03-19 19:48:55 +00:00
| module |
|---------------|
| `fzf-project` |
2021-03-19 19:38:01 +00:00
2022-01-08 07:55:23 +00:00
fzf.kak has basic project manipulation capabilities.
2021-03-19 19:38:01 +00:00
To store projects a hidden file is created in `%val{config}` and called `.fzf-projects`.
The location of this file and its name can be changed by modifying the `fzf_project_file` option.
2022-01-08 07:55:23 +00:00
By default project paths that start from the home directory will use `~` instead of the real path.
2021-03-19 19:38:01 +00:00
To change this, set `fzf_project_use_tilda` option to `false`.
2019-03-28 09:53:41 +00:00
## `fzf` command
2021-03-19 19:38:01 +00:00
2021-03-19 18:36:37 +00:00
`fzf` command can be used from prompt mode and for [scripting][20].
2021-03-19 19:38:01 +00:00
The following arguments are supported:
2021-03-19 18:36:37 +00:00
- `-kak-cmd`: A Kakoune command that is applied to `fzf` resulting value, e.g. `edit -existing`, `change-directory`, e.t.c.
2022-01-08 07:55:23 +00:00
- `-multiple-cmd`: A Kakoune command that is applied when multiple items are selected to every item but the first one.
- `-items-cmd`: A command that is used as a pipe to provide a list of values to `fzf`.
For example, if we want to pass a list of all files recursively in the current directory, we would use `-items-cmd %{find .}` which will be piped to the `fzf` tool.
2021-03-19 18:36:37 +00:00
- `-fzf-impl`: Override `fzf` implementation variable.
2022-01-08 07:55:23 +00:00
Can be used if the command needs to provide different arguments to `fzf`.
2021-03-19 18:36:37 +00:00
See [sk-grep.kak][21] as example.
2019-03-27 10:31:42 +00:00
- `-fzf-args`: Additional flags for `fzf` program.
2021-03-19 18:36:37 +00:00
- `-preview-cmd`: A preview command.
Can be used to override default preview handling.
2022-01-08 07:55:23 +00:00
- `-preview`: If specified, the command will ask for a preview.
- `-filter`: A pipe which will be applied to the result provided by `fzf`.
2021-03-19 18:36:37 +00:00
For example, if we are returning such line `3 hello, world!` from `fzf`, and we are interested only in the first field which is `3`, we can use `-filter %{cut -f 1}`.
2022-01-08 07:55:23 +00:00
Basically, everything that `fzf` returns is piped to this filter command.
2021-03-19 18:36:37 +00:00
See [fzf-search.kak][22] as example.
2022-01-08 07:55:23 +00:00
- `-post-action`: Extra commands that are performed after the `-kak-cmd` command.
2019-03-27 10:31:42 +00:00
2021-03-19 19:38:01 +00:00
2018-11-24 15:45:03 +00:00
## Contributing
2021-03-19 19:38:01 +00:00
Please do.
2022-01-08 07:55:23 +00:00
If you want to contribute to fzf.kak by adding a module, you can submit one by providing a pull request, or just open a feature request and we'll see what can be done.
2018-11-24 15:45:03 +00:00
2021-03-19 19:38:01 +00:00
The basic idea behind the module structure can be described as:
1. Provide a user module;
2022-01-08 07:55:23 +00:00
2. Define a command that calls the `fzf` function with appropriate arguments;
3. Create a mapping in a `ModuleLoaded` hook, that requires a new module, and calls the command.
2018-11-24 15:45:03 +00:00
2021-03-19 19:38:01 +00:00
See how existing modules are implemented to understand the idea of how modules are constructed.
2018-11-24 15:45:03 +00:00
2019-03-27 10:31:42 +00:00
2020-05-24 09:46:52 +00:00
### External modules
2021-03-19 19:38:01 +00:00
2021-03-19 18:36:37 +00:00
Support for [yank-ring.kak][25] was externalized to separate plugin [fzf-yank-ring.kak][24]
2020-05-24 09:46:52 +00:00
2021-09-11 11:33:51 +00:00
# Alternatives
There are another (often more simple and robust) plugins, which add support for integration with `fzf` or other fuzzy finders that you might be interested in:
1. [peneira][26] - a fuzzy finder implemented specifically for Kakoune.
2. [connect.kak][27] - a tool that allows you to connect Kakoune with various applications like `fzf` and more.
3. [kakoune.cr][28] - a similar tool to `connect.kak`, but written in the Crystal language.
Also allows you to connect Kakoune to other applications, including `fzf`.
2019-03-27 10:31:42 +00:00
[1]: https://img.shields.io/github/release/andreyorst/fzf.kak.svg
[2]: https://github.com/andreyorst/fzf.kak/releases
[3]: https://img.shields.io/github/release-date/andreyorst/fzf.kak.svg
[4]: https://github.com/andreyorst/fzf.kak/releases
[5]: https://img.shields.io/github/commits-since/andreyorst/fzf.kak/latest.svg
[6]: https://img.shields.io/github/license/andreyorst/fzf.kak.svg
[7]: https://github.com/mawww/kakoune
[8]: https://github.com/junegunn/fzf
[9]: https://github.com/lotabout/skim
[10]: https://user-images.githubusercontent.com/19470159/46813471-6ee76800-cd7f-11e8-89aa-123b3a5f9f1b.gif
[11]: https://github.com/andreyorst/plug.kak
[12]: https://www.gnu.org/software/findutils/
[13]: https://github.com/ggreer/the_silver_searcher
[14]: https://github.com/BurntSushi/ripgrep
[15]: https://github.com/sharkdp/fd
[16]: https://github.com/sharkdp/bat
[17]: https://github.com/rubychan/coderay
[18]: https://gitlab.com/saalen/highlight
[19]: https://github.com/jneen/rouge
[20]: #writing-a-module
[21]: rc/modules/sk-grep.kak
[22]: rc/modules/fzf-search.kak
2019-03-28 09:53:41 +00:00
[23]: #configuration
2020-05-24 09:46:52 +00:00
[24]: https://gitlab.com/losnappas/fzf-yank-ring.kak
[25]: https://github.com/alexherbo2/yank-ring.kak
2021-09-11 11:33:51 +00:00
[26]: https://github.com/gustavo-hms/peneira
[27]: https://github.com/kakounedotcom/connect.kak
2021-09-11 11:34:40 +00:00
[28]: https://github.com/alexherbo2/kakoune.cr
2021-03-19 18:36:37 +00:00
<!-- LocalWords: Github Kakoune fzf kak config VCS ctags Tmux fd sk
LocalWords: ripgrep readme Coderay rc
-->