how to choose one file from similiar files in terminal (via tmux)

0

Issue

There are some txt files under a folder

log_train_20211029-134139.txt  log_train_20211029-134156.txt  log_train_20211029-134241.txt  log_train_20211029-155517.txt  log_train_20211029-155754.txt  log_train_20211029-155832.txt  log_train_20211101-142937.txt  

They have similar names. When I want to open and check them one by one, I have to choose a valid number from the list given by TAB key many times.

vim log_train_20211
(press TAB)

vim log_train_20211029-1
(press TAB)

vim log_train_20211029-155
(press TAB, looking for a valid number...)

vim log_train_20211029-155832.txt 

This process is too annoying. It there any method that I could quickly open one of the files from terminal?

Ps. I am using Terminator. Sometimes work with tmux.

Solution

FZF

You could give fzf (a fuzzy finder) a look. Then you could do vim $(fzf) and quickly hone in on the file of interest. It works great both in the terminal (tmux or no tmux) and in vim (there is a vim plugin to make it a seamless part of vim).

Terminal only

Another way, not relying on installing fzf, would be to use wildcards to pin down the file: vim log*2021*-1*32.txt would open any file with the parts between the *s, if the parts appear in the same order. Therefore if you choose the identifying parts to be unique to the file you want, you can skip over the non-unique parts.

Whether this is faster than autocomplete depends on how similar your file names are and how many there are to choose from and if you know ahead of time (i.e. without scanning through all the options during the autocomplete process) which file you want to open.

Answered By – mattb

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More