vim 变量具有不需要的尾随字符



在我的 vimrc 中,我尝试将 grep 的输出存储到 vim 变量中

let w:tex_file =  system("grep -lZ '\documentclass' *.tex")

在我的 linux 盒子上,这完美运行。

let w:tex_file main.tex

但是在我的Macbook上,我有一个不需要的尾随字符"^A"

let w:tex_file main.tex^A

我怎样才能摆脱这个?

您看到的尾随字符^@是换行符。你可以像这样轻松摆脱(你应该):

let w:tex_file =  system("grep -lZ '\documentclass' *.tex")[:-2]

let w:tex_file =  system("grep -lZ '\documentclass' *.tex")
let w:tex_file = w:tex_file[:-2]

最新更新