From 853012ceef7c8e8e28e6cbb6c790f76956a62b03 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 15 Apr 2015 22:49:45 +0900 Subject: [PATCH] [vim] Add g:fzf_action for customizing key bindings Close #189 --- README.md | 27 +++++---------------------- plugin/fzf.vim | 15 +++++++++------ 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index c0dd8cd..3337093 100644 --- a/README.md +++ b/README.md @@ -276,34 +276,17 @@ If you have set up fzf for Vim, `:FZF` command will be added. " With options :FZF --no-sort -m /tmp + +" Bang version starts in fullscreen instead of using tmux pane or Neovim split +:FZF! ``` Similarly to [ctrlp.vim](https://github.com/kien/ctrlp.vim), use enter key, `CTRL-T`, `CTRL-X` or `CTRL-V` to open selected files in the current window, in new tabs, in horizontal splits, or in vertical splits respectively. -Note that the environment variables `FZF_DEFAULT_COMMAND` and `FZF_DEFAULT_OPTS` -also apply here. - -If you're on a tmux session or using Neovim, `:FZF` will launch fzf in a -split-window whose height can be adjusted with `g:fzf_height` (default: -'40%'). However, the bang version (`:FZF!`) will always start in fullscreen. - -In GVim, you need an external terminal emulator to start fzf with. `xterm` -command is used by default, but you can customize it with `g:fzf_launcher`. - -```vim -" This is the default. %s is replaced with fzf command -let g:fzf_launcher = 'xterm -e bash -ic %s' - -" Use urxvt instead -let g:fzf_launcher = 'urxvt -geometry 120x30 -e sh -c %s' -``` - -If you're running MacVim on OSX, I recommend you to use iTerm2 as the launcher. -Refer to the [this wiki -page](https://github.com/junegunn/fzf/wiki/On-MacVim-with-iTerm2) to see how -to set up. +Note that the environment variables `FZF_DEFAULT_COMMAND` and +`FZF_DEFAULT_OPTS` also apply here. #### `fzf#run([options])` diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 063bc2e..99aa300 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -308,23 +308,26 @@ function! s:callback(dict, temps) return lines endfunction +let s:default_action = { + \ 'ctrl-m': 'e', + \ 'ctrl-t': 'tabedit', + \ 'ctrl-x': 'split', + \ 'ctrl-v': 'vsplit' } + function! s:cmd_callback(lines) abort if empty(a:lines) return endif let key = remove(a:lines, 0) - if key == 'ctrl-t' | let cmd = 'tabedit' - elseif key == 'ctrl-x' | let cmd = 'split' - elseif key == 'ctrl-v' | let cmd = 'vsplit' - else | let cmd = 'e' - endif + let cmd = get(s:action, key, 'e') for item in a:lines execute cmd s:escape(item) endfor endfunction function! s:cmd(bang, ...) abort - let args = extend(['--expect=ctrl-t,ctrl-x,ctrl-v'], a:000) + let s:action = get(g:, 'fzf_action', s:default_action) + let args = extend(['--expect='.join(keys(s:action), ',')], a:000) let opts = {} if len(args) > 0 && isdirectory(expand(args[-1])) let opts.dir = remove(args, -1)