Is it possible to open a file to a specific line number as formatted in grep -n results?
Well, it's not an alias, you can use vim like this:
vim +<LineNumberHere> fileName
So, for example
vim +150 .bash_history
opens your .bash_history file (for bash), and navigates to line 150.
Incidentally, you can also do this with search terms. For example
vim +/MyTerm MyFile
opens MyFile and navigates to the first occurrence of MyTerm from the top.
Enjoy!
One solution to this is to use the file_line.vim plugin, which lets you specify a file name and line number as an argument to Vim or on Vim's command line, just as you've shown.
Another is this script,
$ cat $(which vimgrep)
#!/bin/bash
tmp=$(mktemp)
cat > $tmp
exec < /dev/tty
vim --cmd 'let &efm=&gfm' -q $tmp "$@"
rm $tmp
which can be used like this:
$ grep -Hn xyz .* | vimgrep
and which loads all the matches into Vim's quickfix error list. See
:help quickfix.txt
Note the -H
option to grep to ensure that the file name is included in grep's output even if .*
expands to only one file name.