Skip to main content
2 of 5
added 633 characters in body
B Layer
  • 20.1k
  • 2
  • 32
  • 59

With native Vim there's no pretty way to do it. You'll have to submit a couple Ex commands using the -c or + command-line flag:

vim +123 ~/.zshrc -c 'e ~/.profile | 10'

That is, after startup the command :e ~/.profile will open ~/.profile and the next command :10 will take you to line 10.

If you don't mind installing a plugin you can use vim-fetch which allows a command line like:

vim ~/.zshrc:123 ~/.profile:10

(Just tested it out and it works fine.)

Before I found that plugin I had whipped up a wrapper script that uses the same parameter format. You'd call it instead of Vim. (Or you could name it vim and put it in your PATH ahead of Vim itself...but I don't recommend that.) I'm posting it just in case anyone's interested:

#!/bin/bash

for arg; do
    # If an existing, regular file is followed by ':' and a number...
    if [[ $arg =~ ^[^:]*:[[:digit:]]+$ && -f ${arg%%:*} ]]; then
        cmds+=(-c "e ${arg%%:*} | ${arg##*:}")
    else
        other+=($arg)
    fi
done

/bin/vim "${other[@]}" "${cmds[@]}" -c first

This was just a quick thing I did for fun so I'm sure it's not 100% bulletproof...caveat emptor. :)

B Layer
  • 20.1k
  • 2
  • 32
  • 59