Autohotkey:剪贴板将制表符转换为空格 [英] Autohotkey : Clipboard Convert Tabs to Spaces

查看:589
本文介绍了Autohotkey:剪贴板将制表符转换为空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码被复制到我的剪贴板中。粘贴它看起来像这样。其中[tab]是一个实际的制表符缩进

  [tab]< header id =mastheadclass =site-header > 
[tab] [tab]< h1>
[标签] [标签] [标签]< h2>
[标签] [标签] [标签] [标签]< h3>
[标签] [标签] [标签] [标签] [标签]< h4>;

我想按一个autohotkey自动标准化代码片段。所以如果每一行都有一个[tab],请将其删除。
然后将每个[tab]转换为2个空格[b]

$ p $ < header id =mastheadclass = 站点报头 >
**< h1>
****< h2>
******< h3>
********< h4>

所以一般的工作流程是:


  1. 复制代码到剪贴板

  2. 按下一个autohotkey
  3. 粘贴新格式化的内容

autohotkey的伪代码如下所示:
$ b


  • 挖掘每个剪贴板内容行

  • 如果每个项目共享相同数目的[tab]空格,请将其全部删除。
  • *] 2 spaces


解决方案

 将每个标签转换为2个空格:

clipboard =

< header id =mastheadclass =site-header>
< h1> ;
< h2>
< h3>
< h4> ;;

clipboard:= StrReplace(clipboard,A_Tab,A_Space A_Space)

https://autohotkey.com/docs/commands/StringReplace.htm


I have a snippet of code I copied into my clipboard. Pasting it out looks like this. Where[tab] is an actual tab indent

[tab]<header id="masthead" class="site-header">
[tab][tab]<h1>
[tab][tab][tab]<h2>
[tab][tab][tab][tab]<h3>
[tab][tab][tab][tab][tab]<h4>;

I want to press an autohotkey to automatically normalize the code snippet. So if there's a [tab] on every line, remove it. Then convert each [tab] into 2 spaces [**]

<header id="masthead" class="site-header">
**<h1>
****<h2>
******<h3>
********<h4>;

So the general workflow is:

  1. Copy code to clipboard
  2. Press an autohotkey
  3. Paste the newly formatted contents

Pseudocode for autohotkey would look like this

  • Dig through every clipboard content line by line
  • If every item shares an equal number of [tab] spaces, remove them entirely
  • Line by line, convert [tab] to [**] 2 spaces

解决方案

; convert each tab into 2 spaces:

clipboard =
(
    <header id="masthead" class="site-header">
        <h1>
            <h2>
                <h3>
                    <h4>;
)
clipboard := StrReplace(clipboard, A_Tab, A_Space A_Space)

https://autohotkey.com/docs/commands/StringReplace.htm

这篇关于Autohotkey:剪贴板将制表符转换为空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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