0

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.

zheyuanWang
  • 1,158
  • 2
  • 16
  • 30

1 Answers1

1

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.

mattb
  • 2,787
  • 2
  • 6
  • 20
  • Also see [here](https://stackoverflow.com/a/64416946/14467607) and [here](https://stackoverflow.com/a/67019648/14467607) for a couple of answers of mine that might interest you if decide to go down the fzf route. – mattb Nov 01 '21 at 11:38
  • Great answer! add a tip for rookie vim users like me: type `:n` to go to the next opened file ; ) – zheyuanWang Nov 02 '21 at 11:26