有没有办法只在 Vim 的某些区域同步 html 文件中所做的更改? (保持其他元素完好无损。)
有没有办法只在某些区域同步在 html 文件中所做的更改?保持其他元素完好无损。
假设我有这两个文件:
hello-world-english.html:
<div>
<p>Hello World</p>
</div>
hello-world-spanish.html:
<div>
<p>Hola Mundo</p>
</div>
我对第一个文件进行了以下更改(hello-world-english .html):
<div id=new-div">
<div>
<h2 id="new-header-2">
</h2>
<p>Hello World</p>
</div>
<div>
然后我希望第二个同步更改,但保留
内的内容标签
完好无损:
<div id=new-div">
<div>
<h2 id="new-header-2">
</h2>
<p>Hola Mundo</p>
</div>
<div>
PS:
我正在使用Vim!
Is there a way of synchronizing changes made in a html file only in some areas? leaving the other elements intact.
Lets say I have these 2 files:
hello-world-english.html:
<div>
<p>Hello World</p>
</div>
hello-world-spanish.html:
<div>
<p>Hola Mundo</p>
</div>
And I make the following change to the first one (hello-world-english.html):
<div id=new-div">
<div>
<h2 id="new-header-2">
</h2>
<p>Hello World</p>
</div>
<div>
Then I want the second one to synchronize the changes but leaving what's inside the <p> tag
intact:
<div id=new-div">
<div>
<h2 id="new-header-2">
</h2>
<p>Hola Mundo</p>
</div>
<div>
P S :
I'm using Vim!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
来分隔您想要在不同文件中保持同步的内容,例如:
'
'
但是,如果您希望未修改的数据是,例如,这将是一个问题,在其中一个
内。或者,您可以编写一个生成器,它需要两个文件:
hello-world.html
和您想要分开的部分的列表。这里的技巧是使用特殊标记,例如@
(或任何其他很少使用的字符),并将其替换为列表中的一项,这将是相当简单的。只需在hello-world.html
或列表更新时重新生成即可,一切就绪。或者更确切地说不是。我认为这个问题已经被比我更有经验的人解决了。谷歌是你的朋友;)。
You could use
<iframe>
to separate what you want to keep syncronized in different files, for example:'
'
But that'd be a problem if you want the unmodified data to be, for example, inside one of those
<div>
. Alternatively, you could write a generator that'd take two files:hello-world.html
and a list of the parts you want to keep separated. The trick here is to use a special marker, such as@
(or any other rarely used character), and replace it with one of the items in the list, which would be fairly trivial. Just regenerate when eitherhello-world.html
or the list get updated, and you're all set.Or rather not. I think the problem is already solved by someone with better experience than me. Google is you friend ;).
简短回答:不。
较长回答:这实际上取决于您对文件所做的更改。我想到了两种可能性:
1)对一个文件进行更改并通过版本控制差异运行它(您正在使用版本控制,不是吗?)以获得补丁文件。然后将补丁文件应用到另一个 HTML 文件。
2) 编写一个 vim 脚本,其中包含一系列编辑命令来进行所需的更改,然后在 vim 中打开每个文件和
:source
脚本。如果它们遇到了不期望的 HTML 文件之间的差异,则这两种方法都可能失败或进行意外更改。
更好的答案: 使用不同的语言维护 html 文件的两个版本是一个非常糟糕的主意,并且无法扩展(如果您想添加第三种语言怎么办?第四种语言?第十种语言?)。我建议使用一个模板文件,其中包含所有用户可见文本的占位符,以及一个脚本(使用 Python、Ruby 或任何您熟悉的语言),用特定于语言的转换表中的文本替换占位符。然后添加新语言只需编写新的转换表即可,您可以对模板进行任何所需的更改并为每种语言重新生成 HTML。
Short answer: No.
Longer answer: it really depends on what changes you are making to the file. Two possibilities come to mind:
1) make the changes to one file and run it through your version control diff (you are using version control, aren't you?) to get a patch file. Then apply the patch file to the other HTML file.
2) write a vim script with a series of edit commands that make the changes you want, and then open each file in vim and
:source
the script.Both if these may fail or make unexpected changes if they hit differences between the HTML files that they are not expecting.
Better answer: Maintaining two version of the html file with different languages is a really bad idea and will not scale (what if you want to add a third language? A fourth? A tenth?). I suggest having a template file with placeholders for all the user-visible text, and a script (in Python, Ruby or whatever you are comfortable with) that replaces the placeholders with text from a language-specific conversion table. Then adding a new language is simply a matter of writing a new conversion table, and you can make whatever changes you want to the template and regenerate the HTML for every language.
让 vim 显示两个文件之间的差异,并使用 dp 和 do 更新您想要的部分。
Have vim display the differences between the two files, and use
dp
anddo
to update the part you wish to.