国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專(zhuān)欄INFORMATION COLUMN

VIM與模糊搜索神器FZF的集成用法 - 從簡(jiǎn)單到高級(jí)

?xiaoxiao, / 2362人閱讀

摘要:比如下表是它可用的所有選項(xiàng)是一個(gè)函數(shù),用來(lái)創(chuàng)建自己的自動(dòng)補(bǔ)全功能。如果第一個(gè)參數(shù)是一個(gè)命令字符或一個(gè)那么它會(huì)被用作對(duì)于高級(jí)用戶(hù),可以傳入一個(gè)字典選項(xiàng)。希望大家可以結(jié)合創(chuàng)造出更多的使用方法。

FZF and VIM 前言

fzf本身并不是一個(gè)vim 插件,本來(lái)作者只提供了基本的wrapper函數(shù)(比如fzf#run). 但后來(lái)作者發(fā)現(xiàn)很多人并不熟悉VIMScript, 所以就創(chuàng)建一個(gè)默認(rèn)的vim plugin.

為什么在VIM里用fzf?

fzf可以異步地運(yùn)行,不影響vim操作,比同類(lèi)的其他插件都快得多。

如何安裝

有兩種安裝方式vundle或vim-plug

vundle
set rtp+=/home/harriszh/.fzf/
...
Plugin "junegunn/fzf.vim"
vim-plug
Plug "/usr/local/opt/fzf"
Plug "junegunn/fzf.vim"

如果你希望通過(guò)vim-plug來(lái)安裝fzf, 那么使用下面設(shè)置

Plug "junegunn/fzf", { "dir": "~/.fzf", "do": "./install --all" }
Plug "junegunn/fzf.vim"
vim下支持的命令

這些命令都是FZF調(diào)用某個(gè)工具產(chǎn)生文件,文件內(nèi)容, tag, comment, command,然后FZF用一個(gè)小窗口把它們顯示出來(lái),用戶(hù)就可以用模糊搜索的方式來(lái)選擇一個(gè)或多個(gè)選項(xiàng),按下enter鍵后就可以用VIM打開(kāi)它們或跳轉(zhuǎn)到相應(yīng)的行。
如Files針對(duì)的就是文件, GFiles針對(duì)的就是git文件

Command List
Files [PATH] 普通文件查找 (similar to :FZF)
GFiles [OPTS] git文件查找 (git ls-files)
GFiles? git文件查找 (git status)
Buffers buffer文件切換
Colors Color schemes
Ag [PATTERN] ag search result (ALT-A to select all, ALT-D to deselect all)
Lines [QUERY] 加載的所有buffer里查找
BLines [QUERY] 在當(dāng)前buffer里查找包含某關(guān)鍵詞的行
Tags [QUERY] 以Tag查找 (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: 命令歷史查找
History/ Search history
Snippets Snippets (UltiSnips)
Commits Git commits (requires fugitive.vim)
BCommits Git commits for the current buffer
Commands Commands
Maps Normal mode mappings
Helptags Help tags 1
Filetypes File types
例子

FilesFZF一樣的作用,它會(huì)列出所有文件,選中后vim會(huì)打開(kāi)選中的文件

Buffers用于在存在于buffer中的文件間切換

Lines 用于在存在于buffer里的文件中尋找含有某個(gè)關(guān)鍵詞的行

BLines Lines類(lèi)似,只不過(guò)它只在當(dāng)前buffer里查找

因?yàn)閞ipgrep是目前性能最好的文本內(nèi)容搜索工具,所以我們可以自己定義一個(gè)命令

command! -bang -nargs=* Rg
   call fzf#vim#grep(
     "rg --column --line-number --no-heading --color=always --smart-case ".shellescape(), 1,
     0 ? fzf#vim#with_preview("up:60%")
             : fzf#vim#with_preview("right:50%:hidden", "?"),
     0)

這樣輸入:Rg 會(huì)調(diào)用ripgrep來(lái)遞歸搜索當(dāng)前目錄

定制化 按鍵綁定

上面的命令都可以通過(guò)ctrl-t, ctrl-x, ctrl-v來(lái)在new tab, new split, new vsplit窗口打開(kāi)

" 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"
本地設(shè)定
" [Buffers] 如果可能跳到已存在窗口
let g:fzf_buffers_jump = 1

" [[B]Commits] 自定義被"git log"使用的選項(xiàng)
let g:fzf_commits_log_options = "--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr""

" [Tags] 定義用來(lái)產(chǎn)生tag的命令
let g:fzf_tags_command = "ctags -R"

" [Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = "alt-enter,ctrl-x"
高級(jí)定制

也可以使用autoload函數(shù)來(lái)定義自己的命令

" 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(), 0,
     { "dir": systemlist("git rev-parse --show-toplevel")[0] }, 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"}, 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(,
                   0 ? fzf#vim#with_preview("up:60%")
                           : fzf#vim#with_preview("right:50%:hidden", "?"),
                   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 --smart-case ".shellescape(), 1,
     0 ? fzf#vim#with_preview("up:60%")
             : fzf#vim#with_preview("right:50%:hidden", "?"),
     0)

" Likewise, Files command with preview window
command! -bang -nargs=? -complete=dir Files
   call fzf#vim#files(, fzf#vim#with_preview(), 0)
