How to a open a file in vim using pipe

I get to use the locate command extremely often.

So if I run the following command.

locate updatedb | head -1

Then it gives me the O/p

/usr/updatedb.conf

I wonder if there is any such command that can let me open that file directly?

I am hoping for something like this.

locate updatedb | head -1 | vim

You're nearly done:

$ locate updatedb | head -1 | xargs vim

sometimes (under certain terminals) you need reset the terminal after editing.

$ reset

As an interactive editor, Vim needs both stdin and stdout, so using it within a pipe is problematic and makes Vim warn about this. For just a single file, process substitution solves this easily:

vim "$(locate updatedb | head -1)"

You can also use backticks, and that even works inside Vim itself:

:edit `locate updatedb | head -1`