可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
How can I have multiple cursors in Notepad++?
I will have a couple of tab delimited values . I need to write a query for all of these values. For example, if I get an Excel file with values like this:
1234 xyz pqr 2345 sdf kkk ...
I want to copy this whole piece of data into Notepad++ and write the query, inserting all the values at once.
Like this:
Insert into tbl (1234, xyz) where clm = 'pqr' Insert into tbl (2345, sdf) where clm = 'kkk' ...
I used to do it with my previous text editor Ultraedit. Can this be done using Notepad++?
回答1:
Yes: simply press and hold the Alt key, click and drag to select the lines whose columns you wish to edit, and begin typing.
You can also go to Settings > Preferences..., and in the Editing tab, turn on multi-editing, to enable selection of multiple separate regions or columns of text to edit at once.
It's much more intuitive, as you can see your edits live as you type.
回答2:
You can use Edit > Column Editor...
to insert text at the current and following lines. The shortcut is Alt + C.
回答3:
In the position where you want to add text, do:
Shift
+ Alt
+ down arrow
and select the lines you want. Then type. The text you type is inserted on all of the lines you selected.
回答4:
Notepad++ also handles multiple cursors now.
Go into Settings => Preferences => Editing and check "Enable" in "Multi editing settings" Then, just use Ctrl+click to use multiple cursors.
Feature demo on official website here : https://notepad-plus-plus.org/features/multi-editing.html
回答5:
Notepad++ has a powerful regex engine, capable to search and replace patterns at will.
In your scenario:
Click the menu item Search\Replace...
Fill the 'Find what' field with the search pattern:
^(\d{4})\s+(\w{3})\s+(\w{3})$
Fill the replace pattern:
Insert into tbl (\1, \2) where clm = \3
Click the Replace All
button.
And that's it.
回答6:
The easiest method to solve your problem (without going to a different editor or learning regex) is to record a macro.
- Place your cursor at the start of your text, click the 'record' button in the ribbon, and then edit just that one row of text. You may only use arrow keys or ctrl+arrow keys to move around characters/words rather than clicking with your mouse. The 'home' and 'end' keys are also useful.
- When you're finished with that one line, move your cursor (again without using the mouse) to the start of the next line.
- Click the 'stop recording' button.
- Click the 'play macro' button to check that it works on the next line as expected.
- Click the 'run macro multiple times' to do it again, and again, and again... :P
One advantage of this over 'multi-editing' cursors is you don't have to manually click and place cursors on every single row. The second advantage is that you can work with tab-delimited data that doesn't have consistent size/length - just use ctrl+left/right to skip words.
Honestly, macros in N++ have saved about a year of my life.
回答7:
You can add/edit content on multiple lines by using control button. This is multi edit feature in Notepad++, we need to enable it from settings. Press and hold control, select places where you want to enter text, release control and start typing, this will update the text at all the places selected previously.
Ref: http://notepad-plus-plus.org/features/multi-editing.html
回答8:
Notepad++ only has column editing. This is not completely the same as multiple cursors.
Sublime Text has a marvelous implementation of this, might be worth checking out...
It's a relatively new editor (2011) that is gaining popularity quite fast: http://www.google.com/trends/explore#q=Notepad%2B%2B%2C%20Sublime%20Text&cmpt=q
Edit: Apparently somewhere around Notepad++ version 6.x multi-cursor editing got added, but there are still a few more advanced features for it in Sublime, like "select next occurrence".