VIM:执行复杂文件类型的脚本和显示结果
VIM: Execute script and display result for complex file type
我有一个自定义的非常复杂的文件格式。这种格式可以通过 bash 脚本解析为人类可读的(最终调用 c++ 程序来实际解析它(。
我该怎么办,以便在 vim 尝试读取此文件时,而不是简单地打开它,它应该首先调用此脚本,然后显示其结果而不是文件的内容
将此添加到您的 vimrc 文件中:
autocmd BufRead *.yourext call ParseMyComplexFile() " When reading your complex files
function ParseMyComplexFile()
let l:fname = expand('%:t') " Copy current file name to l:fname
enew " Open new empty buffer in place of current one
setlocal buftype=nofile " (scratch buffer) New buffer is not related to a file and will not be written
setlocal bufhidden=hide " (scratch buffer) Don't unload the buffer when it is hidden
setlocal noswapfile " (scratch buffer) No swap file for this buffer
" Execute your script on the file and change the name of the buffer to 'parsed <filename>'
silent execute "read !yourscript.sh " . l:fname
silent execute "file parsed " . l:fname
1d " Delete the first unwanted empty row
1 " Position to first row
endfunction
将yourext
和yourscript.sh
替换为正确的值。
您将有两个新缓冲区:一个包含原始文件,另一个包含解析的输出(这将是当前缓冲区(。
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 如何通过cpp程序运行shell脚本
- 程序崩溃并显示"std::out_of_range"错误
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 在程序中编写脚本来编写和编译代码
- 从数据库实时显示QT c++中的数据
- 当使用比格式支持的精度更高的精度来显示数字时,会写出什么数据
- 显示错误输出的简单数组排序程序
- 如何在c++中使用system()来运行包含空格的python脚本
- Qt自定义QPush按钮未显示在布局上
- 如何从 bash 脚本捕获终端输出并将其显示在我的 Qt UI 中?
- QWebEngineView仅在javascript脚本完成后显示页面
- VIM:执行复杂文件类型的脚本和显示结果
- 屏幕显示脚本中'.'令牌之前的预期非限定 id
- 从c++程序运行shell脚本会自动将shell脚本的输出显示到控制台吗