mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-06 20:54:28 +08:00
Compare commits
240 Commits
revert-500
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
879db51d09 | ||
|
|
3725f364cc | ||
|
|
98dcd77a18 | ||
|
|
a2ed9fb885 | ||
|
|
3ed6ac56d0 | ||
|
|
3cb44a8ba5 | ||
|
|
1fff637559 | ||
|
|
245eaf8e50 | ||
|
|
f06bd1e69b | ||
|
|
6cda389bde | ||
|
|
b3a49d7993 | ||
|
|
80d1cc2e68 | ||
|
|
556f45e79a | ||
|
|
ec75ffbfd5 | ||
|
|
c5ce7908ee | ||
|
|
04bfa81157 | ||
|
|
6f28c8c7bb | ||
|
|
f7c7b44764 | ||
|
|
0337b09394 | ||
|
|
8f3846f968 | ||
|
|
3e2ed513d4 | ||
|
|
279e1ec068 | ||
|
|
0a80e43f90 | ||
|
|
47077d0b17 | ||
|
|
42507c3bea | ||
|
|
19de6507ff | ||
|
|
08dcd814a9 | ||
|
|
71b0e0fb94 | ||
|
|
3656cbb9ef | ||
|
|
61edb0ca42 | ||
|
|
a50c2640b9 | ||
|
|
d91dd754a9 | ||
|
|
99093bd103 | ||
|
|
269c08641e | ||
|
|
503bb6fe9c | ||
|
|
45d96c9cb1 | ||
|
|
e69f2dcdad | ||
|
|
0b3e015ad8 | ||
|
|
8ea9574b3e | ||
|
|
20a1c014b5 | ||
|
|
f6cb5b1789 | ||
|
|
1e054c1d07 | ||
|
|
d1016dbd7c | ||
|
|
f3b82091a6 | ||
|
|
678ee1a549 | ||
|
|
fe362d413a | ||
|
|
937f430ce3 | ||
|
|
587f55bf50 | ||
|
|
7ba5be32bc | ||
|
|
2c501dc5a2 | ||
|
|
19dec6c038 | ||
|
|
1be10b0e50 | ||
|
|
5c218e982d | ||
|
|
832a090870 | ||
|
|
5ab282c2f4 | ||
|
|
811f34b70b | ||
|
|
e0d131d953 | ||
|
|
1dcdb21db6 | ||
|
|
5d87ac1fe8 | ||
|
|
f5ba993af3 | ||
|
|
fd812b5710 | ||
|
|
87b60bb133 | ||
|
|
dc71692255 | ||
|
|
ca542801a1 | ||
|
|
bdf48c282a | ||
|
|
9c37e6801b | ||
|
|
0f03107bc9 | ||
|
|
fd7fab77b2 | ||
|
|
7434543270 | ||
|
|
531dd67350 | ||
|
|
9ceac71802 | ||
|
|
333635e25e | ||
|
|
ecbf9cd98e | ||
|
|
f64c5b726d | ||
|
|
c491d702b7 | ||
|
|
c6b59d8ad7 | ||
|
|
2f3e29fc37 | ||
|
|
dff3ad4b62 | ||
|
|
a4617a7291 | ||
|
|
6a34c9060a | ||
|
|
c311c0a95f | ||
|
|
d5f1f8641b | ||
|
|
b23e4bb8f8 | ||
|
|
1f7bfa4007 | ||
|
|
70541d2ee0 | ||
|
|
91332acb1c | ||
|
|
66cb8b8264 | ||
|
|
d6aa21476b | ||
|
|
0452b71830 | ||
|
|
a4ce66d725 | ||
|
|
e393108bfa | ||
|
|
bd703a7a7d | ||
|
|
980cd07439 | ||
|
|
a552e44810 | ||
|
|
b1afeca8cc | ||
|
|
e34f6c129d | ||
|
|
161da95640 | ||
|
|
d7211d0f61 | ||
|
|
a88311b222 | ||
|
|
75c7e87de1 | ||
|
|
ee91c93d4c | ||
|
|
caf7754b26 | ||
|
|
1ef72b14cc | ||
|
|
711fb41e39 | ||
|
|
02a192ea0b | ||
|
|
68ab645574 | ||
|
|
707f5b6269 | ||
|
|
36de5db9f0 | ||
|
|
1fcdee55cc | ||
|
|
d43df0ea2f | ||
|
|
811b8607c6 | ||
|
|
e9d62b4c87 | ||
|
|
dfc318b2be | ||
|
|
a1f33472f9 | ||
|
|
708c26aceb | ||
|
|
4c9af003e6 | ||
|
|
54b3817db2 | ||
|
|
65b6cdb0f2 | ||
|
|
97ec188e07 | ||
|
|
636a62f140 | ||
|
|
8fa9cf0524 | ||
|
|
cabfd44a8b | ||
|
|
cc13a4b728 | ||
|
|
53b3aea0da | ||
|
|
61c4b6d1ed | ||
|
|
bd3a021ec1 | ||
|
|
7d45724fdd | ||
|
|
fcb1e6ebec | ||
|
|
ddc377c0d3 | ||
|
|
8b3ab784ed | ||
|
|
44057cce0e | ||
|
|
0eb385065b | ||
|
|
01f7146cf6 | ||
|
|
0fe8e198a3 | ||
|
|
3348aef05d | ||
|
|
18205e071d | ||
|
|
4145f53f3d | ||
|
|
23dda8602f | ||
|
|
9cc54fb3d3 | ||
|
|
2115caeba1 | ||
|
|
7bc8eccf57 | ||
|
|
2bf85d25e2 | ||
|
|
8f1e73b598 | ||
|
|
16e3efbcb1 | ||
|
|
5aa5977d74 | ||
|
|
7a655179a4 | ||
|
|
996ec3b4b0 | ||
|
|
a74605b81d | ||
|
|
3925db8307 | ||
|
|
25bed070d8 | ||
|
|
2c07630341 | ||
|
|
5b6f282d97 | ||
|
|
4cf475b753 | ||
|
|
f86ef1bce6 | ||
|
|
f90b3197ad | ||
|
|
d4d36b412b | ||
|
|
7ccecee77d | ||
|
|
d16ddcf58d | ||
|
|
ef24327796 | ||
|
|
15ed47f561 | ||
|
|
ed9d66c2a6 | ||
|
|
e32a9c3767 | ||
|
|
48a2d80a24 | ||
|
|
467c327788 | ||
|
|
ee08c8f949 | ||
|
|
dc7796a6e2 | ||
|
|
dc4c4c2271 | ||
|
|
6eeeab64a8 | ||
|
|
360f7f36da | ||
|
|
8a6894d6a5 | ||
|
|
8b778dc642 | ||
|
|
fab0597a50 | ||
|
|
76669c3c1d | ||
|
|
f71f4808d9 | ||
|
|
206ec5efe9 | ||
|
|
65edb6ad99 | ||
|
|
6eda9fd38a | ||
|
|
fcdb7a0096 | ||
|
|
98cf39949b | ||
|
|
bce6588d24 | ||
|
|
359a80e3a3 | ||
|
|
91ed5f4b39 | ||
|
|
5c87ab86c0 | ||
|
|
ac4e7bfb36 | ||
|
|
b31512e2a2 | ||
|
|
9b50e2fd5f | ||
|
|
7bf940d261 | ||
|
|
f0acabf7e8 | ||
|
|
95f025ef2d | ||
|
|
ad1833ecbc | ||
|
|
741d7caabf | ||
|
|
0dbcfb28c4 | ||
|
|
b73d141b74 | ||
|
|
974d366b33 | ||
|
|
50707b089b | ||
|
|
c6275ee108 | ||
|
|
c3954d294a | ||
|
|
8fa84e0fdf | ||
|
|
aedd47be21 | ||
|
|
8224416813 | ||
|
|
a3459df758 | ||
|
|
2eb1bccea9 | ||
|
|
f52fcd3d6c | ||
|
|
e042ec03a2 | ||
|
|
633c980c05 | ||
|
|
bd80d334be | ||
|
|
f39c92b7ce | ||
|
|
2a58380051 | ||
|
|
6ce58caad3 | ||
|
|
8d56bdd6ad | ||
|
|
1d9e7d2a90 | ||
|
|
033033daa3 | ||
|
|
1b01a5069b | ||
|
|
6aa1db67a5 | ||
|
|
34881b707b | ||
|
|
ce82e10630 | ||
|
|
88595ebbaa | ||
|
|
dc5f9437fc | ||
|
|
3661409e95 | ||
|
|
bbda33b402 | ||
|
|
dcf49751e9 | ||
|
|
9f0bae1248 | ||
|
|
a362bc58f1 | ||
|
|
17d24ae31d | ||
|
|
c0a5fee707 | ||
|
|
2686522b2e | ||
|
|
7e92b73d03 | ||
|
|
3d33d4cd66 | ||
|
|
9036680e74 | ||
|
|
02654656af | ||
|
|
009c58b481 | ||
|
|
11b7fb91e1 | ||
|
|
76926aa247 | ||
|
|
d0042b9dee | ||
|
|
45d39f5711 | ||
|
|
6902f6bc1c | ||
|
|
ad113a64fc | ||
|
|
ba7a22888b | ||
|
|
be8aa32b1e | ||
|
|
18df14c2f6 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sh text eol=lf
|
||||
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
github: junegunn
|
||||
29
.github/ISSUE_TEMPLATE.md
vendored
29
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,29 +0,0 @@
|
||||
<!-- Check all that apply [x] -->
|
||||
- Category
|
||||
- [ ] Question
|
||||
- [ ] Bug
|
||||
- [ ] Suggestion
|
||||
- OS
|
||||
- [ ] Linux
|
||||
- [ ] macOS
|
||||
- [ ] Windows
|
||||
- [ ] Etc.
|
||||
- Vim
|
||||
- [ ] Vim
|
||||
- [ ] Neovim
|
||||
|
||||
<!--
|
||||
|
||||
Before submitting
|
||||
=================
|
||||
|
||||
- Make sure that you have the latest version of fzf and fzf.vim
|
||||
- Check if your problem is reproducible with a minimal configuration
|
||||
|
||||
Start Vim with a minimal configuration
|
||||
======================================
|
||||
|
||||
vim -Nu <(curl https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw)
|
||||
|
||||
-->
|
||||
|
||||
49
.github/ISSUE_TEMPLATE/issue.yml
vendored
Normal file
49
.github/ISSUE_TEMPLATE/issue.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
name: Issue Template
|
||||
description: Report a problem or bug related to fzf.vim to help us improve
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Check the version of fzf used by running
|
||||
|
||||
```vim
|
||||
:echo system(fzf#exec() .. ' --version')
|
||||
```
|
||||
|
||||
If you don't have the latest version, run the following code to download it
|
||||
|
||||
```vim
|
||||
:call fzf#install()
|
||||
```
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Checklist
|
||||
options:
|
||||
- label: I have fzf 0.54.0 or later
|
||||
required: true
|
||||
- label: I have searched through the existing issues
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: Output of `:echo system(fzf#exec() .. ' --version')`
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: OS
|
||||
options:
|
||||
- label: Linux
|
||||
- label: macOS
|
||||
- label: Windows
|
||||
- label: Etc.
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Problem / Steps to reproduce
|
||||
validations:
|
||||
required: true
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Junegunn Choi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
480
README.md
480
README.md
@@ -1,3 +1,17 @@
|
||||
<div align="center" markdown="1">
|
||||
<sup>Special thanks to:</sup>
|
||||
<br>
|
||||
<a href="https://tuple.app/fzf.vim">
|
||||
<img alt="Tuple's sponsorship image" src="https://raw.githubusercontent.com/junegunn/i/master/tuple.png" width="400">
|
||||
</a>
|
||||
|
||||
### [Tuple, the premier screen sharing app for developers](https://tuple.app/fzf.vim)
|
||||
[Available for MacOS & Windows](https://tuple.app/fzf.vim)<br>
|
||||
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
fzf :heart: vim
|
||||
===============
|
||||
|
||||
@@ -6,16 +20,12 @@ Things you can do with [fzf][fzf] and Vim.
|
||||
Rationale
|
||||
---------
|
||||
|
||||
[fzf][fzf] in itself is not a Vim plugin, and the official repository only
|
||||
provides the [basic wrapper function][run] for Vim and it's up to the users to
|
||||
[fzf][fzf] itself is not a Vim plugin, and the official repository only
|
||||
provides the [basic wrapper function][run] for Vim. It's up to the users to
|
||||
write their own Vim commands with it. However, I've learned that many users of
|
||||
fzf are not familiar with Vimscript and are looking for the "default"
|
||||
implementation of the features they can find in the alternative Vim plugins.
|
||||
|
||||
This repository is a bundle of fzf-based commands and mappings extracted from
|
||||
my [.vimrc][vimrc] to address such needs. They are *not* designed to be
|
||||
flexible or configurable, and there's no guarantee of backward-compatibility.
|
||||
|
||||
Why you should use fzf on Vim
|
||||
-----------------------------
|
||||
|
||||
@@ -27,69 +37,82 @@ is small, which is the case for many of the commands provided here.
|
||||
Nevertheless I wrote them anyway since it's really easy to implement custom
|
||||
selector with fzf.
|
||||
|
||||
fzf is an independent command-line program and thus requires an external
|
||||
terminal emulator when on GVim. You may or may not like the experience. Also
|
||||
note that Windows support is experimental at the moment.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Use [vim-plug](https://github.com/junegunn/vim-plug) or any Vim plugin
|
||||
manager of your choice.
|
||||
fzf.vim depends on the basic Vim plugin of [the main fzf
|
||||
repository][fzf-main], which means you need to **set up both "fzf" and
|
||||
"fzf.vim" on Vim**. To learn more about fzf/Vim integration, see
|
||||
[README-VIM][README-VIM].
|
||||
|
||||
If you already installed fzf using [Homebrew](https://brew.sh/), the following
|
||||
should suffice:
|
||||
[fzf-main]: https://github.com/junegunn/fzf
|
||||
[README-VIM]: https://github.com/junegunn/fzf/blob/master/README-VIM.md
|
||||
|
||||
### Using [vim-plug](https://github.com/junegunn/vim-plug)
|
||||
|
||||
```vim
|
||||
Plug '/usr/local/opt/fzf'
|
||||
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
|
||||
Plug 'junegunn/fzf.vim'
|
||||
```
|
||||
|
||||
But if you want to install fzf as well using vim-plug:
|
||||
`fzf#install()` makes sure that you have the latest binary, but it's optional,
|
||||
so you can omit it if you use a plugin manager that doesn't support hooks.
|
||||
|
||||
```vim
|
||||
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
|
||||
Plug 'junegunn/fzf.vim'
|
||||
### Dependencies
|
||||
|
||||
- [fzf][fzf-main] 0.54.0 or above
|
||||
- For syntax-highlighted preview, install [bat](https://github.com/sharkdp/bat)
|
||||
- If [delta](https://github.com/dandavison/delta) is available, `GF?`,
|
||||
`Commits` and `BCommits` will use it to format `git diff` output.
|
||||
- `Ag` requires [The Silver Searcher (ag)][ag]
|
||||
- `Rg` requires [ripgrep (rg)][rg]
|
||||
- `Tags` and `Helptags` require Perl
|
||||
- `Tags PREFIX` requires `readtags` command from [Universal Ctags](https://ctags.io/)
|
||||
|
||||
```sh
|
||||
# Installing dependencies using Homebrew
|
||||
brew install fzf bat ripgrep the_silver_searcher perl universal-ctags
|
||||
```
|
||||
|
||||
- `dir` and `do` options are not mandatory
|
||||
- Use `./install --bin` instead if you don't need fzf outside of Vim
|
||||
- Make sure to use Vim 7.4 or above
|
||||
|
||||
Commands
|
||||
--------
|
||||
|
||||
| Command | List |
|
||||
| --- | --- |
|
||||
| `Files [PATH]` | Files (similar to `:FZF`) |
|
||||
| `GFiles [OPTS]` | Git files (`git ls-files`) |
|
||||
| `GFiles?` | Git files (`git status`) |
|
||||
| `Buffers` | Open buffers |
|
||||
| `Colors` | Color schemes |
|
||||
| `Ag [PATTERN]` | [ag][ag] search result (`ALT-A` to select all, `ALT-D` to deselect all) |
|
||||
| `Lines [QUERY]` | Lines in loaded buffers |
|
||||
| `BLines [QUERY]` | Lines in the current buffer |
|
||||
| `Tags [QUERY]` | Tags in the project (`ctags -R`) |
|
||||
| `BTags [QUERY]` | Tags in the current buffer |
|
||||
| `Marks` | Marks |
|
||||
| `Windows` | Windows |
|
||||
| `Locate PATTERN` | `locate` command output |
|
||||
| `History` | `v:oldfiles` and open buffers |
|
||||
| `History:` | Command history |
|
||||
| `History/` | Search history |
|
||||
| `Snippets` | Snippets ([UltiSnips][us]) |
|
||||
| `Commits` | Git commits (requires [fugitive.vim][f]) |
|
||||
| `BCommits` | Git commits for the current buffer |
|
||||
| `Commands` | Commands |
|
||||
| `Maps` | Normal mode mappings |
|
||||
| `Helptags` | Help tags <sup id="a1">[1](#helptags)</sup> |
|
||||
| `Filetypes` | File types
|
||||
| Command | List |
|
||||
| --- | --- |
|
||||
| `:Files [PATH]` | Files (runs `$FZF_DEFAULT_COMMAND` if defined) |
|
||||
| `:GFiles [OPTS]` | Git files (`git ls-files`) |
|
||||
| `:GFiles?` | Git files (`git status`) |
|
||||
| `:Buffers` | Open buffers |
|
||||
| `:Colors` | Color schemes |
|
||||
| `:Ag [PATTERN]` | [ag][ag] search result (`ALT-A` to select all, `ALT-D` to deselect all) |
|
||||
| `:Rg [PATTERN]` | [rg][rg] search result (`ALT-A` to select all, `ALT-D` to deselect all) |
|
||||
| `:RG [PATTERN]` | [rg][rg] search result; relaunch ripgrep on every keystroke |
|
||||
| `:Lines [QUERY]` | Lines in loaded buffers |
|
||||
| `:BLines [QUERY]` | Lines in the current buffer |
|
||||
| `:Tags [PREFIX]` | Tags in the project (`ctags -R`) |
|
||||
| `:BTags [QUERY]` | Tags in the current buffer |
|
||||
| `:Changes` | Changelist across all open buffers |
|
||||
| `:Marks` | Marks |
|
||||
| `:BMarks` | Marks in the current buffer |
|
||||
| `:Jumps` | Jumps |
|
||||
| `:Windows` | Windows |
|
||||
| `:Locate PATTERN` | `locate` command output |
|
||||
| `:History` | `v:oldfiles` and open buffers |
|
||||
| `:History:` | Command history |
|
||||
| `:History/` | Search history |
|
||||
| `:Snippets` | Snippets ([UltiSnips][us]) |
|
||||
| `:Commits [LOG_OPTS]` | Git commits (requires [fugitive.vim][f]) |
|
||||
| `:BCommits [LOG_OPTS]` | Git commits for the current buffer; visual-select lines to track changes in the range |
|
||||
| `:Commands` | Commands |
|
||||
| `:Maps` | Normal mode mappings |
|
||||
| `:Helptags` | Help tags <sup id="a1">[1](#helptags)</sup> |
|
||||
| `:Filetypes` | File types
|
||||
|
||||
- Most commands support `CTRL-T` / `CTRL-X` / `CTRL-V` key
|
||||
bindings to open in a new tab, a new split, or in a new vertical split
|
||||
- Bang-versions of the commands (e.g. `Ag!`) will open fzf in fullscreen
|
||||
- You can set `g:fzf_command_prefix` to give the same prefix to the commands
|
||||
- e.g. `let g:fzf_command_prefix = 'Fzf'` and you have `FzfFiles`, etc.
|
||||
- You can set `g:fzf_vim.command_prefix` to give the same prefix to the commands
|
||||
- e.g. `let g:fzf_vim.command_prefix = 'Fzf'` and you have `FzfFiles`, etc.
|
||||
|
||||
(<a name="helptags">1</a>: `Helptags` will shadow the command of the same name
|
||||
from [pathogen][pat]. But its functionality is still available via `call
|
||||
@@ -98,110 +121,237 @@ pathogen#helptags()`. [↩](#a1))
|
||||
[pat]: https://github.com/tpope/vim-pathogen
|
||||
[f]: https://github.com/tpope/vim-fugitive
|
||||
|
||||
### Customization
|
||||
Customization
|
||||
-------------
|
||||
|
||||
#### Global options
|
||||
### Configuration options of the base plugin
|
||||
|
||||
See [README-VIM.md][readme-vim] of the main fzf repository for details.
|
||||
Every command in fzf.vim internally calls `fzf#wrap` function of the main
|
||||
repository which supports a set of global option variables. So please read
|
||||
through [README-VIM][README-VIM] to learn more about them.
|
||||
|
||||
[readme-vim]: https://github.com/junegunn/fzf/blob/master/README-VIM.md#configuration
|
||||
### Configuration options for fzf.vim
|
||||
|
||||
All configuration values for this plugin are stored in `g:fzf_vim` dictionary,
|
||||
so **make sure to initialize it before assigning any configuration values to
|
||||
it**.
|
||||
|
||||
```vim
|
||||
" This is the default extra key bindings
|
||||
let g:fzf_action = {
|
||||
\ 'ctrl-t': 'tab split',
|
||||
\ 'ctrl-x': 'split',
|
||||
\ 'ctrl-v': 'vsplit' }
|
||||
|
||||
" Default fzf layout
|
||||
" - down / up / left / right
|
||||
let g:fzf_layout = { 'down': '~40%' }
|
||||
|
||||
" In Neovim, you can set up fzf window using a Vim command
|
||||
let g:fzf_layout = { 'window': 'enew' }
|
||||
let g:fzf_layout = { 'window': '-tabnew' }
|
||||
let g:fzf_layout = { 'window': '10split enew' }
|
||||
|
||||
" Customize fzf colors to match your color scheme
|
||||
let g:fzf_colors =
|
||||
\ { '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'] }
|
||||
|
||||
" Enable per-command history.
|
||||
" CTRL-N and CTRL-P will be automatically bound to next-history and
|
||||
" previous-history instead of down and up. If you don't like the change,
|
||||
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
|
||||
let g:fzf_history_dir = '~/.local/share/fzf-history'
|
||||
" Initialize configuration dictionary
|
||||
let g:fzf_vim = {}
|
||||
```
|
||||
|
||||
#### Command-local options
|
||||
#### Preview window
|
||||
|
||||
Some commands will show the preview window on the right. You can customize the
|
||||
behavior with `g:fzf_vim.preview_window`. Here are some examples:
|
||||
|
||||
```vim
|
||||
" [Buffers] Jump to the existing window if possible
|
||||
let g:fzf_buffers_jump = 1
|
||||
" This is the default option:
|
||||
" - Preview window on the right with 50% width
|
||||
" - CTRL-/ will toggle preview window.
|
||||
" - Note that this array is passed as arguments to fzf#vim#with_preview function.
|
||||
" - To learn more about preview window options, see `--preview-window` section of `man fzf`.
|
||||
let g:fzf_vim.preview_window = ['right,50%', 'ctrl-/']
|
||||
|
||||
" Preview window is hidden by default. You can toggle it with ctrl-/.
|
||||
" It will show on the right with 50% width, but if the width is smaller
|
||||
" than 70 columns, it will show above the candidate list
|
||||
let g:fzf_vim.preview_window = ['hidden,right,50%,<70(up,40%)', 'ctrl-/']
|
||||
|
||||
" Empty value to disable preview window altogether
|
||||
let g:fzf_vim.preview_window = []
|
||||
|
||||
" fzf.vim needs bash to display the preview window.
|
||||
" On Windows, fzf.vim will first see if bash is in $PATH, then if
|
||||
" Git bash (C:\Program Files\Git\bin\bash.exe) is available.
|
||||
" If you want it to use a different bash, set this variable.
|
||||
" let g:fzf_vim = {}
|
||||
" let g:fzf_vim.preview_bash = 'C:\Git\bin\bash.exe'
|
||||
```
|
||||
|
||||
#### Command-level options
|
||||
|
||||
```vim
|
||||
" [Buffers] Jump to the existing window if possible (default: 0)
|
||||
let g:fzf_vim.buffers_jump = 1
|
||||
|
||||
" [Ag|Rg|RG] Display path on a separate line for narrow screens (default: 0)
|
||||
" * Requires Perl and fzf 0.56.0 or later
|
||||
let g:fzf_vim.grep_multi_line = 0
|
||||
" PATH:LINE:COL:LINE
|
||||
let g:fzf_vim.grep_multi_line = 1
|
||||
" PATH:LINE:COL:
|
||||
" LINE
|
||||
let g:fzf_vim.grep_multi_line = 2
|
||||
" PATH:LINE:COL:
|
||||
" LINE
|
||||
" (empty line between items using --gap option)
|
||||
|
||||
" [[B]Commits] Customize the options used by 'git log':
|
||||
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
|
||||
let g:fzf_vim.commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
|
||||
|
||||
" [Tags] Command to generate tags file
|
||||
let g:fzf_tags_command = 'ctags -R'
|
||||
let g:fzf_vim.tags_command = 'ctags -R'
|
||||
|
||||
" [Commands] --expect expression for directly executing the command
|
||||
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
|
||||
let g:fzf_vim.commands_expect = 'alt-enter,ctrl-x'
|
||||
```
|
||||
|
||||
#### Advanced customization
|
||||
#### Command-level fzf options
|
||||
|
||||
You can use autoload functions to define your own commands.
|
||||
You can set fzf options for each command by setting
|
||||
`g:fzf_vim.{command}_options`.
|
||||
|
||||
```vim
|
||||
" Command for git grep
|
||||
" - fzf#vim#grep(command, with_column, [options], [fullscreen])
|
||||
command! -bang -nargs=* GGrep
|
||||
\ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0)
|
||||
" In string
|
||||
let g:fzf_vim.buffers_options = '--style full --border-label " Open Buffers "'
|
||||
|
||||
" Override Colors command. You can safely do this in your .vimrc as fzf.vim
|
||||
" will not override existing commands.
|
||||
command! -bang Colors
|
||||
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}, <bang>0)
|
||||
" In list (No need to quote or escape values)
|
||||
let g:fzf_vim.buffers_options = ['--style', 'full', '--border-label', ' Open Buffers ']
|
||||
```
|
||||
|
||||
" Augmenting Ag command using fzf#vim#with_preview function
|
||||
" * fzf#vim#with_preview([[options], preview window, [toggle keys...]])
|
||||
" * For syntax-highlighting, Ruby and any of the following tools are required:
|
||||
" - Highlight: http://www.andre-simon.de/doku/highlight/en/highlight.php
|
||||
" - CodeRay: http://coderay.rubychan.de/
|
||||
" - Rouge: https://github.com/jneen/rouge
|
||||
"
|
||||
" :Ag - Start fzf with hidden preview window that can be enabled with "?" key
|
||||
" :Ag! - Start fzf in fullscreen and display the preview window above
|
||||
command! -bang -nargs=* Ag
|
||||
\ call fzf#vim#ag(<q-args>,
|
||||
\ <bang>0 ? fzf#vim#with_preview('up:60%')
|
||||
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
|
||||
\ <bang>0)
|
||||
#### List type to handle multiple selections
|
||||
|
||||
" Similarly, we can apply it to fzf#vim#grep. To use ripgrep instead of ag:
|
||||
command! -bang -nargs=* Rg
|
||||
\ call fzf#vim#grep(
|
||||
\ 'rg --column --line-number --no-heading --color=always '.shellescape(<q-args>), 1,
|
||||
\ <bang>0 ? fzf#vim#with_preview('up:60%')
|
||||
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
|
||||
\ <bang>0)
|
||||
The following commands will fill the quickfix list when multiple entries are
|
||||
selected.
|
||||
|
||||
" Likewise, Files command with preview window
|
||||
* `Ag`
|
||||
* `Rg` / `RG`
|
||||
* `Lines` / `BLines`
|
||||
* `Tags` / `BTags`
|
||||
|
||||
By setting `g:fzf_vim.listproc`, you can make them use location list instead.
|
||||
|
||||
```vim
|
||||
" Default: Use quickfix list
|
||||
let g:fzf_vim.listproc = { list -> fzf#vim#listproc#quickfix(list) }
|
||||
|
||||
" Use location list instead of quickfix list
|
||||
let g:fzf_vim.listproc = { list -> fzf#vim#listproc#location(list) }
|
||||
```
|
||||
|
||||
You can customize the list type per command by defining variables named
|
||||
`g:fzf_vim.listproc_{command_name_in_lowercase}`.
|
||||
|
||||
```vim
|
||||
" Command-wise customization
|
||||
let g:fzf_vim.listproc_ag = { list -> fzf#vim#listproc#quickfix(list) }
|
||||
let g:fzf_vim.listproc_rg = { list -> fzf#vim#listproc#location(list) }
|
||||
```
|
||||
|
||||
You can further customize the behavior by providing a custom function to
|
||||
process the list instead of using the predefined `fzf#vim#listproc#quickfix`
|
||||
or `fzf#vim#listproc#location`.
|
||||
|
||||
```vim
|
||||
" A customized version of fzf#vim#listproc#quickfix.
|
||||
" The last two lines are commented out not to move to the first entry.
|
||||
function! g:fzf_vim.listproc(list)
|
||||
call setqflist(a:list)
|
||||
copen
|
||||
wincmd p
|
||||
" cfirst
|
||||
" normal! zvzz
|
||||
endfunction
|
||||
```
|
||||
|
||||
### Advanced customization
|
||||
|
||||
#### Vim functions
|
||||
|
||||
Each command in fzf.vim is backed by a Vim function. You can override
|
||||
a command or define a variation of it by calling its corresponding function.
|
||||
|
||||
| Command | Vim function |
|
||||
| --- | --- |
|
||||
| `Files` | `fzf#vim#files(dir, [spec dict], [fullscreen bool])` |
|
||||
| `GFiles` | `fzf#vim#gitfiles(git_options, [spec dict], [fullscreen bool])` |
|
||||
| `GFiles?` | `fzf#vim#gitfiles('?', [spec dict], [fullscreen bool])` |
|
||||
| `Buffers` | `fzf#vim#buffers([query string], [bufnrs list], [spec dict], [fullscreen bool])` |
|
||||
| `Colors` | `fzf#vim#colors([spec dict], [fullscreen bool])` |
|
||||
| `Rg` | `fzf#vim#grep(command, [spec dict], [fullscreen bool])` |
|
||||
| `RG` | `fzf#vim#grep2(command_prefix, query, [spec dict], [fullscreen bool])` |
|
||||
| ... | ... |
|
||||
|
||||
(We can see that the last two optional arguments of each function are
|
||||
identical. They are directly passed to `fzf#wrap` function. If you haven't
|
||||
read [README-VIM][README-VIM] already, please read it before proceeding.)
|
||||
|
||||
#### Example: Customizing `Files` command
|
||||
|
||||
This is the default definition of `Files` command:
|
||||
|
||||
```vim
|
||||
command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, <bang>0)
|
||||
```
|
||||
|
||||
Let's say you want to a variation of it called `ProjectFiles` that only
|
||||
searches inside `~/projects` directory. Then you can do it like this:
|
||||
|
||||
```vim
|
||||
command! -bang ProjectFiles call fzf#vim#files('~/projects', <bang>0)
|
||||
```
|
||||
|
||||
Or, if you want to override the command with different fzf options, just pass
|
||||
a custom spec to the function.
|
||||
|
||||
```vim
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
|
||||
\ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline']}, <bang>0)
|
||||
```
|
||||
|
||||
Want a preview window?
|
||||
|
||||
```vim
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline', '--preview', 'cat {}']}, <bang>0)
|
||||
```
|
||||
|
||||
It kind of works, but you probably want a nicer previewer program than `cat`.
|
||||
fzf.vim ships [a versatile preview script](bin/preview.sh) you can readily
|
||||
use. It internally executes [bat](https://github.com/sharkdp/bat) for syntax
|
||||
highlighting, so make sure to install it.
|
||||
|
||||
```vim
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline', '--preview', '~/.vim/plugged/fzf.vim/bin/preview.sh {}']}, <bang>0)
|
||||
```
|
||||
|
||||
However, it's not ideal to hard-code the path to the script which can be
|
||||
different in different circumstances. So in order to make it easier to set up
|
||||
the previewer, fzf.vim provides `fzf#vim#with_preview` helper function.
|
||||
Similarly to `fzf#wrap`, it takes a spec dictionary and returns a copy of it
|
||||
with additional preview options.
|
||||
|
||||
```vim
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview({'options': ['--layout=reverse', '--info=inline']}), <bang>0)
|
||||
```
|
||||
|
||||
You can just omit the spec argument if you only want the previewer.
|
||||
|
||||
```vim
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
|
||||
```
|
||||
|
||||
#### Example: `git grep` wrapper
|
||||
|
||||
The following example implements `GGrep` command that works similarly to
|
||||
predefined `Ag` or `Rg` using `fzf#vim#grep`.
|
||||
|
||||
- We set the base directory to git root by setting `dir` attribute in spec
|
||||
dictionary.
|
||||
- [The preview script](bin/preview.sh) supports `grep` format
|
||||
(`FILE_PATH:LINE_NO:...`), so we can just wrap the spec with
|
||||
`fzf#vim#with_preview` as before to enable previewer.
|
||||
|
||||
```vim
|
||||
command! -bang -nargs=* GGrep
|
||||
\ call fzf#vim#grep(
|
||||
\ 'git grep --line-number -- '.fzf#shellescape(<q-args>),
|
||||
\ fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), <bang>0)
|
||||
```
|
||||
|
||||
Mappings
|
||||
@@ -216,12 +366,9 @@ Mappings
|
||||
| `<plug>(fzf-complete-word)` | `cat /usr/share/dict/words` |
|
||||
| `<plug>(fzf-complete-path)` | Path completion using `find` (file + dir) |
|
||||
| `<plug>(fzf-complete-file)` | File completion using `find` |
|
||||
| `<plug>(fzf-complete-file-ag)` | File completion using `ag` |
|
||||
| `<plug>(fzf-complete-line)` | Line completion (all open buffers) |
|
||||
| `<plug>(fzf-complete-buffer-line)` | Line completion (current buffer only) |
|
||||
|
||||
### Usage
|
||||
|
||||
```vim
|
||||
" Mapping selecting mappings
|
||||
nmap <leader><tab> <plug>(fzf-maps-n)
|
||||
@@ -231,22 +378,38 @@ omap <leader><tab> <plug>(fzf-maps-o)
|
||||
" Insert mode completion
|
||||
imap <c-x><c-k> <plug>(fzf-complete-word)
|
||||
imap <c-x><c-f> <plug>(fzf-complete-path)
|
||||
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
|
||||
imap <c-x><c-l> <plug>(fzf-complete-line)
|
||||
|
||||
" Advanced customization using autoload functions
|
||||
inoremap <expr> <c-x><c-k> fzf#vim#complete#word({'left': '15%'})
|
||||
```
|
||||
|
||||
### Completion helper
|
||||
Completion functions
|
||||
--------------------
|
||||
|
||||
`fzf#complete` is a helper function for creating custom fuzzy completion using
|
||||
fzf. If the first parameter is a command string or a Vim list, it will be used
|
||||
as the source.
|
||||
| Function | Description |
|
||||
| --- | --- |
|
||||
| `fzf#vim#complete#path(command, [spec])` | Path completion |
|
||||
| `fzf#vim#complete#word([spec])` | Word completion |
|
||||
| `fzf#vim#complete#line([spec])` | Line completion (all open buffers) |
|
||||
| `fzf#vim#complete#buffer_line([spec])` | Line completion (current buffer only) |
|
||||
|
||||
```vim
|
||||
" Path completion with custom source command
|
||||
inoremap <expr> <c-x><c-f> fzf#vim#complete#path('fd')
|
||||
inoremap <expr> <c-x><c-f> fzf#vim#complete#path('rg --files')
|
||||
|
||||
" Word completion with custom spec with popup layout option
|
||||
inoremap <expr> <c-x><c-k> fzf#vim#complete#word({'window': { 'width': 0.2, 'height': 0.9, 'xoffset': 1 }})
|
||||
```
|
||||
|
||||
Custom completion
|
||||
-----------------
|
||||
|
||||
`fzf#vim#complete` is a helper function for creating custom fuzzy completion
|
||||
using fzf. If the first parameter is a command string or a Vim list, it will
|
||||
be used as the source.
|
||||
|
||||
```vim
|
||||
" Replace the default dictionary completion with fzf-based fuzzy completion
|
||||
inoremap <expr> <c-x><c-k> fzf#complete('cat /usr/share/dict/words')
|
||||
inoremap <expr> <c-x><c-k> fzf#vim#complete('cat /usr/share/dict/words')
|
||||
```
|
||||
|
||||
For advanced uses, you can pass an options dictionary to the function. The set
|
||||
@@ -262,22 +425,45 @@ following exceptions:
|
||||
completion prefix as the argument and return the final value
|
||||
- `sink` or `sink*` are ignored
|
||||
|
||||
#### Reducer example
|
||||
```vim
|
||||
" Global line completion (not just open buffers. ripgrep required.)
|
||||
inoremap <expr> <c-x><c-l> fzf#vim#complete(fzf#wrap({
|
||||
\ 'prefix': '^.*$',
|
||||
\ 'source': 'rg -n ^ --color always',
|
||||
\ 'options': '--ansi --delimiter : --nth 3..',
|
||||
\ 'reducer': { lines -> join(split(lines[0], ':\zs')[2:], '') }}))
|
||||
```
|
||||
|
||||
### Reducer example
|
||||
|
||||
```vim
|
||||
function! s:make_sentence(lines)
|
||||
return substitute(join(a:lines), '^.', '\=toupper(submatch(0))', '').'.'
|
||||
endfunction
|
||||
|
||||
inoremap <expr> <c-x><c-s> fzf#complete({
|
||||
inoremap <expr> <c-x><c-s> fzf#vim#complete({
|
||||
\ 'source': 'cat /usr/share/dict/words',
|
||||
\ 'reducer': function('<sid>make_sentence'),
|
||||
\ 'options': '--multi --reverse --margin 15%,0',
|
||||
\ 'left': 20})
|
||||
```
|
||||
|
||||
Status line (neovim)
|
||||
--------------------
|
||||
Status line of terminal buffer
|
||||
------------------------------
|
||||
|
||||
When fzf starts in a terminal buffer (see [fzf/README-VIM.md][termbuf]), you
|
||||
may want to customize the statusline of the containing buffer.
|
||||
|
||||
[termbuf]: https://github.com/junegunn/fzf/blob/master/README-VIM.md#fzf-inside-terminal-buffer
|
||||
|
||||
### Hide statusline
|
||||
|
||||
```vim
|
||||
autocmd! FileType fzf set laststatus=0 noshowmode noruler
|
||||
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
|
||||
```
|
||||
|
||||
### Custom statusline
|
||||
|
||||
```vim
|
||||
function! s:fzf_statusline()
|
||||
@@ -297,7 +483,7 @@ License
|
||||
MIT
|
||||
|
||||
[fzf]: https://github.com/junegunn/fzf
|
||||
[run]: https://github.com/junegunn/fzf#usage-as-vim-plugin
|
||||
[vimrc]: https://github.com/junegunn/dotfiles/blob/master/vimrc
|
||||
[run]: https://github.com/junegunn/fzf/blob/master/README-VIM.md#fzfrun
|
||||
[ag]: https://github.com/ggreer/the_silver_searcher
|
||||
[rg]: https://github.com/BurntSushi/ripgrep
|
||||
[us]: https://github.com/SirVer/ultisnips
|
||||
|
||||
983
autoload/fzf/vim.vim
Normal file → Executable file
983
autoload/fzf/vim.vim
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
@@ -47,8 +47,9 @@ else
|
||||
endif
|
||||
|
||||
function! fzf#vim#complete#word(...)
|
||||
let sources = empty(&dictionary) ? ['/usr/share/dict/words'] : split(&dictionary, ',')
|
||||
return fzf#vim#complete(s:extend({
|
||||
\ 'source': 'cat /usr/share/dict/words'},
|
||||
\ 'source': 'cat ' . join(map(sources, 'fzf#shellescape(v:val)'))},
|
||||
\ get(a:000, 0, fzf#wrap())))
|
||||
endfunction
|
||||
|
||||
|
||||
95
autoload/fzf/vim/ipc.vim
Normal file
95
autoload/fzf/vim/ipc.vim
Normal file
@@ -0,0 +1,95 @@
|
||||
" Copyright (c) 2024 Junegunn Choi
|
||||
"
|
||||
" MIT License
|
||||
"
|
||||
" Permission is hereby granted, free of charge, to any person obtaining
|
||||
" a copy of this software and associated documentation files (the
|
||||
" "Software"), to deal in the Software without restriction, including
|
||||
" without limitation the rights to use, copy, modify, merge, publish,
|
||||
" distribute, sublicense, and/or sell copies of the Software, and to
|
||||
" permit persons to whom the Software is furnished to do so, subject to
|
||||
" the following conditions:
|
||||
"
|
||||
" The above copyright notice and this permission notice shall be
|
||||
" included in all copies or substantial portions of the Software.
|
||||
"
|
||||
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
" LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
function! s:warn(message)
|
||||
echohl WarningMsg
|
||||
echom a:message
|
||||
echohl None
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#ipc#start(Callback)
|
||||
if !exists('*job_start') && !exists('*jobstart')
|
||||
call s:warn('job_start/jobstart function not supported')
|
||||
return ''
|
||||
endif
|
||||
|
||||
if !executable('mkfifo')
|
||||
call s:warn('mkfifo is not available')
|
||||
return ''
|
||||
endif
|
||||
|
||||
call fzf#vim#ipc#stop()
|
||||
|
||||
let g:fzf_ipc = { 'fifo': tempname(), 'callback': a:Callback }
|
||||
if !filereadable(g:fzf_ipc.fifo)
|
||||
call system('mkfifo '..shellescape(g:fzf_ipc.fifo))
|
||||
if v:shell_error
|
||||
call s:warn('Failed to create fifo')
|
||||
endif
|
||||
endif
|
||||
|
||||
call fzf#vim#ipc#restart()
|
||||
|
||||
return g:fzf_ipc.fifo
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#ipc#restart()
|
||||
if !exists('g:fzf_ipc')
|
||||
throw 'fzf#vim#ipc not started'
|
||||
endif
|
||||
|
||||
let Callback = g:fzf_ipc.callback
|
||||
if exists('*job_start')
|
||||
let g:fzf_ipc.job = job_start(
|
||||
\ ['cat', g:fzf_ipc.fifo],
|
||||
\ {'out_cb': { _, msg -> call(Callback, [msg]) },
|
||||
\ 'exit_cb': { _, status -> status == 0 ? fzf#vim#ipc#restart() : '' }}
|
||||
\ )
|
||||
else
|
||||
let eof = ['']
|
||||
let g:fzf_ipc.job = jobstart(
|
||||
\ ['cat', g:fzf_ipc.fifo],
|
||||
\ {'stdout_buffered': 1,
|
||||
\ 'on_stdout': { j, msg, e -> msg != eof ? call(Callback, msg) : '' },
|
||||
\ 'on_exit': { j, status, e -> status == 0 ? fzf#vim#ipc#restart() : '' }}
|
||||
\ )
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#ipc#stop()
|
||||
if !exists('g:fzf_ipc')
|
||||
return
|
||||
endif
|
||||
|
||||
let job = g:fzf_ipc.job
|
||||
if exists('*job_stop')
|
||||
call job_stop(job)
|
||||
else
|
||||
call jobstop(job)
|
||||
call jobwait([job])
|
||||
endif
|
||||
|
||||
call delete(g:fzf_ipc.fifo)
|
||||
unlet g:fzf_ipc
|
||||
endfunction
|
||||
38
autoload/fzf/vim/listproc.vim
Normal file
38
autoload/fzf/vim/listproc.vim
Normal file
@@ -0,0 +1,38 @@
|
||||
" Copyright (c) 2023 Junegunn Choi
|
||||
"
|
||||
" MIT License
|
||||
"
|
||||
" Permission is hereby granted, free of charge, to any person obtaining
|
||||
" a copy of this software and associated documentation files (the
|
||||
" "Software"), to deal in the Software without restriction, including
|
||||
" without limitation the rights to use, copy, modify, merge, publish,
|
||||
" distribute, sublicense, and/or sell copies of the Software, and to
|
||||
" permit persons to whom the Software is furnished to do so, subject to
|
||||
" the following conditions:
|
||||
"
|
||||
" The above copyright notice and this permission notice shall be
|
||||
" included in all copies or substantial portions of the Software.
|
||||
"
|
||||
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
" LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
function! fzf#vim#listproc#quickfix(list)
|
||||
call setqflist(a:list)
|
||||
copen
|
||||
wincmd p
|
||||
cfirst
|
||||
normal! zvzz
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#listproc#location(list)
|
||||
call setloclist(0, a:list)
|
||||
lopen
|
||||
wincmd p
|
||||
lfirst
|
||||
normal! zvzz
|
||||
endfunction
|
||||
@@ -1,57 +1,3 @@
|
||||
#!/usr/bin/env ruby
|
||||
#
|
||||
# usage: ./preview.rb [-v] FILENAME[:LINE][:IGNORED]
|
||||
|
||||
require 'shellwords'
|
||||
|
||||
COMMAND = %[(highlight -O ansi -l {} || coderay {} || rougify {} || cat {}) 2> /dev/null]
|
||||
ANSI = /\x1b\[[0-9;]*m/
|
||||
REVERSE = "\x1b[7m"
|
||||
RESET = "\x1b[m"
|
||||
|
||||
split = ARGV.delete('-v')
|
||||
|
||||
def usage
|
||||
puts "usage: #$0 [-v] FILENAME[:LINENO][:IGNORED]"
|
||||
exit 1
|
||||
end
|
||||
|
||||
usage if ARGV.empty?
|
||||
|
||||
file, center, extra = ARGV.first.split(':')
|
||||
if ARGV.first =~ /^[A-Z]:\\/
|
||||
file << ':' + center
|
||||
center = extra
|
||||
end
|
||||
usage unless file
|
||||
|
||||
path = File.expand_path(file)
|
||||
unless File.readable? path
|
||||
puts "File not found: #{file}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
if `file --mime "#{file}"` =~ /binary/
|
||||
puts "#{file} is a binary file"
|
||||
exit 0
|
||||
end
|
||||
|
||||
center = (center || 0).to_i
|
||||
if ENV['FZF_PREVIEW_HEIGHT']
|
||||
height = ENV['FZF_PREVIEW_HEIGHT'].to_i
|
||||
else
|
||||
height = File.readable?('/dev/tty') ? `stty size < /dev/tty`.split.first.to_i : 40
|
||||
height /= 2 if split
|
||||
height -= 2 # preview border
|
||||
end
|
||||
offset = [1, center - height / 3].max
|
||||
|
||||
IO.popen(['sh', '-c', COMMAND.gsub('{}', Shellwords.shellescape(path))]) do |io|
|
||||
io.each_line.drop(offset - 1).take(height).each_with_index do |line, lno|
|
||||
if lno + offset == center
|
||||
puts REVERSE + line.chomp.gsub(ANSI) { |m| m + REVERSE } + RESET
|
||||
else
|
||||
puts line
|
||||
end
|
||||
end
|
||||
end
|
||||
puts 'preview.rb is deprecated. Use preview.sh instead.'
|
||||
|
||||
102
bin/preview.sh
102
bin/preview.sh
@@ -1,57 +1,93 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
REVERSE="\x1b[7m"
|
||||
RESET="\x1b[m"
|
||||
|
||||
if [ "$1" == "-v" ]; then
|
||||
SPLIT=1
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "usage: $0 [-v] FILENAME[:LINENO][:IGNORED]"
|
||||
if [[ $# -lt 1 ]]; then
|
||||
echo "usage: $0 [--tag] FILENAME[:LINENO][:IGNORED]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $1 = --tag ]]; then
|
||||
shift
|
||||
"$(dirname "${BASH_SOURCE[0]}")/tagpreview.sh" "$@"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# Ignore if an empty path is given
|
||||
[[ -z $1 ]] && exit
|
||||
|
||||
IFS=':' read -r -a INPUT <<< "$1"
|
||||
FILE=${INPUT[0]}
|
||||
CENTER=${INPUT[1]}
|
||||
|
||||
if [[ $1 =~ ^[A-Z]:\\ ]]; then
|
||||
if [[ "$1" =~ ^[A-Za-z]:\\ ]]; then
|
||||
FILE=$FILE:${INPUT[1]}
|
||||
CENTER=${INPUT[2]}
|
||||
fi
|
||||
|
||||
if [[ -n "$CENTER" && ! "$CENTER" =~ ^[0-9] ]]; then
|
||||
exit 1
|
||||
fi
|
||||
CENTER=${CENTER/[^0-9]*/}
|
||||
|
||||
# MS Win support
|
||||
if [[ "$FILE" =~ '\' ]]; then
|
||||
if [ -z "$MSWINHOME" ]; then
|
||||
MSWINHOME="$HOMEDRIVE$HOMEPATH"
|
||||
fi
|
||||
if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
|
||||
MSWINHOME="${MSWINHOME//\\/\\\\}"
|
||||
FILE="${FILE/#\~\\/$MSWINHOME\\}"
|
||||
FILE=$(wslpath -u "$FILE")
|
||||
elif [ -n "$MSWINHOME" ]; then
|
||||
FILE="${FILE/#\~\\/$MSWINHOME\\}"
|
||||
fi
|
||||
fi
|
||||
|
||||
FILE="${FILE/#\~\//$HOME/}"
|
||||
if [ ! -r "$FILE" ]; then
|
||||
echo "File not found ${FILE}"
|
||||
if [[ "${INPUT[0]}" != '[No Name]' ]]; then
|
||||
echo "File not found ${FILE}"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$(file --mime "$FILE")" =~ binary ]]; then
|
||||
echo "$1 is a binary file"
|
||||
if [ -z "$CENTER" ]; then
|
||||
CENTER=0
|
||||
fi
|
||||
|
||||
# Sometimes bat is installed as batcat.
|
||||
if [[ -z "$BATCAT" ]]; then
|
||||
if command -v batcat > /dev/null; then
|
||||
BATCAT="batcat"
|
||||
elif command -v bat > /dev/null; then
|
||||
BATCAT="bat"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$FZF_PREVIEW_COMMAND" ] && [ "${BATCAT:+x}" ] && [[ ! -d "$FILE" ]] ; then
|
||||
${BATCAT} --style="${BAT_STYLE:-numbers}" --color=always --pager=never \
|
||||
--highlight-line=$CENTER -- "$FILE"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
FILE_LENGTH=${#FILE}
|
||||
MIME=$(file --dereference --mime -- "$FILE")
|
||||
if [[ "${MIME:FILE_LENGTH}" =~ binary ]] && [[ ! -d "$FILE" ]]; then
|
||||
echo "$MIME"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -z "$CENTER" ]; then
|
||||
CENTER=1
|
||||
DEFAULT_COMMAND="highlight -O ansi -l {} || coderay {} || rougify {} || cat {}"
|
||||
if [[ -d "$FILE" ]]; then
|
||||
DEFAULT_COMMAND="tree -C -L2 {} || ls -l --color=always {}"
|
||||
fi
|
||||
CMD=${FZF_PREVIEW_COMMAND:-$DEFAULT_COMMAND}
|
||||
CMD=${CMD//{\}/"$(printf %q "$FILE")"}
|
||||
|
||||
if [ -n "$FZF_PREVIEW_HEIGHT" ]; then
|
||||
LINES=$FZF_PREVIEW_HEIGHT
|
||||
else
|
||||
if [ -r /dev/tty ]; then
|
||||
LINES=$(stty size < /dev/tty | awk '{print $1}')
|
||||
else
|
||||
LINES=40
|
||||
fi
|
||||
if [ -n "$SPLIT" ]; then
|
||||
LINES=$(($LINES/2)) # using horizontal split
|
||||
fi
|
||||
LINES=$(($LINES-2)) # remove preview border
|
||||
fi
|
||||
|
||||
FIRST=$(($CENTER-$LINES/3))
|
||||
FIRST=$(($FIRST < 1 ? 1 : $FIRST))
|
||||
LAST=$((${FIRST}+${LINES}-1))
|
||||
|
||||
awk "NR >= $FIRST && NR <= $LAST {if (NR == $CENTER) printf(\"$REVERSE%5d %s\n$RESET\", NR, \$0); else printf(\"%5d %s\n\", NR, \$0)}" $FILE
|
||||
eval "$CMD" 2> /dev/null | awk "{ \
|
||||
if (NR == $CENTER) \
|
||||
{ gsub(/\x1b[[0-9;]*m/, \"&$REVERSE\"); printf(\"$REVERSE%s\n$RESET\", \$0); } \
|
||||
else printf(\"$RESET%s\n\", \$0); \
|
||||
}"
|
||||
|
||||
73
bin/tagpreview.sh
Executable file
73
bin/tagpreview.sh
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
REVERSE="\x1b[7m"
|
||||
RESET="\x1b[m"
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "usage: $0 FILENAME:TAGFILE:EXCMD"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
IFS=':' read -r FILE TAGFILE EXCMD <<< "$*"
|
||||
|
||||
# Complete file paths which are relative to the given tag file
|
||||
if [ "${FILE:0:1}" != "/" ]; then
|
||||
FILE="$(dirname "${TAGFILE}")/${FILE}"
|
||||
fi
|
||||
|
||||
if [ ! -r "$FILE" ]; then
|
||||
echo "File not found ${FILE}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If users aren't using vim, they are probably using neovim
|
||||
if command -v vim > /dev/null; then
|
||||
VIMNAME="vim"
|
||||
elif command -v nvim > /dev/null; then
|
||||
VIMNAME="nvim"
|
||||
else
|
||||
echo "Cannot preview tag: vim or nvim unavailable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CENTER="$("${VIMNAME}" -R -i NONE -u NONE -e -m -s "${FILE}" \
|
||||
-c "set nomagic" \
|
||||
-c "silent ${EXCMD}" \
|
||||
-c 'let l=line(".") | new | put =l | print | qa!')" || exit
|
||||
|
||||
START_LINE="$(( CENTER - FZF_PREVIEW_LINES / 2 ))"
|
||||
if (( START_LINE <= 0 )); then
|
||||
START_LINE=1
|
||||
fi
|
||||
END_LINE="$(( START_LINE + FZF_PREVIEW_LINES - 1 ))"
|
||||
|
||||
# Sometimes bat is installed as batcat.
|
||||
if command -v batcat > /dev/null; then
|
||||
BATNAME="batcat"
|
||||
elif command -v bat > /dev/null; then
|
||||
BATNAME="bat"
|
||||
fi
|
||||
|
||||
if [ -z "$FZF_PREVIEW_COMMAND" ] && [ "${BATNAME:+x}" ]; then
|
||||
${BATNAME} --style="${BAT_STYLE:-numbers}" \
|
||||
--color=always \
|
||||
--pager=never \
|
||||
--wrap=never \
|
||||
--terminal-width="${FZF_PREVIEW_COLUMNS}" \
|
||||
--line-range="${START_LINE}:${END_LINE}" \
|
||||
--highlight-line="${CENTER}" \
|
||||
"$FILE"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
DEFAULT_COMMAND="highlight -O ansi -l {} || coderay {} || rougify {} || cat {}"
|
||||
CMD=${FZF_PREVIEW_COMMAND:-$DEFAULT_COMMAND}
|
||||
CMD=${CMD//{\}/$(printf %q "$FILE")}
|
||||
|
||||
eval "$CMD" 2> /dev/null | awk "{ \
|
||||
if (NR >= $START_LINE && NR <= $END_LINE) { \
|
||||
if (NR == $CENTER) \
|
||||
{ gsub(/\x1b[[0-9;]*m/, \"&$REVERSE\"); printf(\"$REVERSE%s\n$RESET\", \$0); } \
|
||||
else printf(\"$RESET%s\n\", \$0); \
|
||||
} \
|
||||
}"
|
||||
10
bin/tags.pl
10
bin/tags.pl
@@ -2,8 +2,16 @@
|
||||
|
||||
use strict;
|
||||
|
||||
my $prefix = shift @ARGV;
|
||||
|
||||
foreach my $file (@ARGV) {
|
||||
open my $lines, $file;
|
||||
my $lines;
|
||||
if ($prefix eq "") {
|
||||
open $lines, $file;
|
||||
} else {
|
||||
# https://perldoc.perl.org/perlopentut#Expressing-the-command-as-a-list
|
||||
open $lines, '-|', 'readtags', '-t', $file, '-e', '-p', '-', $prefix;
|
||||
}
|
||||
while (<$lines>) {
|
||||
unless (/^\!/) {
|
||||
s/^[^\t]*/sprintf("%-24s", $&)/e;
|
||||
|
||||
584
doc/fzf-vim.txt
584
doc/fzf-vim.txt
@@ -1,24 +1,35 @@
|
||||
fzf-vim.txt fzf-vim Last change: October 21 2017
|
||||
fzf-vim.txt fzf-vim Last change: June 8 2025
|
||||
FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
|
||||
==============================================================================
|
||||
|
||||
fzf :heart: vim
|
||||
Rationale
|
||||
Why you should use fzf on Vim
|
||||
Installation
|
||||
Commands
|
||||
Customization
|
||||
Global options
|
||||
Command-local options
|
||||
Advanced customization
|
||||
Mappings
|
||||
Usage
|
||||
Completion helper
|
||||
Reducer example
|
||||
Status line (neovim)
|
||||
License
|
||||
fzf :heart: vim |fzf-vim-fzfheart-vim|
|
||||
Rationale |fzf-vim-rationale|
|
||||
Why you should use fzf on Vim |fzf-vim-why-you-should-use-fzf-on-vim|
|
||||
Installation |fzf-vim-installation|
|
||||
Using vim-plug |fzf-vim-using-vim-plug|
|
||||
Dependencies |fzf-vim-dependencies|
|
||||
Commands |fzf-vim-commands|
|
||||
Customization |fzf-vim-customization|
|
||||
Configuration options of the base plugin |fzf-vim-configuration-options-of-the-base-plugin|
|
||||
Configuration options for fzf.vim |fzf-vim-configuration-options-for-fzf-vim|
|
||||
Preview window |fzf-vim-preview-window|
|
||||
Command-level options |fzf-vim-command-level-options|
|
||||
Command-level fzf options |fzf-vim-command-level-fzf-options|
|
||||
List type to handle multiple selections |fzf-vim-list-type-to-handle-multiple-selections|
|
||||
Advanced customization |fzf-vim-advanced-customization|
|
||||
Vim functions |fzf-vim-vim-functions|
|
||||
Example: Customizing Files command |fzf-vim-example-customizing-files-command|
|
||||
Example: git grep wrapper |fzf-vim-example-git-grep-wrapper|
|
||||
Mappings |fzf-vim-mappings|
|
||||
Completion functions |fzf-vim-completion-functions|
|
||||
Custom completion |fzf-vim-custom-completion|
|
||||
Reducer example |fzf-vim-reducer-example|
|
||||
Status line of terminal buffer |fzf-vim-status-line-of-terminal-buffer|
|
||||
Hide statusline |fzf-vim-hide-statusline|
|
||||
Custom statusline |fzf-vim-custom-statusline|
|
||||
License |fzf-vim-license|
|
||||
|
||||
FZF :HEART: VIM *fzf-vim-fzf-heart-vim*
|
||||
FZF :HEART: VIM *fzf-vim-fzfheart-vim*
|
||||
==============================================================================
|
||||
|
||||
Things you can do with {fzf}{1} and Vim.
|
||||
@@ -29,19 +40,14 @@ Things you can do with {fzf}{1} and Vim.
|
||||
RATIONALE *fzf-vim-rationale*
|
||||
==============================================================================
|
||||
|
||||
{fzf}{1} in itself is not a Vim plugin, and the official repository only
|
||||
provides the {basic wrapper function}{2} for Vim and it's up to the users to
|
||||
write their own Vim commands with it. However, I've learned that many users of
|
||||
fzf are not familiar with Vimscript and are looking for the "default"
|
||||
implementation of the features they can find in the alternative Vim plugins.
|
||||
{fzf}{1} itself is not a Vim plugin, and the official repository only provides
|
||||
the {basic wrapper function}{2} for Vim. It's up to the users to write their
|
||||
own Vim commands with it. However, I've learned that many users of fzf are not
|
||||
familiar with Vimscript and are looking for the "default" implementation of
|
||||
the features they can find in the alternative Vim plugins.
|
||||
|
||||
This repository is a bundle of fzf-based commands and mappings extracted from
|
||||
my {.vimrc}{3} to address such needs. They are not designed to be flexible or
|
||||
configurable, and there's no guarantee of backward-compatibility.
|
||||
|
||||
{1} https://github.com/junegunn/fzf
|
||||
{2} https://github.com/junegunn/fzf#usage-as-vim-plugin
|
||||
{3} https://github.com/junegunn/dotfiles/blob/master/vimrc
|
||||
{1} https://github.com/junegunn/fzf
|
||||
{2} https://github.com/junegunn/fzf/blob/master/README-VIM.md#fzfrun
|
||||
|
||||
|
||||
WHY YOU SHOULD USE FZF ON VIM *fzf-vim-why-you-should-use-fzf-on-vim*
|
||||
@@ -55,194 +61,356 @@ is small, which is the case for many of the commands provided here.
|
||||
Nevertheless I wrote them anyway since it's really easy to implement custom
|
||||
selector with fzf.
|
||||
|
||||
fzf is an independent command-line program and thus requires an external
|
||||
terminal emulator when on GVim. You may or may not like the experience. Also
|
||||
note that Windows support is experimental at the moment.
|
||||
|
||||
|
||||
INSTALLATION *fzf-vim-installation*
|
||||
==============================================================================
|
||||
|
||||
Use {vim-plug}{4} or any Vim plugin manager of your choice.
|
||||
fzf.vim depends on the basic Vim plugin of {the main fzf repository}{1}, which
|
||||
means you need to set up both "fzf" and "fzf.vim" on Vim. To learn more about
|
||||
fzf/Vim integration, see {README-VIM}{3}.
|
||||
|
||||
If you already installed fzf using {Homebrew}{5}, the following should
|
||||
suffice:
|
||||
{1} https://github.com/junegunn/fzf
|
||||
{3} https://github.com/junegunn/fzf/blob/master/README-VIM.md
|
||||
|
||||
|
||||
< Using vim-plug >____________________________________________________________~
|
||||
*fzf-vim-using-vim-plug*
|
||||
>
|
||||
Plug '/usr/local/opt/fzf'
|
||||
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
|
||||
Plug 'junegunn/fzf.vim'
|
||||
<
|
||||
But if you want to install fzf as well using vim-plug:
|
||||
>
|
||||
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
|
||||
Plug 'junegunn/fzf.vim'
|
||||
<
|
||||
- `dir` and `do` options are not mandatory
|
||||
- Use `./install --bin` instead if you don't need fzf outside of Vim
|
||||
- Make sure to use Vim 7.4 or above
|
||||
`fzf#install()` makes sure that you have the latest binary, but it's optional,
|
||||
so you can omit it if you use a plugin manager that doesn't support hooks.
|
||||
|
||||
{4} https://github.com/junegunn/vim-plug
|
||||
{5} https://brew.sh/
|
||||
|
||||
< Dependencies >______________________________________________________________~
|
||||
*fzf-vim-dependencies*
|
||||
|
||||
- {fzf}{1} 0.54.0 or above
|
||||
- For syntax-highlighted preview, install {bat}{4}
|
||||
- If {delta}{5} is available, `GF?`, `Commits` and `BCommits` will use it to
|
||||
format `git diff` output.
|
||||
- `Ag` requires {The Silver Searcher (ag)}{6}
|
||||
- `Rg` requires {ripgrep (rg)}{7}
|
||||
- `Tags` and `Helptags` require Perl
|
||||
- `Tags PREFIX` requires `readtags` command from {Universal Ctags}{8}
|
||||
>
|
||||
# Installing dependencies using Homebrew
|
||||
brew install fzf bat ripgrep the_silver_searcher perl universal-ctags
|
||||
<
|
||||
{1} https://github.com/junegunn/fzf
|
||||
{4} https://github.com/sharkdp/bat
|
||||
{5} https://github.com/dandavison/delta
|
||||
{6} https://github.com/ggreer/the_silver_searcher
|
||||
{7} https://github.com/BurntSushi/ripgrep
|
||||
{8} https://ctags.io/
|
||||
|
||||
|
||||
COMMANDS *fzf-vim-commands*
|
||||
==============================================================================
|
||||
|
||||
*:Files* *:GFiles* *:Buffers* *:Colors* *:Ag* *:Rg* *:RG* *:Lines* *:BLines* *:Tags* *:BTags*
|
||||
*:Changes* *:Marks* *:BMarks* *:Jumps* *:Windows* *:Locate* *:History* *:Snippets* *:Commits*
|
||||
*:BCommits* *:Commands* *:Maps* *:Helptags* *:Filetypes*
|
||||
|
||||
-----------------+-----------------------------------------------------------------------
|
||||
Command | List ~
|
||||
-----------------+-----------------------------------------------------------------------
|
||||
`Files [PATH]` | Files (similar to `:FZF` )
|
||||
`GFiles [OPTS]` | Git files ( `git ls-files` )
|
||||
`GFiles?` | Git files ( `git status` )
|
||||
`Buffers` | Open buffers
|
||||
`Colors` | Color schemes
|
||||
`Ag [PATTERN]` | {ag}{6} search result ( `ALT-A` to select all, `ALT-D` to deselect all)
|
||||
`Lines [QUERY]` | Lines in loaded buffers
|
||||
`BLines [QUERY]` | Lines in the current buffer
|
||||
`Tags [QUERY]` | Tags in the project ( `ctags -R` )
|
||||
`BTags [QUERY]` | Tags in the current buffer
|
||||
`Marks` | Marks
|
||||
`Windows` | Windows
|
||||
`Locate PATTERN` | `locate` command output
|
||||
`History` | `v:oldfiles` and open buffers
|
||||
`History:` | Command history
|
||||
`History/` | Search history
|
||||
`Snippets` | Snippets ({UltiSnips}{7})
|
||||
`Commits` | Git commits (requires {fugitive.vim}{8})
|
||||
`BCommits` | Git commits for the current buffer
|
||||
`Commands` | Commands
|
||||
`Maps` | Normal mode mappings
|
||||
`Helptags` | Help tags [1]
|
||||
`Filetypes` | File types
|
||||
-----------------+-----------------------------------------------------------------------
|
||||
-----------------------+--------------------------------------------------------------------------------------
|
||||
Command | List ~
|
||||
-----------------------+--------------------------------------------------------------------------------------
|
||||
`:Files [PATH]` | Files (runs `$FZF_DEFAULT_COMMAND` if defined)
|
||||
`:GFiles [OPTS]` | Git files ( `git ls-files` )
|
||||
`:GFiles?` | Git files ( `git status` )
|
||||
`:Buffers` | Open buffers
|
||||
`:Colors` | Color schemes
|
||||
`:Ag [PATTERN]` | {ag}{6} search result ( `ALT-A` to select all, `ALT-D` to deselect all)
|
||||
`:Rg [PATTERN]` | {rg}{7} search result ( `ALT-A` to select all, `ALT-D` to deselect all)
|
||||
`:RG [PATTERN]` | {rg}{7} search result; relaunch ripgrep on every keystroke
|
||||
`:Lines [QUERY]` | Lines in loaded buffers
|
||||
`:BLines [QUERY]` | Lines in the current buffer
|
||||
`:Tags [PREFIX]` | Tags in the project ( `ctags -R` )
|
||||
`:BTags [QUERY]` | Tags in the current buffer
|
||||
`:Changes` | Changelist across all open buffers
|
||||
`:Marks` | Marks
|
||||
`:BMarks` | Marks in the current buffer
|
||||
`:Jumps` | Jumps
|
||||
`:Windows` | Windows
|
||||
`:Locate PATTERN` | `locate` command output
|
||||
`:History` | `v:oldfiles` and open buffers
|
||||
`:History:` | Command history
|
||||
`:History/` | Search history
|
||||
`:Snippets` | Snippets ({UltiSnips}{9})
|
||||
`:Commits [LOG_OPTS]` | Git commits (requires {fugitive.vim}{10})
|
||||
`:BCommits [LOG_OPTS]` | Git commits for the current buffer; visual-select lines to track changes in the range
|
||||
`:Commands` | Commands
|
||||
`:Maps` | Normal mode mappings
|
||||
`:Helptags` | Help tags [1]
|
||||
`:Filetypes` | File types
|
||||
-----------------------+--------------------------------------------------------------------------------------
|
||||
|
||||
*g:fzf_command_prefix*
|
||||
*g:fzf_vim.command_prefix*
|
||||
|
||||
- Most commands support CTRL-T / CTRL-X / CTRL-V key bindings to open in a new
|
||||
tab, a new split, or in a new vertical split
|
||||
- Bang-versions of the commands (e.g. `Ag!`) will open fzf in fullscreen
|
||||
- You can set `g:fzf_command_prefix` to give the same prefix to the commands
|
||||
- e.g. `let g:fzf_command_prefix = 'Fzf'` and you have `FzfFiles`, etc.
|
||||
- You can set `g:fzf_vim.command_prefix` to give the same prefix to the commands
|
||||
- e.g. `let g:fzf_vim.command_prefix = 'Fzf'` and you have `FzfFiles`, etc.
|
||||
|
||||
(1: `Helptags` will shadow the command of the same name from {pathogen}{9}.
|
||||
But its functionality is still available via `call pathogen#helptags()`.)
|
||||
(1: `Helptags` will shadow the command of the same name from {pathogen}{11}.
|
||||
But its functionality is still available via `call pathogen#helptags()`. [↩])
|
||||
|
||||
{6} https://github.com/ggreer/the_silver_searcher
|
||||
{7} https://github.com/SirVer/ultisnips
|
||||
{8} https://github.com/tpope/vim-fugitive
|
||||
{9} https://github.com/tpope/vim-pathogen
|
||||
{7} https://github.com/BurntSushi/ripgrep
|
||||
{7} https://github.com/BurntSushi/ripgrep
|
||||
{9} https://github.com/SirVer/ultisnips
|
||||
{10} https://github.com/tpope/vim-fugitive
|
||||
{11} https://github.com/tpope/vim-pathogen
|
||||
|
||||
|
||||
< Customization >_____________________________________________________________~
|
||||
*fzf-vim-customization*
|
||||
CUSTOMIZATION *fzf-vim-customization*
|
||||
==============================================================================
|
||||
|
||||
|
||||
Global options~
|
||||
*fzf-vim-global-options*
|
||||
< Configuration options of the base plugin >__________________________________~
|
||||
*fzf-vim-configuration-options-of-the-base-plugin*
|
||||
|
||||
See {README-VIM.md}{10} of the main fzf repository for details.
|
||||
Every command in fzf.vim internally calls `fzf#wrap` function of the main
|
||||
repository which supports a set of global option variables. So please read
|
||||
through {README-VIM}{3} to learn more about them.
|
||||
|
||||
{3} https://github.com/junegunn/fzf/blob/master/README-VIM.md
|
||||
|
||||
|
||||
< Configuration options for fzf.vim >_________________________________________~
|
||||
*fzf-vim-configuration-options-for-fzf-vim*
|
||||
|
||||
*g:fzf_vim*
|
||||
|
||||
All configuration values for this plugin are stored in `g:fzf_vim` dictionary,
|
||||
so make sure to initialize it before assigning any configuration values to it.
|
||||
>
|
||||
" This is the default extra key bindings
|
||||
let g:fzf_action = {
|
||||
\ 'ctrl-t': 'tab split',
|
||||
\ 'ctrl-x': 'split',
|
||||
\ 'ctrl-v': 'vsplit' }
|
||||
|
||||
" Default fzf layout
|
||||
" - down / up / left / right
|
||||
let g:fzf_layout = { 'down': '~40%' }
|
||||
|
||||
" In Neovim, you can set up fzf window using a Vim command
|
||||
let g:fzf_layout = { 'window': 'enew' }
|
||||
let g:fzf_layout = { 'window': '-tabnew' }
|
||||
let g:fzf_layout = { 'window': '10split enew' }
|
||||
|
||||
" Customize fzf colors to match your color scheme
|
||||
let g:fzf_colors =
|
||||
\ { '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'] }
|
||||
|
||||
" Enable per-command history.
|
||||
" CTRL-N and CTRL-P will be automatically bound to next-history and
|
||||
" previous-history instead of down and up. If you don't like the change,
|
||||
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
|
||||
let g:fzf_history_dir = '~/.local/share/fzf-history'
|
||||
" Initialize configuration dictionary
|
||||
let g:fzf_vim = {}
|
||||
<
|
||||
{10} https://github.com/junegunn/fzf/blob/master/README-VIM.md#configuration
|
||||
|
||||
Preview window~
|
||||
*fzf-vim-preview-window*
|
||||
|
||||
Command-local options~
|
||||
*fzf-vim-command-local-options*
|
||||
*g:fzf_vim.preview_window*
|
||||
|
||||
*g:fzf_buffers_jump* *g:fzf_commits_log_options* *g:fzf_tags_command*
|
||||
*g:fzf_commands_expect*
|
||||
Some commands will show the preview window on the right. You can customize the
|
||||
behavior with `g:fzf_vim.preview_window`. Here are some examples:
|
||||
|
||||
*g:fzf_vim.preview_bash*
|
||||
>
|
||||
" [Buffers] Jump to the existing window if possible
|
||||
let g:fzf_buffers_jump = 1
|
||||
" This is the default option:
|
||||
" - Preview window on the right with 50% width
|
||||
" - CTRL-/ will toggle preview window.
|
||||
" - Note that this array is passed as arguments to fzf#vim#with_preview function.
|
||||
" - To learn more about preview window options, see `--preview-window` section of `man fzf`.
|
||||
let g:fzf_vim.preview_window = ['right,50%', 'ctrl-/']
|
||||
|
||||
" Preview window is hidden by default. You can toggle it with ctrl-/.
|
||||
" It will show on the right with 50% width, but if the width is smaller
|
||||
" than 70 columns, it will show above the candidate list
|
||||
let g:fzf_vim.preview_window = ['hidden,right,50%,<70(up,40%)', 'ctrl-/']
|
||||
|
||||
" Empty value to disable preview window altogether
|
||||
let g:fzf_vim.preview_window = []
|
||||
|
||||
" fzf.vim needs bash to display the preview window.
|
||||
" On Windows, fzf.vim will first see if bash is in $PATH, then if
|
||||
" Git bash (C:\Program Files\Git\bin\bash.exe) is available.
|
||||
" If you want it to use a different bash, set this variable.
|
||||
" let g:fzf_vim = {}
|
||||
" let g:fzf_vim.preview_bash = 'C:\Git\bin\bash.exe'
|
||||
<
|
||||
|
||||
Command-level options~
|
||||
*fzf-vim-command-level-options*
|
||||
|
||||
*g:fzf_vim.commands_expect* *g:fzf_vim.tags_command* *g:fzf_vim.commits_log_options*
|
||||
*g:fzf_vim.buffers_jump*
|
||||
>
|
||||
" [Buffers] Jump to the existing window if possible (default: 0)
|
||||
let g:fzf_vim.buffers_jump = 1
|
||||
|
||||
" [Ag|Rg|RG] Display path on a separate line for narrow screens (default: 0)
|
||||
" * Requires Perl and fzf 0.56.0 or later
|
||||
let g:fzf_vim.grep_multi_line = 0
|
||||
" PATH:LINE:COL:LINE
|
||||
let g:fzf_vim.grep_multi_line = 1
|
||||
" PATH:LINE:COL:
|
||||
" LINE
|
||||
let g:fzf_vim.grep_multi_line = 2
|
||||
" PATH:LINE:COL:
|
||||
" LINE
|
||||
" (empty line between items using --gap option)
|
||||
|
||||
" [[B]Commits] Customize the options used by 'git log':
|
||||
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
|
||||
let g:fzf_vim.commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
|
||||
|
||||
" [Tags] Command to generate tags file
|
||||
let g:fzf_tags_command = 'ctags -R'
|
||||
let g:fzf_vim.tags_command = 'ctags -R'
|
||||
|
||||
" [Commands] --expect expression for directly executing the command
|
||||
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
|
||||
let g:fzf_vim.commands_expect = 'alt-enter,ctrl-x'
|
||||
<
|
||||
|
||||
Advanced customization~
|
||||
Command-level fzf options~
|
||||
*fzf-vim-command-level-fzf-options*
|
||||
|
||||
You can set fzf options for each command by setting
|
||||
`g:fzf_vim.{command}_options`.
|
||||
>
|
||||
" In string
|
||||
let g:fzf_vim.buffers_options = '--style full --border-label " Open Buffers "'
|
||||
|
||||
" In list (No need to quote or escape values)
|
||||
let g:fzf_vim.buffers_options = ['--style', 'full', '--border-label', ' Open Buffers ']
|
||||
<
|
||||
|
||||
List type to handle multiple selections~
|
||||
*fzf-vim-list-type-to-handle-multiple-selections*
|
||||
|
||||
The following commands will fill the quickfix list when multiple entries are
|
||||
selected.
|
||||
|
||||
- `Ag`
|
||||
- `Rg` / `RG`
|
||||
- `Lines` / `BLines`
|
||||
- `Tags` / `BTags`
|
||||
|
||||
*g:fzf_vim.listproc*
|
||||
|
||||
By setting `g:fzf_vim.listproc`, you can make them use location list instead.
|
||||
>
|
||||
" Default: Use quickfix list
|
||||
let g:fzf_vim.listproc = { list -> fzf#vim#listproc#quickfix(list) }
|
||||
|
||||
" Use location list instead of quickfix list
|
||||
let g:fzf_vim.listproc = { list -> fzf#vim#listproc#location(list) }
|
||||
<
|
||||
You can customize the list type per command by defining variables named
|
||||
`g:fzf_vim.listproc_{command_name_in_lowercase}`.
|
||||
|
||||
*g:fzf_vim.listproc_rg* *g:fzf_vim.listproc_ag*
|
||||
>
|
||||
" Command-wise customization
|
||||
let g:fzf_vim.listproc_ag = { list -> fzf#vim#listproc#quickfix(list) }
|
||||
let g:fzf_vim.listproc_rg = { list -> fzf#vim#listproc#location(list) }
|
||||
<
|
||||
You can further customize the behavior by providing a custom function to
|
||||
process the list instead of using the predefined `fzf#vim#listproc#quickfix`
|
||||
or `fzf#vim#listproc#location`.
|
||||
>
|
||||
" A customized version of fzf#vim#listproc#quickfix.
|
||||
" The last two lines are commented out not to move to the first entry.
|
||||
function! g:fzf_vim.listproc(list)
|
||||
call setqflist(a:list)
|
||||
copen
|
||||
wincmd p
|
||||
" cfirst
|
||||
" normal! zvzz
|
||||
endfunction
|
||||
<
|
||||
|
||||
< Advanced customization >____________________________________________________~
|
||||
*fzf-vim-advanced-customization*
|
||||
|
||||
You can use autoload functions to define your own commands.
|
||||
|
||||
Vim functions~
|
||||
*fzf-vim-vim-functions*
|
||||
|
||||
Each command in fzf.vim is backed by a Vim function. You can override a
|
||||
command or define a variation of it by calling its corresponding function.
|
||||
|
||||
----------+---------------------------------------------------------------------------------
|
||||
Command | Vim function ~
|
||||
----------+---------------------------------------------------------------------------------
|
||||
`Files` | `fzf#vim#files(dir, [spec dict], [fullscreen bool])`
|
||||
`GFiles` | `fzf#vim#gitfiles(git_options, [spec dict], [fullscreen bool])`
|
||||
`GFiles?` | `fzf#vim#gitfiles('?', [spec dict], [fullscreen bool])`
|
||||
`Buffers` | `fzf#vim#buffers([query string], [bufnrs list], [spec dict], [fullscreen bool])`
|
||||
`Colors` | `fzf#vim#colors([spec dict], [fullscreen bool])`
|
||||
`Rg` | `fzf#vim#grep(command, [spec dict], [fullscreen bool])`
|
||||
`RG` | `fzf#vim#grep2(command_prefix, query, [spec dict], [fullscreen bool])`
|
||||
... | ...
|
||||
----------+---------------------------------------------------------------------------------
|
||||
|
||||
(We can see that the last two optional arguments of each function are
|
||||
identical. They are directly passed to `fzf#wrap` function. If you haven't
|
||||
read {README-VIM}{3} already, please read it before proceeding.)
|
||||
|
||||
{3} https://github.com/junegunn/fzf/blob/master/README-VIM.md
|
||||
|
||||
|
||||
Example: Customizing Files command~
|
||||
*fzf-vim-example-customizing-files-command*
|
||||
|
||||
This is the default definition of `Files` command:
|
||||
>
|
||||
" Command for git grep
|
||||
" - fzf#vim#grep(command, with_column, [options], [fullscreen])
|
||||
command! -bang -nargs=* GGrep
|
||||
\ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0)
|
||||
|
||||
" Override Colors command. You can safely do this in your .vimrc as fzf.vim
|
||||
" will not override existing commands.
|
||||
command! -bang Colors
|
||||
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}, <bang>0)
|
||||
|
||||
" Augmenting Ag command using fzf#vim#with_preview function
|
||||
" * fzf#vim#with_preview([[options], preview window, [toggle keys...]])
|
||||
" * For syntax-highlighting, Ruby and any of the following tools are required:
|
||||
" - Highlight: http://www.andre-simon.de/doku/highlight/en/highlight.php
|
||||
" - CodeRay: http://coderay.rubychan.de/
|
||||
" - Rouge: https://github.com/jneen/rouge
|
||||
"
|
||||
" :Ag - Start fzf with hidden preview window that can be enabled with "?" key
|
||||
" :Ag! - Start fzf in fullscreen and display the preview window above
|
||||
command! -bang -nargs=* Ag
|
||||
\ call fzf#vim#ag(<q-args>,
|
||||
\ <bang>0 ? fzf#vim#with_preview('up:60%')
|
||||
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
|
||||
\ <bang>0)
|
||||
|
||||
" Similarly, we can apply it to fzf#vim#grep. To use ripgrep instead of ag:
|
||||
command! -bang -nargs=* Rg
|
||||
\ call fzf#vim#grep(
|
||||
\ 'rg --column --line-number --no-heading --color=always '.shellescape(<q-args>), 1,
|
||||
\ <bang>0 ? fzf#vim#with_preview('up:60%')
|
||||
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
|
||||
\ <bang>0)
|
||||
|
||||
" Likewise, Files command with preview window
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
|
||||
command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, <bang>0)
|
||||
<
|
||||
Let's say you want to a variation of it called `ProjectFiles` that only
|
||||
searches inside `~/projects` directory. Then you can do it like this:
|
||||
>
|
||||
command! -bang ProjectFiles call fzf#vim#files('~/projects', <bang>0)
|
||||
<
|
||||
Or, if you want to override the command with different fzf options, just pass
|
||||
a custom spec to the function.
|
||||
>
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline']}, <bang>0)
|
||||
<
|
||||
Want a preview window?
|
||||
>
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline', '--preview', 'cat {}']}, <bang>0)
|
||||
<
|
||||
It kind of works, but you probably want a nicer previewer program than `cat`.
|
||||
fzf.vim ships {a versatile preview script}{12} you can readily use. It
|
||||
internally executes {bat}{4} for syntax highlighting, so make sure to install
|
||||
it.
|
||||
>
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline', '--preview', '~/.vim/plugged/fzf.vim/bin/preview.sh {}']}, <bang>0)
|
||||
<
|
||||
However, it's not ideal to hard-code the path to the script which can be
|
||||
different in different circumstances. So in order to make it easier to set up
|
||||
the previewer, fzf.vim provides `fzf#vim#with_preview` helper function.
|
||||
Similarly to `fzf#wrap`, it takes a spec dictionary and returns a copy of it
|
||||
with additional preview options.
|
||||
>
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview({'options': ['--layout=reverse', '--info=inline']}), <bang>0)
|
||||
<
|
||||
You can just omit the spec argument if you only want the previewer.
|
||||
>
|
||||
command! -bang -nargs=? -complete=dir Files
|
||||
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
|
||||
<
|
||||
{12} bin/preview.sh
|
||||
{4} https://github.com/sharkdp/bat
|
||||
|
||||
|
||||
Example: git grep wrapper~
|
||||
*fzf-vim-example-git-grep-wrapper*
|
||||
|
||||
The following example implements `GGrep` command that works similarly to
|
||||
predefined `Ag` or `Rg` using `fzf#vim#grep`.
|
||||
|
||||
- We set the base directory to git root by setting `dir` attribute in spec
|
||||
dictionary.
|
||||
- {The preview script}{12} supports `grep` format (`FILE_PATH:LINE_NO:...`), so
|
||||
we can just wrap the spec with `fzf#vim#with_preview` as before to enable
|
||||
previewer.
|
||||
>
|
||||
command! -bang -nargs=* GGrep
|
||||
\ call fzf#vim#grep(
|
||||
\ 'git grep --line-number -- '.fzf#shellescape(<q-args>),
|
||||
\ fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), <bang>0)
|
||||
<
|
||||
{12} bin/preview.sh
|
||||
|
||||
|
||||
MAPPINGS *fzf-vim-mappings*
|
||||
==============================================================================
|
||||
@@ -254,17 +422,12 @@ MAPPINGS *fzf-vim-mappings*
|
||||
<plug>(fzf-maps-i) | Insert mode mappings
|
||||
<plug>(fzf-maps-x) | Visual mode mappings
|
||||
<plug>(fzf-maps-o) | Operator-pending mappings
|
||||
<plug>(fzf-complete-word) | `cat /usr/share/dict/words`
|
||||
<plug>(fzf-complete-word) | `cat /usr/share/dict/words`
|
||||
<plug>(fzf-complete-path) | Path completion using `find` (file + dir)
|
||||
<plug>(fzf-complete-file) | File completion using `find`
|
||||
<plug>(fzf-complete-file-ag) | File completion using `ag`
|
||||
<plug>(fzf-complete-line) | Line completion (all open buffers)
|
||||
<plug>(fzf-complete-buffer-line) | Line completion (current buffer only)
|
||||
---------------------------------+------------------------------------------
|
||||
|
||||
|
||||
< Usage >_____________________________________________________________________~
|
||||
*fzf-vim-usage*
|
||||
>
|
||||
" Mapping selecting mappings
|
||||
nmap <leader><tab> <plug>(fzf-maps-n)
|
||||
@@ -274,22 +437,38 @@ MAPPINGS *fzf-vim-mappings*
|
||||
" Insert mode completion
|
||||
imap <c-x><c-k> <plug>(fzf-complete-word)
|
||||
imap <c-x><c-f> <plug>(fzf-complete-path)
|
||||
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
|
||||
imap <c-x><c-l> <plug>(fzf-complete-line)
|
||||
|
||||
" Advanced customization using autoload functions
|
||||
inoremap <expr> <c-x><c-k> fzf#vim#complete#word({'left': '15%'})
|
||||
<
|
||||
|
||||
< Completion helper >_________________________________________________________~
|
||||
*fzf-vim-completion-helper*
|
||||
COMPLETION FUNCTIONS *fzf-vim-completion-functions*
|
||||
==============================================================================
|
||||
|
||||
`fzf#complete` is a helper function for creating custom fuzzy completion using
|
||||
fzf. If the first parameter is a command string or a Vim list, it will be used
|
||||
as the source.
|
||||
-----------------------------------------+--------------------------------------
|
||||
Function | Description ~
|
||||
-----------------------------------------+--------------------------------------
|
||||
`fzf#vim#complete#path(command, [spec])` | Path completion
|
||||
`fzf#vim#complete#word([spec])` | Word completion
|
||||
`fzf#vim#complete#line([spec])` | Line completion (all open buffers)
|
||||
`fzf#vim#complete#buffer_line([spec])` | Line completion (current buffer only)
|
||||
-----------------------------------------+--------------------------------------
|
||||
>
|
||||
" Path completion with custom source command
|
||||
inoremap <expr> <c-x><c-f> fzf#vim#complete#path('fd')
|
||||
inoremap <expr> <c-x><c-f> fzf#vim#complete#path('rg --files')
|
||||
|
||||
" Word completion with custom spec with popup layout option
|
||||
inoremap <expr> <c-x><c-k> fzf#vim#complete#word({'window': { 'width': 0.2, 'height': 0.9, 'xoffset': 1 }})
|
||||
<
|
||||
|
||||
CUSTOM COMPLETION *fzf-vim-custom-completion*
|
||||
==============================================================================
|
||||
|
||||
`fzf#vim#complete` is a helper function for creating custom fuzzy completion
|
||||
using fzf. If the first parameter is a command string or a Vim list, it will
|
||||
be used as the source.
|
||||
>
|
||||
" Replace the default dictionary completion with fzf-based fuzzy completion
|
||||
inoremap <expr> <c-x><c-k> fzf#complete('cat /usr/share/dict/words')
|
||||
inoremap <expr> <c-x><c-k> fzf#vim#complete('cat /usr/share/dict/words')
|
||||
<
|
||||
For advanced uses, you can pass an options dictionary to the function. The set
|
||||
of options is pretty much identical to that for `fzf#run` only with the
|
||||
@@ -303,24 +482,47 @@ following exceptions:
|
||||
- Both `source` and `options` can be given as funcrefs that take the completion
|
||||
prefix as the argument and return the final value
|
||||
- `sink` or `sink*` are ignored
|
||||
>
|
||||
" Global line completion (not just open buffers. ripgrep required.)
|
||||
inoremap <expr> <c-x><c-l> fzf#vim#complete(fzf#wrap({
|
||||
\ 'prefix': '^.*$',
|
||||
\ 'source': 'rg -n ^ --color always',
|
||||
\ 'options': '--ansi --delimiter : --nth 3..',
|
||||
\ 'reducer': { lines -> join(split(lines[0], ':\zs')[2:], '') }}))
|
||||
<
|
||||
|
||||
|
||||
Reducer example~
|
||||
< Reducer example >___________________________________________________________~
|
||||
*fzf-vim-reducer-example*
|
||||
>
|
||||
function! s:make_sentence(lines)
|
||||
return substitute(join(a:lines), '^.', '\=toupper(submatch(0))', '').'.'
|
||||
endfunction
|
||||
|
||||
inoremap <expr> <c-x><c-s> fzf#complete({
|
||||
inoremap <expr> <c-x><c-s> fzf#vim#complete({
|
||||
\ 'source': 'cat /usr/share/dict/words',
|
||||
\ 'reducer': function('<sid>make_sentence'),
|
||||
\ 'options': '--multi --reverse --margin 15%,0',
|
||||
\ 'left': 20})
|
||||
<
|
||||
|
||||
STATUS LINE (NEOVIM) *fzf-vim-status-lineneovim*
|
||||
STATUS LINE OF TERMINAL BUFFER *fzf-vim-status-line-of-terminal-buffer*
|
||||
==============================================================================
|
||||
|
||||
When fzf starts in a terminal buffer (see {fzf/README-VIM.md}{13}), you may
|
||||
want to customize the statusline of the containing buffer.
|
||||
|
||||
{13} https://github.com/junegunn/fzf/blob/master/README-VIM.md#fzf-inside-terminal-buffer
|
||||
|
||||
|
||||
< Hide statusline >___________________________________________________________~
|
||||
*fzf-vim-hide-statusline*
|
||||
>
|
||||
autocmd! FileType fzf set laststatus=0 noshowmode noruler
|
||||
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
|
||||
<
|
||||
|
||||
< Custom statusline >_________________________________________________________~
|
||||
*fzf-vim-custom-statusline*
|
||||
>
|
||||
function! s:fzf_statusline()
|
||||
" Override statusline as you like
|
||||
|
||||
@@ -21,12 +21,23 @@
|
||||
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
if exists('g:loaded_fzf_vim')
|
||||
finish
|
||||
endif
|
||||
let g:loaded_fzf_vim = 1
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
let s:is_win = has('win32') || has('win64')
|
||||
|
||||
function! s:conf(name, default)
|
||||
let conf = get(g:, 'fzf_vim', {})
|
||||
let val = get(conf, a:name, get(g:, 'fzf_' . a:name, a:default))
|
||||
return val
|
||||
endfunction
|
||||
|
||||
function! s:defs(commands)
|
||||
let prefix = get(g:, 'fzf_command_prefix', '')
|
||||
let prefix = s:conf('command_prefix', '')
|
||||
if prefix =~# '^[^A-Z]'
|
||||
echoerr 'g:fzf_command_prefix must start with an uppercase letter'
|
||||
return
|
||||
@@ -40,36 +51,41 @@ function! s:defs(commands)
|
||||
endfunction
|
||||
|
||||
call s:defs([
|
||||
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, <bang>0)',
|
||||
\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=* Lines call fzf#vim#lines(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=* BLines call fzf#vim#buffer_lines(<q-args>, <bang>0)',
|
||||
\'command! -bar -bang Colors call fzf#vim#colors(<bang>0)',
|
||||
\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=* Tags call fzf#vim#tags(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, <bang>0)',
|
||||
\'command! -bar -bang Snippets call fzf#vim#snippets(<bang>0)',
|
||||
\'command! -bar -bang Commands call fzf#vim#commands(<bang>0)',
|
||||
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
|
||||
\'command! -bar -bang Helptags call fzf#vim#helptags(<bang>0)',
|
||||
\'command! -bar -bang Windows call fzf#vim#windows(<bang>0)',
|
||||
\'command! -bar -bang Commits call fzf#vim#commits(<bang>0)',
|
||||
\'command! -bar -bang BCommits call fzf#vim#buffer_commits(<bang>0)',
|
||||
\'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)',
|
||||
\'command! -bar -bang Filetypes call fzf#vim#filetypes(<bang>0)',
|
||||
\'command! -bang -nargs=* History call s:history(<q-args>, <bang>0)'])
|
||||
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
|
||||
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
|
||||
\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, fzf#vim#with_preview({ "placeholder": "{1}" }), <bang>0)',
|
||||
\'command! -bang -nargs=* Lines call fzf#vim#lines(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=* BLines call fzf#vim#buffer_lines(<q-args>, <bang>0)',
|
||||
\'command! -bar -bang Colors call fzf#vim#colors(<bang>0)',
|
||||
\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".fzf#shellescape(<q-args>), fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* RG call fzf#vim#grep2("rg --column --line-number --no-heading --color=always --smart-case -- ", <q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Tags call fzf#vim#tags(<q-args>, fzf#vim#with_preview({ "placeholder": "--tag {2}:{-1}:{3..}" }), <bang>0)',
|
||||
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, fzf#vim#with_preview({ "placeholder": "{2}:{3..}" }), <bang>0)',
|
||||
\'command! -bar -bang Snippets call fzf#vim#snippets(<bang>0)',
|
||||
\'command! -bar -bang Commands call fzf#vim#commands(<bang>0)',
|
||||
\'command! -bar -bang Jumps call fzf#vim#jumps(fzf#vim#with_preview({ "placeholder": "{2..4}"}), <bang>0)',
|
||||
\'command! -bar -bang -nargs=* Marks call fzf#vim#marks(<q-args>, <bang>0)',
|
||||
\'command! -bar -bang -nargs=* BMarks call fzf#vim#marks("abcdefghijklmnopqrstuvwxyz", <bang>0)',
|
||||
\'command! -bar -bang Changes call fzf#vim#changes(<bang>0)',
|
||||
\'command! -bar -bang Helptags call fzf#vim#helptags(fzf#vim#with_preview({ "placeholder": "--tag {2}:{3}:{4}" }), <bang>0)',
|
||||
\'command! -bar -bang Windows call fzf#vim#windows(fzf#vim#with_preview({ "placeholder": "{2}" }), <bang>0)',
|
||||
\'command! -bar -bang -nargs=* -range=% -complete=file Commits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#commits(<q-args>, fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
||||
\'command! -bar -bang -nargs=* -range=% BCommits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#buffer_commits(<q-args>, fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
||||
\'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)',
|
||||
\'command! -bar -bang Filetypes call fzf#vim#filetypes(<bang>0)',
|
||||
\'command! -bang -nargs=* History call s:history(<q-args>, fzf#vim#with_preview(), <bang>0)'])
|
||||
|
||||
function! s:history(arg, bang)
|
||||
function! s:history(arg, extra, bang)
|
||||
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
|
||||
if a:arg[0] == ':'
|
||||
call fzf#vim#command_history(bang)
|
||||
elseif a:arg[0] == '/'
|
||||
call fzf#vim#search_history(bang)
|
||||
else
|
||||
call fzf#vim#history(bang)
|
||||
call fzf#vim#history(a:extra, bang)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -77,7 +93,7 @@ function! fzf#complete(...)
|
||||
return call('fzf#vim#complete', a:000)
|
||||
endfunction
|
||||
|
||||
if has('nvim') && get(g:, 'fzf_nvim_statusline', 1)
|
||||
if (has('nvim') || has('terminal') && has('patch-8.0.995')) && (s:conf('statusline', 1) || s:conf('nvim_statusline', 1))
|
||||
function! s:fzf_restore_colors()
|
||||
if exists('#User#FzfStatusLine')
|
||||
doautocmd User FzfStatusLine
|
||||
@@ -95,7 +111,7 @@ if has('nvim') && get(g:, 'fzf_nvim_statusline', 1)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:fzf_nvim_term()
|
||||
function! s:fzf_vim_term()
|
||||
if get(w:, 'airline_active', 0)
|
||||
let w:airline_disabled = 1
|
||||
autocmd BufWinLeave <buffer> let w:airline_disabled = 0
|
||||
@@ -108,11 +124,14 @@ if has('nvim') && get(g:, 'fzf_nvim_statusline', 1)
|
||||
|
||||
augroup _fzf_statusline
|
||||
autocmd!
|
||||
autocmd FileType fzf call s:fzf_nvim_term()
|
||||
autocmd FileType fzf call s:fzf_vim_term()
|
||||
augroup END
|
||||
endif
|
||||
|
||||
let g:fzf#vim#buffers = {}
|
||||
if !exists('g:fzf#vim#buffers')
|
||||
let g:fzf#vim#buffers = {}
|
||||
endif
|
||||
|
||||
augroup fzf_buffers
|
||||
autocmd!
|
||||
if exists('*reltimefloat')
|
||||
|
||||
Reference in New Issue
Block a user