1

I'm working on Open::This, which provides a command line utility that acts as a wrapper around vim, emacs and nano. The utility is called ot. It does things like translating ot lib/Foo/Bar.pm:99 into vim +99 lib/Foo/Bar.pm.

What I'd like to be able to do is translate ot lib/Foo/Bar.pm:99:50 into a vim command which will open lib/Foo/Bar.pm at line 99 and column 50. Is this possible to do without using a vim plugin?

To sum up, I know the command line syntax to open a file at an arbitrary line. Is it possible to do this and move the cursor to an arbitrary column at the same time?

1

You can have vim execute arbitrary commands (i.e., not just a line number) after loading the first file on the command line using +'{cmd}' or -c '{cmd}'. This is documented in vim's man page. For example, to load file Foo/Bar.pm then go to line 99, column 50, you can use:

vim +'call cursor(99,50)' Foo/Bar.pm

Note that this uses byte position for the column number, starting from one. If your file has multi-byte characters and you wish to use vim's understanding of column numbers instead, you can instead do:

vim +'normal! 99G50|' Foo/Bar.pm

This uses the normal commands G for go-to line and | meaning go to screen column (starting at one).

Which to use depends on how your tool emits column numbers.

0

You can do it like this:

vim -c "call cursor(19, 11)" .bashrc

This opens .bashrc and puts the cursor on line 19, column 11.

Note that <TAB> is one character!

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.