本文翻译自:Notepad++ add to every line
I'm using Notepad++ and I can't figure this out : 我正在使用Notepad ++而我无法解决这个问题:
I have numerous lines all starting with http
. 我有很多行都以http
开头。 I need to add some text in front of it in every line. 我需要在每行中添加一些文本。 Also, I need to add different text to the end of each line. 另外,我需要在每行的末尾添加不同的文本。 Each line ends differently. 每条线的结尾都不同。
What is the fastest way to add text to the start and end of each line? 在每行的开头和结尾添加文本的最快方法是什么?
#1楼
参考:https://stackoom.com/question/kAa1/Notepad-添加到每一行
#2楼
Follow these steps: 跟着这些步骤:
- Press Ctrl + H to bring up the Find/Replace Dialog. 按Ctrl + H以显示“查找/替换”对话框。
- Choose the
Regular expression
option near the bottom of the dialog. 选择对话框底部附近的Regular expression
选项。
To add a word, such as test
, at the beginning of each line: 要在每行的开头添加一个单词,例如test
:
- Type
^
in theFind what
textbox 在Find what
文本框中键入^
- Type
test
in theReplace with
textbox 在Replace with
文本框中键入test
- Place cursor in the first line of the file to ensure all lines are affected 将光标放在文件的第一行以确保所有行都受到影响
- Click
Replace All
button 单击Replace All
按钮
To add a word, such as test
, at the end of each line: 要在每行的末尾添加一个单词,例如test
:
- Type
$
in theFind what
textbox 在Find what
文本框中键入$
- Type
test
in theReplace with
textbox 在Replace with
文本框中键入test
- Place cursor in the first line of the file to ensure all lines are affected 将光标放在文件的第一行以确保所有行都受到影响
- Click
Replace All
button 单击Replace All
按钮
#3楼
Notepad++ has a very powerful editing capability. Notepad ++具有非常强大的编辑功能。 (Today I'm searching for the similar function in Sublime Text), but for Notepad++, just hold Alt when you drag the mouse. (今天我在Sublime Text中搜索类似的功能),但对于Notepad ++,只需在拖动鼠标时按住Alt键 。 What you type will then replace the selected column on every line. 然后,您键入的内容将替换每行上的选定列。 To insert without replacing existing text, use Alt-Shift . 要在不替换现有文本的情况下插入,请使用Alt-Shift 。
#4楼
- Move your cursor to the start of the first line 将光标移动到第一行的开头
- Hold down Alt + Shift and use the cursor down key to extend the selection to the end of the block 按住Alt + Shift并使用向下光标键将选择范围扩展到块的末尾
This allows you to type on every line simultaneously. 这允许您同时键入每一行。
I found the solution above here . 我在这里找到了解决方案。
I think this is much easier than using regex. 我认为这比使用正则表达式容易得多。
#5楼
Open Notepad++, then click Ctrl + F . 打开Notepad ++,然后单击Ctrl + F.
Choose Regular Expression 选择正则表达式
*Find What: "^" (which represents index of the each line - "PREFIX"). *查找内容:“^”(表示每行的索引 - “PREFIX”)。
Replace with : "anyText"* 替换为:“anyText”*
For Suffix on each line: Follow the same steps as above "Replace ^ with $" . 对于每行的后缀 :按照上面“使用$替换^”中的相同步骤操作。 That's it. 而已。
#6楼
You can automatically do it in Notepad++ (add text at the beginning and/or end of each line) by using one regular expression in Replace ( Ctrl + H ): 您可以在Notepad ++中自动执行此操作 (在每行的开头和/或末尾添加文本) ,使用 Replace( Ctrl + H )中的一个正则表达式 :
Explanation: Expression $1
in Replace with input denotes all the characters that include the round brackets (.*)
in Find what regular expressin. 说明: 替换为输入中的表达式$1
表示在查找常规表达式中包含圆括号(.*)
所有字符。
Tested, it works. 经测试,它的工作原理。
Hope that helps. 希望有所帮助。