映射
Mapping Description
(fzf-maps-n) Normal mode mappings
(fzf-maps-i) Insert mode mappings
(fzf-maps-x) Visual mode mappings
(fzf-maps-o) Operator-pending mappings
(fzf-complete-word) cat /usr/share/dict/words
(fzf-complete-path) Path completion using find (file + dir)
(fzf-complete-file) File completion using find
(fzf-complete-file-ag) File completion using ag
(fzf-complete-line) Line completion (all open buffers)
(fzf-complete-buffer-line) Line completion (current buffer only)
映射用法
" Mapping selecting mappings
nmap  (fzf-maps-n)
xmap  (fzf-maps-x)
omap  (fzf-maps-o)

" Insert mode completion
imap  (fzf-complete-word)
imap  (fzf-complete-path)
imap  (fzf-complete-file-ag)
imap  (fzf-complete-line)

" Advanced customization using autoload functions
inoremap   fzf#vim#complete#word({"left": "15%"})
創(chuàng)建自己的插件

fzf#run()是vim集成的核心函數(shù),它接受一個(gè)字典變量作為輸入, 你至少要通過(guò)sink選項(xiàng)來(lái)告訴fzf如何處理選中的條目。
比如:

call fzf#run({"sink": "tabedit", "options": "--multi --reverse"})

call fzf#run({"source": "git ls-files", "sink": "e", "right": "40%"})

call fzf#run({"source": map(split(globpath(&rtp, "colors/*.vim")),
                           "fnamemodify(v:val, ":t:r")"),
             "sink": "colo", "left": "25%"})

下表是它可用的所有選項(xiàng)

Option name Type Description
source string External command to generate input to fzf (e.g. find .)
source list Vim list as input to fzf
sink string Vim command to handle the selected item (e.g. e, tabe)
sink funcref Reference to function to process each selected item
sink* funcref Similar to sink, but takes the list of output lines at once
options string Options to fzf
dir string Working directory
up/down/left/right number/string Use tmux pane with the given size (e.g. 20, 50%)
window (Neovim only) string Command to open fzf window (e.g. vertical aboveleft 30new)
launcher string External terminal emulator to start fzf with (GVim only)
launcher funcref Function for generating launcher string (GVim only)
completion helper

fzf#vim#complete是一個(gè)helper函數(shù),用來(lái)創(chuàng)建自己的自動(dòng)補(bǔ)全功能。 如果第一個(gè)參數(shù)是一個(gè)命令字符或一個(gè)vim list, 那么它會(huì)被用作source.

" Replace the default dictionary completion with fzf-based fuzzy completion
inoremap   fzf#vim#complete("cat /usr/share/dict/words")

對(duì)于高級(jí)用戶(hù),可以傳入一個(gè)字典選項(xiàng)。它的選項(xiàng)和fzf#run是一致的,除了下面幾個(gè)選項(xiàng)。

reducer (funcref)

把fzf的輸出轉(zhuǎn)成單一字符串

prefix (funcref or string; default: k*$)

用于匹配想自動(dòng)補(bǔ)全字符串的正則表達(dá)式

或者是一個(gè)函數(shù)

sourceoptions可以是一個(gè)函數(shù)引用, 它用prefix作為輸入?yún)?shù),返回最終的值

sinksink*被忽略

" 全局補(bǔ)全 (不僅僅是buffers. 需要安裝ripgrep)
inoremap   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例子:

function! s:make_sentence(lines)
return substitute(join(a:lines), "^.", "=toupper(submatch(0))", "")."."
endfunction

inoremap   fzf#vim#complete({
 "source":  "cat /usr/share/dict/words",
 "reducer": function("make_sentence"),
 "options": "--multi --reverse --margin 15%,0",
 "left":    20})
總結(jié)

結(jié)合FZF,vim可實(shí)現(xiàn)快速文件跳轉(zhuǎn),特別是在結(jié)合Rg或ctags或git以后,可以快速地跳轉(zhuǎn)到滿(mǎn)足某種條件的文件中。
希望大家可以結(jié)合FZF創(chuàng)造出更多的使用方法。有任何好點(diǎn)子,歡迎聯(lián)系本人

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.specialneedsforspecialkids.com/yun/25042.html

相關(guān)文章

  • 模糊搜索神器fzf

    摘要:讓你通過(guò)輸入模糊的關(guān)鍵詞就可以定位文件或文件夾。當(dāng)你的思維也習(xí)慣了模糊匹配后,在工作中可以大幅提高你的工作效率。模糊搜索的概念如下,你記得文件名含有,那么你只需要把所有文件送給然后在窗口里輸入就可以了,不管實(shí)現(xiàn)名是還是都會(huì)匹配上。 前言 fzf是目前最快的fuzzy finder。使用golang編寫(xiě)。結(jié)合其他工具(比如ag和fasd)可以完成非常多的工作。讓你通過(guò)輸入模糊的關(guān)鍵詞就可...

    miqt 評(píng)論0 收藏0
  • Vim模糊文件搜索fzf

    摘要:參考官網(wǎng)參考使用全指南安裝直接在插件管理器中其中會(huì)把命令行軟件安裝到本機(jī)的目錄中,然后在中就可以直接通過(guò)執(zhí)行來(lái)使用命令搜索文件了。使用最簡(jiǎn)單的話(huà),直接在中輸入命令就會(huì)彈出當(dāng)前目錄下的所有文件列表,然后可以各種模糊搜索,按和上下選擇。 不同于Command-T只能用于VIM,大名鼎鼎的fzf是命令行工具,而且只在VIM中使用的話(huà)也不需要手動(dòng)去編譯任何依賴(lài),直接用插件管理器安裝即可立馬使用...

    lavor 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<