简体   繁体   中英

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:

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:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM