The simplest way is to pass locate as shell substitution, like:
vim $(locate filename123)
You can also consider to use find instead of locate to pass file names to edit, in example:
find . -name 'filename123' -exec vim {} +
On Unix/OSX you can use xargs with -o parameter, like:
locate filename123 | xargs -o vim
-oReopen stdin as /dev/tty in the child process before executing the command. This is useful if you want xargs to run an interactive application.
Or on Linux try the following workaround using:
locate filename123 | xargs -J% sh -c 'vim < /dev/tty $@'
If you're using different commands, use command substitution to achieve that, like:
vim $(locate filename123)
vim `locate filename123`
Alternatively use GNU parallel instead of xargs to force tty allocation, in example:
locate filename123 | parallel -X --tty vi
Note: parallelon Unix/OSX won't work as it has different parameters and it doesn't support tty.
Many other popular commands provides pseudo-tty allocation as well (like -t in ssh), so check for help.
Other suggestion would be to use vipe (a Vim command pipe) or use the following simple script:
#!/bin/sh
# usage: locate filename123 | vip
exec vim < /dev/tty "$@"
Related: