vim 里打开 file:line
0x00
Linux 里,很多工具都会按文件加行号(file:line
)的格式输出,比如 grep
:
$ grep -nr "Sanitize in progress..."
drivers/mmc/core/mmc_ops.c:1008: pr_debug("%s: Sanitize in progress...\n", mmc_hostname(host));
又比如 Linux 动态打印里的:
# cd /sys/kernel/debug/dynamic_debug
# cat control | egrep '^init'
init/main.c:1426 [main]run_init_process =p " %s\012"
init/main.c:1424 [main]run_init_process =p " with environment:\012"
init/main.c:1423 [main]run_init_process =p " %s\012"
init/main.c:1421 [main]run_init_process =p " with arguments:\012"
init/main.c:1211 [main]initcall_blacklisted =p "initcall %s blacklisted\012"
init/main.c:1172 [main]initcall_blacklist =p "blacklisting initcall %s\012"
或者 gdb 里显示 backtrace 调用栈的时候:
#0 test (obs=0x24eb0, argc=1, argv=0x2b8c8)
at builtin.c:993
#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
at macro.c:71
(More stack frames follow...)
0x01
vim 可以有打开文件并定位到某一行的功能:
$ vim --help
...
+ Start at end of file
+<lnum> Start at line <lnum>
...
比如:
vim +27 foobar.py
0x02
如何直接打开前面的 file:line
呢?找到一个插件:https://github.com/bogado/file-line , 可以实现这个操作。比如,启用插件后,可以这样操作:
vim index.html:20
vim app/models/user.rb:1337
这样从 grep 等各种输出里,可以直接拷贝,然后在 vim 里打开并跳转到指定行。