如何“申请"文本文件中的退格字符(最好在 vim 中) [英] How to "apply" backspace characters within a text file (ideally in vim)

查看:30
本文介绍了如何“申请"文本文件中的退格字符(最好在 vim 中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有退格字符的日志文件 (^H).我正在 Vim 中查看文件,可能很难看出发生了什么.

I have a log file with backspace characters in it (^H). I'm looking through the file in Vim and it can be quite hard to see what's going on.

理想情况下,我希望能够在给定的行/范围上应用"所有 ^H,以便我可以看到最终结果.

Ideally I'd like to be able to "apply" all the ^H on a given line/range so that I can see the final result.

我更愿意在 Vim 中逐行执行此操作,但是转换整个文件的解决方案总比没有好.

I'd much rather do this within Vim on a line-by-line basis, but a solution which converts the whole file is better than nothing.

推荐答案

打开'paste'选项(使用:set paste),然后按dd i 1 在要应用退格键的每一行上.如果您删除多行甚至整个文件,这也适用.

Turn on the 'paste' option (using :set paste), and then press dd i <CTRL-R> 1 <ESC> on each line that you want to apply the backspaces to. This also works if you delete multiple lines, or even the whole file.

这里的关键是您正在使用 1 在插入模式下输入"寄存器 1(刚刚删除的行的位置)的内容,粘贴"选项可防止 Vim 使用任何映射或缩写.

The key here is that you are using <CTRL-R> 1 in insert mode to 'type out' the contents of register 1 (where your deleted lines just got put), and 'paste' option prevents Vim from using any mappings or abbreviations.

这篇关于如何“申请"文本文件中的退格字符(最好在 vim 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