Vim-在搜索中捕获字符串并在替换中使用 [英] Vim - Capture strings on Search and use on Replace

查看:320
本文介绍了Vim-在搜索中捕获字符串并在替换中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CSS选择器,例如:

I have a css selector such as:

#page-site-index .toolbar .items {

如何捕获".toolbar .items"部分并将其用于Vim S& R的Replace部分,因此该选择器可以变成:

How do I capture the ".toolbar .items" part and use it on Replace part of Vim S&R, so this selector can turn into:

#page-site-index .toolbar .items, #page-site-login .toolbar .items {

类似的东西:

%s:/#page-site-index \(.toolbar .items\)/#page-site-index (the captured string), #page-site-login (the captured string)/g

顺便说一句,我正在使用Vim的终端版本.

Btw, I'm using the terminal version of Vim.

推荐答案

使用\1 ...在此处查看Wiki: http://vim.wikia.com/wiki/Search_and_replace

Use \1... See the wiki here: http://vim.wikia.com/wiki/Search_and_replace

更明确地:

%s:/#page-site-index \(.toolbar .items\)/#page-site-index \1, #page-site-login \1/g

这篇关于Vim-在搜索中捕获字符串并在替换中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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