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:
Vim can display line numbers in the left margin: Press ESC key. At the : prompt type the following command to run on line numbers: set number. To turn off line numbering, type the following command at the : prompt set nonumber.
Press the Esc key if you are currently in insert or append mode. Press : (the colon). The cursor should reappear at the lower left corner of the screen next to a : prompt. A column of sequential line numbers will then appear at the left side of the screen.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With