Skip to main content
Mention use of -first ... plus a number of minor changes.
Source Link
B Layer
  • 20.1k
  • 2
  • 32
  • 59

Native

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.

You can, of course, do this with as many files as you'd like.

One thing worth noting is that after startup the current buffer will be the last one specified on the command line rather than the first as is normally the case. As a workaround you can add -c first to the end of the command line (as is done in the wrapper script, below). For example:

vim foo.txt +10 -c 'e bar.txt | 20' -c 'e baz.txt | 30' -c first

The current buffer in this case will be foo.txt (with the cursor on line 10).

Plugin

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

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

It works but it's a little wonky, IMOin my opinion. It seems that it loads a (non-existent) file named, for example, ~/zshrc:123 and only upon navigating to that buffer does the plugin parse out the line number and load the actual file. You may or may not notice this happening. (I noticed it because I saw the temporary file:line name in my tab line.)

Wrapper

Before I found that plugin I had whipped up a wrapper script for Vim that uses the same parameter format. You'd call it instead of VimThe script name is substituted for vim. (If you really wanted to you could name it vim and put it in your PATH ahead of Vim itself.) 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 funthis quickly as a little Bash exercise so I'm sure it'sit may not 100% bulletproofwork perfectly for every conceivable set of command line arguments...caveat emptor. :)

Native

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.

Plugin

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

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

It works but it's a little wonky, IMO. It seems that it loads a (non-existent) file named, for example, ~/zshrc:123 and only upon navigating to that buffer does the plugin parse out the line number and load the actual file. You may or may not notice this happening. (I noticed it because I saw the temporary file:line name in my tab line.)

Wrapper

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. (If you really wanted to you could name it vim and put it in your PATH ahead of Vim itself.) 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. :)

Native

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.

You can, of course, do this with as many files as you'd like.

One thing worth noting is that after startup the current buffer will be the last one specified on the command line rather than the first as is normally the case. As a workaround you can add -c first to the end of the command line (as is done in the wrapper script, below). For example:

vim foo.txt +10 -c 'e bar.txt | 20' -c 'e baz.txt | 30' -c first

The current buffer in this case will be foo.txt (with the cursor on line 10).

Plugin

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

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

It works but it's a little wonky, in my opinion. It seems that it loads a (non-existent) file named, for example, ~/zshrc:123 and only upon navigating to that buffer does the plugin parse out the line number and load the actual file. You may or may not notice this happening. (I noticed it because I saw the temporary file:line name in my tab line.)

Wrapper

Before I found that plugin I had whipped up a wrapper script for Vim that uses the same parameter format. The script name is substituted for vim. (If you really wanted to you could name it vim and put it in your PATH ahead of Vim itself.) 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

I did this quickly as a little Bash exercise so it may not work perfectly for every conceivable set of command line arguments...caveat emptor. :)

Add opinion of plugin and some headers
Source Link
B Layer
  • 20.1k
  • 2
  • 32
  • 59

Native

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.

Plugin

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 works but it's a little wonky, IMO. It seems that it loads a (non-existent) file named, for example, ~/zshrc:123 and only upon navigating to that buffer does the plugin parse out the line number and load the actual file. You may or may not notice this happening. (I noticed it works finebecause I saw the temporary file:line name in my tab line.)

Wrapper

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. (If you really wanted to you could name it vim and put it in your PATH ahead of Vim itself.) 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. :)

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. (If you really wanted to you could name it vim and put it in your PATH ahead of Vim itself.) 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. :)

Native

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.

Plugin

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

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

It works but it's a little wonky, IMO. It seems that it loads a (non-existent) file named, for example, ~/zshrc:123 and only upon navigating to that buffer does the plugin parse out the line number and load the actual file. You may or may not notice this happening. (I noticed it because I saw the temporary file:line name in my tab line.)

Wrapper

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. (If you really wanted to you could name it vim and put it in your PATH ahead of Vim itself.) 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. :)

deleted 3 characters in body
Source Link
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. (OrIf you really wanted to 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. :)

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. :)

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. (If you really wanted to you could name it vim and put it in your PATH ahead of Vim itself.) 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. :)

added 633 characters in body
Source Link
B Layer
  • 20.1k
  • 2
  • 32
  • 59
Loading
Source Link
B Layer
  • 20.1k
  • 2
  • 32
  • 59
Loading