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 fileTake 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 back1" Copyright (c) 2015 Junegunn ChoiFix install script (source ~/.xxxrc has no effect)Junegunn Choibefore adoption64541cb
lines 2–23why, one step back2"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 back24let s:min_tmux_width = 10Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
line 25why, one step back25let s:min_tmux_height = 3Allow setting tmux split height in %Junegunn Choibefore adoptioncf8dbf8
line 26why, one step back26let s:default_tmux_height = '40%'[vim] External terminal emulator for GVimJunegunn Choibefore adoption4a3a5ee
line 27why, one step back27let s:launcher = 'xterm -e bash -ic %s'Merge pull request #116 from junegunn/goJunegunn Choibefore adoption209a6d3
line 28why, one step back28let s:fzf_go = expand('<sfile>:h:h').'/bin/fzf'[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18
line 29why, one step back29let s:fzf_rb = expand('<sfile>:h:h').'/fzf'Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
line 30why, one step back30Major update to Vim pluginJunegunn Choibefore adoptione7439ce
lines 31–33why, one step back31let s:cpo_save = &cpo32set cpo&vim33[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18
lines 34–37why, one step back34function! s:fzf_exec()35 if !exists('s:exec')36 call system('type fzf')37 if v:shell_errorMerge pull request #116 from junegunn/goJunegunn Choibefore adoption209a6d3
lines 38–39why, one step back38 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 back40 else41 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 back47 else[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18
line 48why, one step back48 return s:execPrefer pre-existing function/alias in Vim pluginJunegunn Choibefore adoptionb8e438b
line 49why, one step back49 endif[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18
line 50why, one step back50endfunctionFix install script (source ~/.xxxrc has no effect)Junegunn Choibefore adoption64541cb
line 51why, one step back51Vim plugin: do not enable tmux-integration if version < 1.7Junegunn Choibefore adoptionaf677e7
line 52why, one step back52function! s:tmux_enabled()[vim] Enable fzf in GVim using xtermJunegunn Choibefore adoption0b43f98
lines 53–56why, one step back53 if has('gui_running')54 return 055 endif56Vim plugin: do not enable tmux-integration if version < 1.7Junegunn Choibefore adoptionaf677e7
lines 57–68why, one step back57 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:tmux67endfunction68Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 69–72why, one step back69function! s:shellesc(arg)70 return '"'.substitute(a:arg, '"', '\\"', 'g').'"'71endfunction72Update Vim plugin to take path argumentJunegunn Choibefore adoptionf282741
lines 73–76why, one step back73function! s:escape(path)74 return substitute(a:path, ' ', '\\ ', 'g')75endfunction76Major update to Vim pluginJunegunn Choibefore adoptione7439ce
lines 77–78why, one step back77function! fzf#run(...) abort78 let dict = exists('a:1') ? a:1 : {}Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
line 79why, one step back79 let temps = { 'result': tempname() }Major update to Vim pluginJunegunn Choibefore adoptione7439ce
line 80why, one step back80 let optstr = get(dict, 'options', '')[vim] Defer `type fzf` to reduce startup timeJunegunn Choibefore adoption3e91c18
lines 81–85why, one step back81 try82 let fzf_exec = s:fzf_exec()83 catch84 throw v:exception85 endtryMajor update to Vim pluginJunegunn Choibefore adoptione7439ce
lines 86–92why, one step back8687 if has_key(dict, 'source')88 let source = dict.source89 let type = type(source)90 if type == 191 let prefix = source.'|'92 elseif type == 3Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 93–95why, one step back93 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 back96 else97 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 back102 let command = prefix.fzf_exec.' '.optstr.' > '.temps.resultMajor update to Vim pluginJunegunn Choibefore adoptione7439ce
line 103why, one step back103[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0
line 104why, one step back104 if s:tmux_enabled() && s:tmux_splittable(dict)Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 105–109why, one step back105 return s:execute_tmux(dict, command, temps)106 else107 return s:execute(dict, command, temps)108 endif109endfunctionMajor update to Vim pluginJunegunn Choibefore adoptione7439ce
line 110why, one step back110[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0
lines 111–116why, one step back111function! 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_height115endfunction116Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
line 117why, one step back117function! s:pushd(dict)[vim] Ignore 'dir' option if emptyJunegunn Choibefore adoption6fd6fff
line 118why, one step back118 if !empty(get(a:dict, 'dir', ''))Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 119–122why, one step back119 let a:dict.prev_dir = getcwd()120 execute 'chdir '.s:escape(a:dict.dir)121 endif122endfunctionMajor update to Vim pluginJunegunn Choibefore adoptione7439ce
line 123why, one step back123Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 124–132why, one step back124function! 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 back133 if has('gui_running')[vim] External terminal emulator for GVimJunegunn Choibefore adoption4a3a5ee
lines 134–135why, one step back134 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 back136 else[vim] External terminal emulator for GVimJunegunn Choibefore adoption4a3a5ee
line 137why, one step back137 let command = a:command[vim] Enable fzf in GVim using xtermJunegunn Choibefore adoption0b43f98
line 138why, one step back138 endif[vim] External terminal emulator for GVimJunegunn Choibefore adoption4a3a5ee
line 139why, one step back139 execute 'silent !'.commandVim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 140–141why, one step back140 redraw!141 if v:shell_error[vim] Do not print error message on exit status 1Junegunn Choibefore adoption89298a8
lines 142–146why, one step back142 " Do not print error message on exit status 1143 if v:shell_error > 1144 echohl ErrorMsg145 echo 'Error running ' . command146 endifVim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 147–152why, one step back147 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 back153function! s:env_var(name)154 if exists('$'.a:name)155 return a:name . "='". substitute(expand('$'.a:name), "'", "'\\\\''", 'g') . "' "156 else157 return ''158 endif159endfunction160Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
line 161why, one step back161function! s:execute_tmux(dict, command, temps)[vim] Apply FZF_DEFAULT_{OPTS,COMMAND} when using tmux splits (#87)Junegunn Choibefore adoption1e07b3b
line 162why, one step back162 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 back163 if !empty(get(a:dict, 'dir', ''))[vim] Apply FZF_DEFAULT_{OPTS,COMMAND} when using tmux splits (#87)Junegunn Choibefore adoption1e07b3b
line 164why, one step back164 let command = 'cd '.s:escape(a:dict.dir).' && '.commandVim plugin: tmux integrationJunegunn Choibefore adoption2b34665
line 165why, one step back165 endifAllow setting tmux split height in %Junegunn Choibefore adoptioncf8dbf8
line 166why, one step back166[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0
lines 167–170why, one step back167 let splitopt = '-v'168 if has_key(a:dict, 'tmux_width')169 let splitopt = '-h'170 let size = a:dict.tmux_widthAllow setting tmux split height in %Junegunn Choibefore adoptioncf8dbf8
line 171why, one step back171 else[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0
line 172why, one step back172 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 back173 endif174[Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0
lines 175–180why, one step back175 if type(size) == 1 && size =~ '%$'176 let sizeopt = '-p '.size[0:-2]177 else178 let sizeopt = '-l '.size179 endif180Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 181–183why, one step back181 let s:pane = substitute(182 \ system(183 \ printf([Vim] Allow vertical split of tmux windowJunegunn Choibefore adoption16031b0
lines 184–185why, one step back184 \ '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 back186 let s:dict = a:dict187 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 back216 for line in linesVim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 217–218why, one step back217 if type(a:dict.sink) == 2218 call a:dict.sink(line)Major update to Vim pluginJunegunn Choibefore adoptione7439ce
line 219why, one step back219 elseVim plugin: tmux integrationJunegunn Choibefore adoption2b34665
line 220why, one step back220 execute a:dict.sink.' '.s:escape(line)Fix install script (source ~/.xxxrc has no effect)Junegunn Choibefore adoption64541cb
lines 221–223why, one step back221 endif222 endfor223 endifVim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 224–232why, one step back224 endif225226 for tf in values(a:temps)227 silent! call delete(tf)228 endfor229230 call s:popd(a:dict)231232 return linesFix install script (source ~/.xxxrc has no effect)Junegunn Choibefore adoption64541cb
lines 233–234why, one step back233endfunction234Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
line 235why, one step back235function! s:cmd(bang, ...) abortMajor update to Vim pluginJunegunn Choibefore adoptione7439ce
lines 236–240why, one step back236 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 endifVim plugin: tmux integrationJunegunn Choibefore adoption2b34665
lines 241–243why, one step back241 if !a:bang242 let opts.tmux = get(g:, 'fzf_tmux_height', s:default_tmux_height)243 endifMajor update to Vim pluginJunegunn Choibefore adoptione7439ce
lines 244–246why, one step back244 call fzf#run(extend({ 'sink': 'e', 'options': join(args) }, opts))245endfunction246Vim plugin: tmux integrationJunegunn Choibefore adoption2b34665
line 247why, one step back247command! -nargs=* -complete=dir -bang FZF call s:cmd('<bang>' == '!', <f-args>)Major update to Vim pluginJunegunn Choibefore adoptione7439ce
lines 248–250why, one step back248249let &cpo = s:cpo_save250unlet s:cpo_saveFix install script (source ~/.xxxrc has no effect)Junegunn Choibefore adoption64541cb
line 251why, one step back251