1
0
Fork 0
fzf.kak/README.md

147 lines
6.9 KiB
Markdown
Raw Normal View History

2018-09-22 10:59:28 +00:00
# fzf.kak
2018-09-22 11:15:53 +00:00
2018-09-24 14:45:51 +00:00
[![GitHub release](https://img.shields.io/github/release/andreyorst/fzf.kak.svg)](https://github.com/andreyorst/fzf.kak/releases)
[![GitHub Release Date](https://img.shields.io/github/release-date/andreyorst/fzf.kak.svg)](https://github.com/andreyorst/fzf.kak/releases)
2018-09-24 14:42:50 +00:00
![Github commits (since latest release)](https://img.shields.io/github/commits-since/andreyorst/fzf.kak/latest.svg)
![license](https://img.shields.io/github/license/andreyorst/fzf.kak.svg)
2018-11-24 12:35:10 +00:00
**fzf.kak** is a plugin for [Kakoune](https://github.com/mawww/kakoune) editor, that brings integration with [fzf](https://github.com/junegunn/fzf)
tool. This plugin is being tested against Kakoune 2018.09.04.
2018-09-22 11:15:53 +00:00
2018-10-11 15:00:41 +00:00
![showcase](https://user-images.githubusercontent.com/19470159/46813471-6ee76800-cd7f-11e8-89aa-123b3a5f9f1b.gif)
2018-10-11 14:53:25 +00:00
2018-09-22 11:15:53 +00:00
## Installation
2018-09-24 08:54:05 +00:00
Recommended way to install is to use [plug.kak](https://github.com/andreyorst/plug.kak) plugin
manager. You can install **fzf.kak** by adding this to your `kakrc`:
2018-09-22 11:15:53 +00:00
```kak
2018-11-24 12:44:18 +00:00
plug "andreyorst/fzf.kak"
2018-09-22 11:15:53 +00:00
```
2018-09-24 08:54:05 +00:00
Then reload Kakoune config or restart Kakoune and run `:plug-install`.
Or install this plugin any other preferred way.
2018-09-22 11:15:53 +00:00
## Usage
2018-11-24 12:44:18 +00:00
There's no default key binding to invoke fzf, but **fzf.kak** provides a `fzf-mode` command that can be mapped to preferred key.
You can set your own mapping to invoke `fzf-mode`:
2018-11-24 12:44:18 +00:00
```kak
map global normal <c-p> ': fzf-mode<ret>'
# note that the space after colon is intentional to suppess fzf-mode to show in command history
```
2018-11-24 12:44:18 +00:00
Each fzf sub-command has mnemonic mapping, like `f` for opening files, `t` for tags and so on.
Available mappings:
2018-11-24 12:35:10 +00:00
- <kbd>b</kbd> - Select buffer
2018-11-24 12:44:18 +00:00
- <kbd>c</kbd> - Switch server's working directory
2018-11-24 12:35:10 +00:00
- <kbd>f</kbd> - Search for file and open it
- <kbd>v</kbd> - Edit file in version control system tree
- <kbd>Alt+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
2018-11-24 12:36:13 +00:00
- <kbd>Alt+t</kbd> - Select tag kind filter on per language basis
2018-09-22 11:15:53 +00:00
So for example pressing <kbd>Ctrl+p</kbd><kbd>f</kbd> will open fzf at the
bottom of the Kakoune buffer, showing you all possible files.
2018-09-22 17:25:20 +00:00
### Settings
**fzf.kak** features a lot of settings via options that can be altered to change how **fzf.kak** behaves.
#### Tmux
When using inside tmux, fzf will use bottom split. Height of this split can be changed with `fzf_tmux_height` option.
2018-11-24 12:44:18 +00:00
`fzf_tmux_height_file_preview` option is used to control height of the split when you do file searching with file-preview turned on.
2018-11-24 12:44:18 +00:00
#### File with file-preview turned on.
2018-09-22 17:25:20 +00:00
You can configure what command to use to search for files, and it's arguments.
2018-10-11 12:01:55 +00:00
Supported tools are [GNU Find](https://www.gnu.org/software/findutils/), [The Silver Searcher](https://github.com/ggreer/the_silver_searcher), [ripgrep](https://github.com/BurntSushi/ripgrep), [fd](https://github.com/sharkdp/fd). GNU find is used by default, but you can switch to another one. There are some default values for those, so you can go:
2018-09-22 17:25:20 +00:00
```kak
2018-10-11 12:01:55 +00:00
set-option global fzf_file_command 'rg' # 'ag', 'fd' or 'find'
2018-09-22 17:25:20 +00:00
```
Or if you don't like default file arguments, which are `find -type f`, and would like to disable searching in, say `.git` directories you can set it like so:
```kak
set-option global fzf_file_command "find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type f -print"
```
The same pattern applies for other commands, except `buffer`, and `cd`.
2018-10-11 12:01:55 +00:00
#### VCS
This script supports these version control systems: Git, Subversion, GNU Bazaar, Mercurial.
By default <kbd>v</kbd> mapping from `fzf mode` will detect your version control system and open fzf for you.
If you wish to explicitly use some particular vcs command, you can use `V` mapping, which includes
all supported vcs shortcuts.
2018-10-11 12:01:55 +00:00
You also able to set parameters to vcs command to use to provide project files. Supported options:
* `fzf_git_command`
* `fzf_svn_command`
* `fzf_bzr_command`
* `fzf_hg_command`
2018-10-11 12:01:55 +00:00
Other VCS are not supported officially. Open a feature request if you want some unsupported VCS to be included.
2018-11-24 12:44:18 +00:00
You also can change one of options to contain your VCS command, and use this command explicitly from VCS sub-mode.
#### ctags
2018-10-11 20:11:19 +00:00
It is also possible to add parameters to ctags search executable. like `sort -u` and others:
```kak
set-option global fzf_tag_command 'readtags -l | cut -f1 | sort -u | ... '
```
Though it is not recommended, since `sort` may slowdown `fzf-tag` on huge projects.
##### Filtering tags
Since ctags supports showing particular kind of tag for many languages,
`fzf-tag` dinamicly defines mappings for those languages with <kbd>Alt</kbd> key based on current filetype.
For example to show only functions while `fzf-tag` is active press <kbd>Alt</kbd>+<kbd>f</kbd>.
It will reload fzf window and only function tags will be listed.
2018-10-11 05:18:06 +00:00
#### Preview
When using X11 **fzf.kak** automatically tries to detect where to show preview window, depending
on aspect ratio of new termial window. By default if the height is bigger than the width, preview occupies
upper 60% of space. If height is smaller than the width, preview is shown at the right side.
2018-10-11 05:18:06 +00:00
You can configure the amount of space for preview window with these options: `fzf_preview_height` and `fzf_preview_width`.
When **fzf.kak** is used in tmux, it will show preview on the right side. Heigth of preview split can be adjusted with
`fzf_tmux_height_file_preview`
Amount of lines in preview window can be changed with `fzf_preview_lines` option.
2018-10-11 05:18:06 +00:00
You also can specify which highlighter to use within the preview window with `fzf_highlighter` option.
Supported tools are:
2018-10-31 18:38:30 +00:00
* [Bat](https://github.com/sharkdp/bat)
* [Coderay](https://github.com/rubychan/coderay)
* [Highlight](https://gitlab.com/saalen/highlight)
* [Rouge](https://github.com/jneen/rouge)
2018-10-11 05:18:06 +00:00
You can disable the preview window in fzf window by setting `fzf_preview` option to `false`:
```kak
set-option global fzf_preview false
```
2018-11-24 15:45:03 +00:00
## Contributing
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.
### Writing a module
You can write a module for **fzf.kak**. To create one, simply define a function in separate file, located
in `rc/fzf-modules/`, and named after the function. **fzf.kak** provides a general purpose command, that can be called with some
Kakoune command as first parameter, and command that provides list of items for fzf as a second parameter. Third optional parameter is
for defining extra arguments for fzf itself, like additional keybindings.
Overall module structure is:
* Define a `fzf-command` command
* Prepare list of items for fzf, or define an item command
* call `fzf` command and pass needed arguments to it.
Of course modules can and will be more complex, since a good module checks if command for providing item list is available on user's machine,
and supports various settings inside it. Feel free to look how existing modules are made.