Skip to content

fzf to open vim makes my terminal wacky

Just trying to use fzf to open files to edit with vim....

fzf | xargs -0 -r vim

opens the file correctly, but once I exit vim my term is stuck in some kind of loop where I can't type anything. All I can do is press enter and it returns a new prompt on the same line... over and over again. What am I missing here?

1 points4 comments
Open on Reddit
About this post
Posted
Archived
Score
1 · 100% up
Kind
Text
ID
ced6ck

Author

58
posts
386
comments
5
media
View profile

4 comments

This is because vim's stdin (standard input) is not your keyboard like it should be, but whatever stdin xargs gives to it, which isn't the keyboard too since xargs's stdin is fzf's stdout.

The invalid state of the terminal can be fixed by running tput reset, which resets all temporary settings a terminal might have - including show/hide the cursor, write/discard characters you type on the screen, etc.

I think that doing vim $(fzf) might be a better approach compared to yours - or any other approach that doesn't involve hijacking vim's stdin.

3 points

Thank you! vim $(fzf) works well and I understand the issue with the other approach.

1 points

Use fzf.vim which is a vim plugin and does what you want better with less surprises :)

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.