Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fzf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
fzf
Commits
7ee6fd1f
Commit
7ee6fd1f
authored
11 years ago
by
Junegunn Choi
Browse files
Options
Downloads
Patches
Plain Diff
Make install script to add key bindings as well
parent
2dca6f0c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+20
-7
20 additions, 7 deletions
README.md
install
+77
-0
77 additions, 0 deletions
install
with
97 additions
and
7 deletions
README.md
+
20
−
7
View file @
7ee6fd1f
...
...
@@ -153,8 +153,8 @@ Most of the time, you will prefer native Vim plugins with better integration
with Vim. The only reason one might consider using fzf in Vim is its speed. For
a very large list of files, fzf is significantly faster and it does not block.
Useful
bash
examples
---------------
-----
Useful examples
---------------
```
sh
# vimf - Open selected file in Vim
...
...
@@ -183,8 +183,16 @@ fkill() {
}
```
bash key bindings
-----------------
Key bindings
------------
The install script will add the following key bindings to your configuration
files.
### bash
-
`CTRL-T`
- Paste the selected file path(s) into the command line
-
`CTRL-R`
- Paste the selected command from history into the command line
```
sh
# Required to refresh the prompt after fzf
...
...
@@ -192,7 +200,9 @@ bind '"\er": redraw-current-line'
# CTRL-T - Paste the selected file path into the command line
fsel
()
{
find
${
1
:-
*
}
| fzf
-m
|
while
read
item
;
do
find
*
-path
'*/\.*'
-prune
\
-o
-type
f
-print
\
-o
-type
l
-print
2> /dev/null | fzf
-m
|
while
read
item
;
do
printf
'%q '
"
$item
"
done
echo
...
...
@@ -203,8 +213,11 @@ bind '"\C-t": " \C-u \C-a\C-k$(fsel)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er"'
bind
'"\C-r": " \C-e\C-u$(history | fzf +s | sed \"s/ *[0-9]* *//\")\e\C-e\er"'
```
zsh widgets
-----------
### zsh
-
`CTRL-T`
- Paste the selected file path(s) into the command line
-
`CTRL-R`
- Paste the selected command from history into the command line
-
`ALT-C`
- cd into the selected directory
```
sh
# CTRL-T - Paste the selected file path(s) into the command line
...
...
This diff is collapsed.
Click to expand it.
install
+
77
−
0
View file @
7ee6fd1f
...
...
@@ -38,6 +38,12 @@ echo
[[
!
$REPLY
=
~ ^[Nn]
$
]]
auto_completion
=
$?
# Key-bindings
read
-p
"Do you want to add key bindings? ([y]/n) "
-n
1
-r
echo
[[
!
$REPLY
=
~ ^[Nn]
$
]]
key_bindings
=
$?
echo
for
shell
in
bash zsh
;
do
echo
-n
"Generate ~/.fzf.
$shell
... "
...
...
@@ -49,14 +55,85 @@ for shell in bash zsh; do
fi
cat
>
$src
<<
EOF
# Setup fzf function
# ------------------
unalias fzf 2> /dev/null
fzf() {
$fzf_cmd
"
\$
@"
}
export -f fzf > /dev/null
# Auto-completion
# ---------------
$fzf_completion
EOF
if
[
$key_bindings
-eq
0
]
;
then
if
[
$shell
=
bash
]
;
then
cat
>>
$src
<<
"
EOF
"
# Key bindings
# ------------
# Required to refresh the prompt after fzf
bind '"
\e
r": redraw-current-line'
# CTRL-T - Paste the selected file path into the command line
fsel() {
find * -path '*/
\.
*' -prune
\
-o -type f -print
\
-o -type l -print 2> /dev/null | fzf -m | while read item; do
printf '%q ' "
$item
"
done
echo
}
bind '"
\C
-t": "
\C
-u
\C
-a
\C
-k
$(
fsel
)
\e\C
-e
\C
-y
\C
-a
\C
-y
\e
y
\C
-h
\C
-e
\e
r"'
# CTRL-R - Paste the selected command from history into the command line
bind '"
\C
-r": "
\C
-e
\C
-u
$(
history
| fzf +s |
sed
\"
s/
*
[
0-9]
*
*
//
\"
)
\e\C
-e
\e
r"'
EOF
else
cat
>>
$src
<<
"
EOF
"
# Key bindings
# ------------
# CTRL-T - Paste the selected file path(s) into the command line
fzf-file-widget() {
local FILES
local IFS="
"
FILES=(
$(
find
*
-path
'*/\.*'
-prune
\
-o
-type
f
-print
\
-o
-type
l
-print
2> /dev/null | fzf
-m
)
)
unset IFS
FILES=
$FILES
:q
LBUFFER="
${
LBUFFER
%% #
}
$FILES
"
zle redisplay
}
zle -N fzf-file-widget
bindkey '^T' fzf-file-widget
# ALT-C - cd into the selected directory
fzf-cd-widget() {
cd "
${
$(
find
*
-path
'*/\.*'
-prune
\
-o
-type
d
-print
2> /dev/null | fzf
)
:-
.
}
"
zle reset-prompt
}
zle -N fzf-cd-widget
bindkey '
\e
c' fzf-cd-widget
# CTRL-R - Paste the selected command from history into the command line
fzf-history-widget() {
LBUFFER=
$(
history
| fzf +s |
sed
"s/ *[0-9]* *//"
)
zle redisplay
}
zle -N fzf-history-widget
bindkey '^R' fzf-history-widget
EOF
fi
fi
echo
"OK"
done
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment