How to a open a file in vim using pipe

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`

In addition to the above answer, to avoid the "terminal corruption" stated by Jacobo de Vera in the comment, use the xargs option -o or --open-tty to make vim assume the input is from a terminal, not stdin.

$ locate updatedb | head -1 | xargs -o vim

See: https://unix.stackexchange.com/a/44428/307359