In IntelliJ IDEs, I can add any duplicate words by using the 'Add selected text for next occurrence' key shortcut. When multiple words are selected simultaneously, I can then change all of them at once using the IdeaVim plugin and ciw key presses.
However, I haven't been able to do this successfully for sentences. For example, if I select a group of text between double quotes: " hello there ", what ends up happening is that I will be able to select/highlight duplicate groups of hello there, but pressing any key results in me only updating the first selection of hello there and not the other selections.
I do realize that I can achieve the same effect simply by doing a find/replace through the entire page, but I like the convenience of adding an occurrence one at a time with just a press of a button. Any suggestions?
There are several ways to achieve the behavior you mentioned. However if you are looking for a method that have the visual effect similar to the Intellij, you may need to use the plugin for vim, such as vim-multiple-cursors.
Here are some vim's ways to do that:
Next Occurence + Redo Last Command:
/ to search for all occurence (/ hello there )
n to navigate to next occurence
v and arrow key/l to select region
Substitute region with s or delete text under region with x
n for next occurence and . (dot) to redo last command and repeat n + .
MACRO:
/ to search for all occurence (/ hello there )
qq to start recording macro to key q
Do step 2-4 from previous method
q to stop recording macro
# then q to apply the macro from key q
Note: If you want to repeat step 5 n times, simply append a number before # (ex. 5#q to apply macro 5 times. If there are only 4 occurence, then macro will only be applied 4 timers.)
Find and Replace:
:%s/ hello there /new value/g to globally replace " hello there " to "new value"
To replace the occurrence in certain place, use visual block v to select the block then :'<,'>s/ hello there /new value/g to replace only in selected area
Related
How can I select several lines in Intellij using keyboard shortcuts?
I found out that I can do it with
ctrl + shift + right/left
But I have to press this buttons several times to select whole line.
What is more the selection starts from current caret position, so if it's not the beginning/end (depending of using left or right arrow) of the line, the whole first line is not selected.
What I usually do is to hit the Home key, and then either:
Shift+End to select until the end of the current line, or
Shift+Down to select until the next line, and then keep pressing Shift+Down to select multiple lines.
Also, IntelliJ IDEA supports the "Extend Selection" and "Shrink Selection" commands, for which the default key bindings are Ctrl+Alt+Left and Ctrl+Alt+Right.
These allow you to select entire blocks of code rather than word by word. You may still need to press the keys multiple times, but way fewer times than when selecting on a word by word basis.
I'm looking for a "select each occurrence of" something I'm trying to find. For example a file has a bunch of text that includes "abc", I type ctrl+f and type abc. I can either find the first one or the next one, but I would like to "multi-cursor" each one in the file.
I've already found the feature that lets me highlight text and ctrl+d to get the next that matches the selection, but if there's a hundred of these things - well that gets quite tiresome.
Ctrl+Shift+L Select all occurrences of current selection
editor.action.selectHighlights
Ctrl+F2 Select all occurrences of current word
editor.action.changeAll
Please refer for more information here.
Alt+Enter Select all occurrences of find match
editor.action.selectAllMatches
This has the added benefit of working with Regular Expression searches, since selecting occurrences of a word of a selection cannot leverage the Regex functionality.
I know this thread is here for a while now, but I think this will be helpful:
This thread on Github talks exactly about it:
https://github.com/microsoft/vscode/pull/5715
Summary:
Ctrl+F --> Open find widegt.
Alt+R --> Turn on regex mode.
Input search text --> Regex text or normal text.
Alt+Enter --> Select all matches.
Left arrow --> Ajust cursors.(Ignore this step if you don't want to edit the ---selected text.)
Edit text --> Do what you want.(Ignore this step if you don't want to edit the -selected text.)
Shift+Home --> Select modified text.(Ignore this step if you don't want to edit the selected text.)
Ctrl+C --> Copy selected text.
Ctrl+N --> Open a new tab.
Ctrl+V --> Paste.
well , basically the Ctrl+Shift+L will select all occurrences of word in the document BUT
there is some coool way to selecting them growingly:
if you hit Ctrl+d it will selects the second match , it you hit Ctrl+d again it will match the third one and so on ....
For Mach User:
COMMAND + Shift+ L Select all occurrences of the current selection
COMMAND + F2 Select all occurrences of the current word
For mac users::
Control + Command + G
^ + ⌘ + G
Ctrl+F2 is what worked for me for VSCode on Windows 10.
While Ctrl+Shift+L just opened some Language selector.
If you are searching in a single file, use simple search using Ctrl+F, then even if you close the search box, simply keep pressing F3 to go to next match and so on. F3 just repeats previous search and selects your next match.
On Mac:
Ctrl+F to open the find menu in top right:
Select the third option within the input and add the regex you want to match.
Ctrl+Shift+L to select all items that match.
Hope that helps!
I'm curious if there is a way to paste text to the end of every line in Sublime 2? And conversely, to the beginning of every line.
test line one
test line two
test line three
test line four
...
Say you have 100 lines of text in the editor, and you want to paste quotation marks to the beginning and end of each line.
Is there an easy way to do this or a plugin that anyone would know of? This would often save me a lot of time on various projects.
Thanks.
Yeah Regex is cool, but there are other alternative.
Select all the lines you want to prefix or suffix
Goto menu Selection -> Split into Lines (Cmd/Ctrl + Shift + L)
This allows you to edit multiple lines at once. Now you can add *Quotes (") or anything * at start and end of each lines.
Here's the workflow I use all the time, using the keyboard only
Ctrl/Cmd + A Select All
Ctrl/Cmd + Shift + L Split into Lines
' Surround every line with quotes
Note that this doesn't work if there are blank lines in the selection.
Select all the lines on which you want to add prefix or suffix. (But if you want to add prefix or suffix to only specific lines, you can use ctrl+Left mouse button to create multiple cursors.)
Push Ctrl+Shift+L.
Push Home key and add prefix.
Push End key and add suffix.
Note, disable wordwrap, otherwise it will not work properly if your lines are longer than sublime's width.
Let's say you have these lines of code:
test line one
test line two
test line three
test line four
Using Search and Replace Ctrl+H with Regex let's find this: ^ and replace it with ", we'll have this:
"test line one
"test line two
"test line three
"test line four
Now let's search this: $ and replace it with ", now we'll have this:
"test line one"
"test line two"
"test line three"
"test line four"
You can use the Search & Replace feature with this regex ^([\w\d\_\.\s\-]*)$ to find text and the replaced text is "$1".
Use column selection. Column selection is one of the unique features of Sublime2; it is used to give you multiple matched cursors (tutorial here). To get multiple cursors, do one of the following:
Mouse:
Hold down the shift (Windows/Linux) or option key (Mac) while selecting a region with the mouse.
Clicking middle mouse button (or scroll) will select as a column also.
Keyboard:
Select the desired region.
Type control+shift+L (Windows/Linux) or command+shift+L (Mac)
You now have multiple lines selected, so you could type a quotation mark at the beginning and end of each line. It would be better to take advantage of Sublime's capabilities, and just type ". When you do this, Sublime automatically quotes the selected text.
Type esc to exit multiple cursor mode.
Select all lines you want to add a suffix or prefix.(command+ A to select all the lines)
Press command+shift+L. This will put one cursor at the end of every line and all the selected lines would still be selected.
For adding suffix press command+right and for adding prefix command+left. This will deselect all the earlier selected text and there will only be cursors at the end or start of every line.
Add required text
I would like to develop a selection-tool for Screen which ignores the leading spaces and numbers in selection.
Problems
What is the code which affects selection-tool C-a Esc in Screen?
To make an algorithm which ignores the linenumbers and the space at the beginning from the selection:
alt text http://files.getdropbox.com/u/175564/%20selection-less.png
The following Perl-regex seems to match the beginning of the line
{5}[1-9]{1-4} {8} # not tested
The selection tool apparently works by concatenating an increase in selection to the current selection. For instance, one line is selected. I select another one: a new line is added to the selection queue. The reverse is true also for a decrease in selection.
I want to put the Perl regex on when the selection obverses \n such that the ignorance of the line is considered.
I think you want to select columns. That'd be much easier than a regex.
From the screen manpage:
c or C to set the left or right margin respectively. If no
repeat count is given, both default to the current
cursor position.
Example: Try this on a rather full text screen: "C-a [
M 20 l SPACE c 10 l 5 j C SPACE".
This moves one to the middle line of the screen, moves
in 20 columns left, marks the beginning of the paste
buffer, sets the left column, moves 5 columns down, sets
the right column, and then marks the end of the paste
buffer. Now try:
"C-a [ M 20 l SPACE 10 l 5 j SPACE"
and notice the difference in the amount of text copied.
So, in your screenshot, press C-a [, move the cursor to the beginning of your text, press SPACE and then press c. Move to the end of your selection and then press SPACE again. Now you have the text you want.
Hope this wasn't too much info. You tagged it with beginner so I wasn't sure if you were a perl or screen beginner.
I know that often using a for loop to generate repetitive content is the better way than pasting something 20 times and changing each paste to the correct number by hand. But let's say for cases where content is hard-coded and I just want a list from 1-20.
I would like a text editor with a "smart" paste command that takes any number imbedded in a string on the clipboard and increments it each time I paste. If it doesn't exist, I will make a plugin.
I'm trying to think of a good 2-stroke keyboard shortcut to do it, close to the ctrl-V. Maybe ctrl-g or numpad_+ (in an app with no zooming).
Does it exist?
In Zeus this can be easily done as follows:
Column mark the area to be converted to a numbers
Use the Macros, Execute Script menu
Type in numbers to run the numbers Lua macro
Type in the first number of the sequence
The marked area will be replaced by an incrementing sequence of number starting at the first number provided in step 4.
I'm trying to think of a good 2-stroke
keyboard shortcut to do it,
Making this into a key stoke action is as simple as binding the numbers Lua macro to the keyboard.
Here is an example of how it works. If 1 values in the text below are column marked and the macro executed with a starting number of 1000:
Field_1
Field_1
Field_1
Field_1
the following text changes will be made:
Field_1000
Field_1001
Field_1002
Field_1003
Armed bear J has a renumber region command, as well as a case-preserving replace-in-files, which means I often keep it around for those features.
TextPad is another text editor with a Fill Region function, for filling with a character, a string, or incrementing numbers (starting from X, with left- or right-alignment, and space- or zero-filled.)
I used Notepad++ now, but I have to keep TextPad around just for that number-filling function.