Skip to content
Myr

fzf.vim

This file

Path

plugin/fzf.vim

251 lines · 6.3 KiB

Last changed by

Merge pull request #116 from junegunn/goJunegunn Choibefore adoption209a6d3

History of this file

Take it

The walk stopped after 200 commits: lines older than 64541cb point at it.

Merge pull request #116 from junegunn/goJunegunn Choibefore adoption209a6d3

line 1why, one step back
1" Copyright (c) 2015 Junegunn Choi

Fix install script (source ~/.xxxrc has no effect)Junegunn Choibefore adoption64541cb

lines 2–23why, one step back
2"
3" MIT License4"5" Permission is hereby granted, free of charge, to any person obtaining6" a copy of this software and associated documentation files (the7" "Software"), to deal in the Software without restriction, including8" without limitation the rights to use, copy, modify, merge, publish,9" distribute, sublicense, and/or sell copies of the Software, and to10" permit persons to whom the Software is furnished to do so, subject to11" the following conditions:12"13" The above copyright notice and this permission notice shall be14" included in all copies or substantial portions of the Software.15"16" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20" LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23

[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0

line 24why, one step back
24let s:min_tmux_width = 10

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

line 25why, one step back
25let s:min_tmux_height = 3

Allow setting tmux split height in %Junegunn Choibefore adoptioncf8dbf8

line 26why, one step back
26let s:default_tmux_height = '40%'

[vim] External terminal emulator for GVimJunegunn Choibefore adoption4a3a5ee

line 27why, one step back
27let s:launcher = 'xterm -e bash -ic %s'

Merge pull request #116 from junegunn/goJunegunn Choibefore adoption209a6d3

line 28why, one step back
28let s:fzf_go = expand('<sfile>:h:h').'/bin/fzf'

[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18

line 29why, one step back
29let s:fzf_rb = expand('<sfile>:h:h').'/fzf'

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

line 30why, one step back
30

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

lines 31–33why, one step back
31let s:cpo_save = &cpo
32set cpo&vim33

[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18

lines 34–37why, one step back
34function! s:fzf_exec()
35 if !exists('s:exec')36 call system('type fzf')37 if v:shell_error

Merge pull request #116 from junegunn/goJunegunn Choibefore adoption209a6d3

lines 38–39why, one step back
38 let s:exec = executable(s:fzf_go) ?
39 \ s:fzf_go : (executable(s:fzf_rb) ? s:fzf_rb : '')

[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18

lines 40–46why, one step back
40 else
41 let s:exec = 'fzf'42 endif43 return s:fzf_exec()44 elseif empty(s:exec)45 unlet s:exec46 throw 'fzf executable not found'

Prefer pre-existing function/alias in Vim pluginJunegunn Choibefore adoptionb8e438b

line 47why, one step back
47 else

[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18

line 48why, one step back
48 return s:exec

Prefer pre-existing function/alias in Vim pluginJunegunn Choibefore adoptionb8e438b

line 49why, one step back
49 endif

[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18

line 50why, one step back
50endfunction

Fix install script (source ~/.xxxrc has no effect)Junegunn Choibefore adoption64541cb

line 51why, one step back
51

Vim plugin: do not enable tmux-integration if version < 1.7Junegunn Choibefore adoptionaf677e7

line 52why, one step back
52function! s:tmux_enabled()

[vim] Enable fzf in GVim using xtermJunegunn Choibefore adoption0b43f98

lines 53–56why, one step back
53 if has('gui_running')
54 return 055 endif56

Vim plugin: do not enable tmux-integration if version < 1.7Junegunn Choibefore adoptionaf677e7

lines 57–68why, one step back
57 if exists('s:tmux')
58 return s:tmux59 endif6061 let s:tmux = 062 if exists('$TMUX')63 let output = system('tmux -V')64 let s:tmux = !v:shell_error && output >= 'tmux 1.7'65 endif66 return s:tmux67endfunction68

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 69–72why, one step back
69function! s:shellesc(arg)
70 return '"'.substitute(a:arg, '"', '\\"', 'g').'"'71endfunction72

Update Vim plugin to take path argumentJunegunn Choibefore adoptionf282741

lines 73–76why, one step back
73function! s:escape(path)
74 return substitute(a:path, ' ', '\\ ', 'g')75endfunction76

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

lines 77–78why, one step back
77function! fzf#run(...) abort
78 let dict = exists('a:1') ? a:1 : {}

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

line 79why, one step back
79 let temps = { 'result': tempname() }

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

line 80why, one step back
80 let optstr = get(dict, 'options', '')

[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18

lines 81–85why, one step back
81 try
82 let fzf_exec = s:fzf_exec()83 catch84 throw v:exception85 endtry

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

lines 86–92why, one step back
86
87 if has_key(dict, 'source')88 let source = dict.source89 let type = type(source)90 if type == 191 let prefix = source.'|'92 elseif type == 3

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 93–95why, one step back
93 let temps.input = tempname()
94 call writefile(source, temps.input)95 let prefix = 'cat '.s:shellesc(temps.input).'|'

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

lines 96–101why, one step back
96 else
97 throw 'Invalid source type'98 endif99 else100 let prefix = ''101 endif

[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18

line 102why, one step back
102 let command = prefix.fzf_exec.' '.optstr.' > '.temps.result

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

line 103why, one step back
103

[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0

line 104why, one step back
104 if s:tmux_enabled() && s:tmux_splittable(dict)

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 105–109why, one step back
105 return s:execute_tmux(dict, command, temps)
106 else107 return s:execute(dict, command, temps)108 endif109endfunction

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

line 110why, one step back
110

[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0

lines 111–116why, one step back
111function! s:tmux_splittable(dict)
112 return113 \ min([&columns, get(a:dict, 'tmux_width', 0)]) >= s:min_tmux_width ||114 \ min([&lines, get(a:dict, 'tmux_height', get(a:dict, 'tmux', 0))]) >= s:min_tmux_height115endfunction116

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

line 117why, one step back
117function! s:pushd(dict)

[vim] Ignore 'dir' option if emptyJunegunn Choibefore adoption6fd6fff

line 118why, one step back
118 if !empty(get(a:dict, 'dir', ''))

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 119–122why, one step back
119 let a:dict.prev_dir = getcwd()
120 execute 'chdir '.s:escape(a:dict.dir)121 endif122endfunction

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

line 123why, one step back
123

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 124–132why, one step back
124function! s:popd(dict)
125 if has_key(a:dict, 'prev_dir')126 execute 'chdir '.s:escape(remove(a:dict, 'prev_dir'))127 endif128endfunction129130function! s:execute(dict, command, temps)131 call s:pushd(a:dict)132 silent !clear

[vim] Enable fzf in GVim using xtermJunegunn Choibefore adoption0b43f98

line 133why, one step back
133 if has('gui_running')

[vim] External terminal emulator for GVimJunegunn Choibefore adoption4a3a5ee

lines 134–135why, one step back
134 let launcher = get(a:dict, 'launcher', get(g:, 'fzf_launcher', s:launcher))
135 let command = printf(launcher, "'".substitute(a:command, "'", "'\"'\"'", 'g')."'")

[vim] Enable fzf in GVim using xtermJunegunn Choibefore adoption0b43f98

line 136why, one step back
136 else

[vim] External terminal emulator for GVimJunegunn Choibefore adoption4a3a5ee

line 137why, one step back
137 let command = a:command

[vim] Enable fzf in GVim using xtermJunegunn Choibefore adoption0b43f98

line 138why, one step back
138 endif

[vim] External terminal emulator for GVimJunegunn Choibefore adoption4a3a5ee

line 139why, one step back
139 execute 'silent !'.command

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 140–141why, one step back
140 redraw!
141 if v:shell_error

[vim] Do not print error message on exit status 1Junegunn Choibefore adoption89298a8

lines 142–146why, one step back
142 " Do not print error message on exit status 1
143 if v:shell_error > 1144 echohl ErrorMsg145 echo 'Error running ' . command146 endif

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 147–152why, one step back
147 return []
148 else149 return s:callback(a:dict, a:temps, 0)150 endif151endfunction152

[vim] Apply FZF_DEFAULT_{OPTS,COMMAND} when using tmux splits (#87)Junegunn Choibefore adoption1e07b3b

lines 153–160why, one step back
153function! s:env_var(name)
154 if exists('$'.a:name)155 return a:name . "='". substitute(expand('$'.a:name), "'", "'\\\\''", 'g') . "' "156 else157 return ''158 endif159endfunction160

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

line 161why, one step back
161function! s:execute_tmux(dict, command, temps)

[vim] Apply FZF_DEFAULT_{OPTS,COMMAND} when using tmux splits (#87)Junegunn Choibefore adoption1e07b3b

line 162why, one step back
162 let command = s:env_var('FZF_DEFAULT_OPTS').s:env_var('FZF_DEFAULT_COMMAND').a:command

[vim] Ignore 'dir' option if emptyJunegunn Choibefore adoption6fd6fff

line 163why, one step back
163 if !empty(get(a:dict, 'dir', ''))

[vim] Apply FZF_DEFAULT_{OPTS,COMMAND} when using tmux splits (#87)Junegunn Choibefore adoption1e07b3b

line 164why, one step back
164 let command = 'cd '.s:escape(a:dict.dir).' && '.command

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

line 165why, one step back
165 endif

Allow setting tmux split height in %Junegunn Choibefore adoptioncf8dbf8

line 166why, one step back
166

[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0

lines 167–170why, one step back
167 let splitopt = '-v'
168 if has_key(a:dict, 'tmux_width')169 let splitopt = '-h'170 let size = a:dict.tmux_width

Allow setting tmux split height in %Junegunn Choibefore adoptioncf8dbf8

line 171why, one step back
171 else

[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0

line 172why, one step back
172 let size = get(a:dict, 'tmux_height', get(a:dict, 'tmux'))

Allow setting tmux split height in %Junegunn Choibefore adoptioncf8dbf8

lines 173–174why, one step back
173 endif
174

[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0

lines 175–180why, one step back
175 if type(size) == 1 && size =~ '%$'
176 let sizeopt = '-p '.size[0:-2]177 else178 let sizeopt = '-l '.size179 endif180

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 181–183why, one step back
181 let s:pane = substitute(
182 \ system(183 \ printf(

[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0

lines 184–185why, one step back
184 \ 'tmux split-window %s %s -P -F "#{pane_id}" %s',
185 \ splitopt, sizeopt, s:shellesc(command))), '\n', '', 'g')

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 186–215why, one step back
186 let s:dict = a:dict
187 let s:temps = a:temps188189 augroup fzf_tmux190 autocmd!191 autocmd VimResized * nested call s:tmux_check()192 augroup END193endfunction194195function! s:tmux_check()196 let panes = split(system('tmux list-panes -a -F "#{pane_id}"'), '\n')197198 if index(panes, s:pane) < 0199 augroup fzf_tmux200 autocmd!201 augroup END202203 call s:callback(s:dict, s:temps, 1)204 redraw205 endif206endfunction207208function! s:callback(dict, temps, cd)209 if !filereadable(a:temps.result)210 let lines = []211 else212 if a:cd | call s:pushd(a:dict) | endif213214 let lines = readfile(a:temps.result)215 if has_key(a:dict, 'sink')

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

line 216why, one step back
216 for line in lines

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 217–218why, one step back
217 if type(a:dict.sink) == 2
218 call a:dict.sink(line)

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

line 219why, one step back
219 else

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

line 220why, one step back
220 execute a:dict.sink.' '.s:escape(line)

Fix install script (source ~/.xxxrc has no effect)Junegunn Choibefore adoption64541cb

lines 221–223why, one step back
221 endif
222 endfor223 endif

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 224–232why, one step back
224 endif
225226 for tf in values(a:temps)227 silent! call delete(tf)228 endfor229230 call s:popd(a:dict)231232 return lines

Fix install script (source ~/.xxxrc has no effect)Junegunn Choibefore adoption64541cb

lines 233–234why, one step back
233endfunction
234

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

line 235why, one step back
235function! s:cmd(bang, ...) abort

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

lines 236–240why, one step back
236 let args = copy(a:000)
237 let opts = {}238 if len(args) > 0 && isdirectory(expand(args[-1]))239 let opts.dir = remove(args, -1)240 endif

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

lines 241–243why, one step back
241 if !a:bang
242 let opts.tmux = get(g:, 'fzf_tmux_height', s:default_tmux_height)243 endif

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

lines 244–246why, one step back
244 call fzf#run(extend({ 'sink': 'e', 'options': join(args) }, opts))
245endfunction246

Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665

line 247why, one step back
247command! -nargs=* -complete=dir -bang FZF call s:cmd('<bang>' == '!', <f-args>)

Major update to Vim pluginJunegunn Choibefore adoptione7439ce

lines 248–250why, one step back
248
249let &cpo = s:cpo_save250unlet s:cpo_save

Fix install script (source ~/.xxxrc has no effect)Junegunn Choibefore adoption64541cb

line 251why, one step back
251