6

Using gF I can jump to a file with the format foobar.py:27:6 to open foobar.py on line 27. My question is how I can make this jump in vimscript?

For example, this won't work:

execute "normal gF " . foobar.py:27:6

because gF doesn't take an argument - it uses the word under the cursor - but hopefully this gives an impression of what I'm trying to do.

7

If you don't care about the column, and as an example you have the linenumber and filename in variables, you could do this:

execute "edit +" . linenumber . " " . filename

Or, as from your example

execute "edit +27 foobar.py"

To expand the colon separation and then edit would look like this:

let fileLine="foobar.py:27"
let filename=split(fileLine,":")[0]
let linenumber=split(fileLine,":")[1]
execute "edit +" . linenumber . " " . filename

I'm hard coding the value of fileLine there, but you could obtain it however you like. I'm ignoring the column for simplicity and because you only mentioned jumping to the line in your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.