regex - Vim 正则表达式 : Add character before the last word of each line

标签 regex vim

Word1 Word2 Word3 ... Wordx LastWord
Word1 Word2 Word3 ... Wordx LastWord

我怎么可能加上“|”在每行的最后一个单词之前,并在 vim 中使用 Regex 返回以下结果?

Word1 Word2 Word3 ... Wordx | LastWord
Word1 Word2 Word3 ... Wordx | LastWord

最佳答案

尝试以下命令

:%s/[^ ]*$/| &/

或者(由IngoKarkat 建议)

:%s/\S*$/| &/

关于regex - Vim 正则表达式 : Add character before the last word of each line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20077765/

相关文章:

Javascript - 删除除正则表达式定义之外的所有内容?

regex - 是否可以使用正则表达式来匹配条件?

git - 进行 git 提交时出现 Vi 错误

vim - 从 Syntastic 隐藏装订线

javascript - 正则表达式认为我正在嵌套,但我没有

python - 我无法使用 re.split 来处理数字,但将它们保留在字符串中并放在一起,

php - 可以使用正则表达式通过 php 表单将可以输入 MySQL 数据库的单词列入黑名单

vim - Vim 如何显示 :ls results (curses/cooked mode)

python - 当我尝试在命令行中运行 vim 时出现 Python 错误

jquery - 仅使用部分值设置组合框的值