kev
kev

Reputation: 161674

How to config vim to open a filename which contains line and column number?

It's usefull, when debug a program.

# compile file
$ g++ -Wall main.cpp
main.cpp:42:7: warning: backslash and newline separated by space

# I do this to locate
$ vim main.cpp +42 +'normal 7|'

# how to do this?
$ vim main.cpp:42:7:

Upvotes: 8

Views: 574

Answers (3)

cutalion
cutalion

Reputation: 4394

Check out file:line plugin also. It will open file and set cursor position to specified line and column.

Works with trailing colon:

vim file.cpp:10
vim file.cpp:10:
vim file.cpp:10:4
vim file.cpp:10:4:

Upvotes: 9

Adam Liss
Adam Liss

Reputation: 48290

Look at the "quickfix" features of vim: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#quickfix

You can compile from within vim (see vim's makeprg and errorformat variables), and then automatically jump to the lines that generate errors using :cc, :cp, and :cn.

The same vimdoc shows you how to jump quickly to the beginning or end of the current function or block of code, and if you use ctags you can also locate the definitions of functions and variables.

Upvotes: 3

strcat
strcat

Reputation: 5622

vim actually has a whole set of built-in commands and options for this.

You get the documentation with

:help quickfix

For example

:set makeprg=g++\ -Wall\ main.cc " the default is make
:make

will parse the errors and warnings output by g++ and let you cycle through the locations.

Upvotes: 4

Related Questions