Sublime Text 3:如何进行排除空行的多行选择? [英] Sublime Text 3: How to do multi-line selection that excludes blank lines?

查看:66
本文介绍了Sublime Text 3:如何进行排除空行的多行选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Stata中写了一些脚本如下:

I have some scripts in Stata written as follows:

* 1. count of firms in each bin
grouplabs Inear_dist_km_0_10 Inear_dist_km_10_30 Inear_dist_km_30_60 Inear_dist_km_60_100 Inear_dist_km_100_150 Inear_dist_km_morethan150, groupvar(Inear_dist_km_gr) emptylabel(empty)
graph hbar (count) if Inear_dist_km_gr !=1, over(Inear_dist_km_gr) name(n1)

* 2. count of firms in each bin (bigger bins)
grouplabs Inear_dist_km_0_20_v2 Inear_dist_km_20_40_v2 Inear_dist_km_40_60_v2 Inear_dist_km_morethan60_v2, groupvar(Inear_dist_km_v2_gr) emptylabel(empty)
graph hbar (count) if Inear_dist_km_v2_gr !=1, over(Inear_dist_km_v2_gr) name(n2)

* 3. GGK firm level bins
grouplabs Inear_dist_km_GGK_0_10 Inear_dist_km_GGK_10_50 Inear_dist_km_GGK_morethan50, groupvar(Inear_dist_km_GGK_gr) emptylabel(empty)
graph hbar (count) if Inear_dist_km_GGK_gr !=1, over(Inear_dist_km_GGK_gr) name(n3)

我需要在每行的末尾添加字符 ;,而不是在每个脚本之间的空行中.我尝试了 Split into Lines 技巧来在每行的末尾获得多个光标,但选择还包括它们之间的空行.这导致

I need to add the character ; at the end of each line, but not in the blank lines between each script. I have tried the Split into Lines trick to get multiple cursors at the end of each line, but the selection also includes the empty lines in between. This results in

* 1. count of firms in each bin;
grouplabs Inear_dist_km_0_10 Inear_dist_km_10_30 Inear_dist_km_30_60 Inear_dist_km_60_100 Inear_dist_km_100_150 Inear_dist_km_morethan150, groupvar(Inear_dist_km_gr) emptylabel(empty);
graph hbar (count) if Inear_dist_km_gr !=1, over(Inear_dist_km_gr) name(n1);
;
* 2. count of firms in each bin (bigger bins);
grouplabs Inear_dist_km_0_20_v2 Inear_dist_km_20_40_v2 Inear_dist_km_40_60_v2 Inear_dist_km_morethan60_v2, groupvar(Inear_dist_km_v2_gr) emptylabel(empty);
graph hbar (count) if Inear_dist_km_v2_gr !=1, over(Inear_dist_km_v2_gr) name(n2);
;
* 3. GGK firm level bins;
grouplabs Inear_dist_km_GGK_0_10 Inear_dist_km_GGK_10_50 Inear_dist_km_GGK_morethan50, groupvar(Inear_dist_km_GGK_gr) emptylabel(empty);
graph hbar (count) if Inear_dist_km_GGK_gr !=1, over(Inear_dist_km_GGK_gr) name(n3);

如何从选择中排除空行,​​以便只有其中包含字符的行才会有 ; 结尾?感谢您的帮助.

How can I exclude the empty lines from the selection so that only lines with characters in it will have ; at the end? I appreciate your help.

推荐答案

  1. 如果您确定您的空白行确实是空白且没有填充空白字符,请按 ctrl+H 使用正则表达式替换,搜索 (?<!^)$ 并替换为 ;.

  1. If you're sure that your blank lines are really blank and not filled with whitespace characters use regex substitution by pressing ctrl+H, search for (?<!^)$ and replace with ;.

  • 正则表达式说:在 ((?<!…)) 开头 (^) 之后不直接找到行尾 ($)代码>).
  • The regex says: find an end of line ($) not directly after ((?<!…)) the beginning (^).

Else 搜索 (?<=\S)$ 但确保没有任何尾随空格或制表符.

Else search for (?<=\S)$ but make sure you don't havy any trailing spaces or tabs.

  • 如何确定":使用[^\S\n]+$ 找到它们并删除.
  • 第一个正则表达式表示:在 ((?<=…)) 一个非空白字符(包括换行符)之后直接找到行尾.

  • How to 'make sure': find them with [^\S\n]+$ and delete.
  • The first regex says: find an end of line directly after ((?<=…)) a non-whitespace character, including linebreak.

第二个正则表达式说:找到一个字符序列(…+),这些字符不是 ([^…]) 个非空白字符或换行符——即不包括换行符的空白字符序列——然后是行尾.

The second regex says: find a sequence (…+) of characters that are not any of ([^…]) non-whitespace characters or linebreak -- i.e. a sequence of whitespace characters excluding the linebreak -- and then the end of line.

  • ctrl+F找到你的空行,搜索^\s*$
  • alt+enter 全选,
  • menu > Selection > Invert Selection(现在你只高亮了非空白行),
  • 继续使用原始的拆分成行技巧.
  • find your blank lines with ctrl+F, search for ^\s*$,
  • select all with alt+enter,
  • menu > Selection > Invert Selection (now you've highlighted inly the non-blank lines),
  • go on with the original Split into Lines trick.

这篇关于Sublime Text 3:如何进行排除空行的多行选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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