Surround selection into array - intellij-idea

I am aware about surrounding selection in quotes or braces
PhpStorm wrap/surround selection?
I need similar but surround selection into array
Assume I have text separated with newline or text separated with space
a
b
c
d
e
a b c d e
I need after selection get [a,b,c,d,e]
Please advice any IDE or method how to achieve this

A no-brainer solution
Make sure the following option is enabled:
For text separated with spaces:
Select the 'array-to-be', hit Ctrl+R and R again (to enter 'In selection' mode)
Type a space in the first field, , in the second
Click 'Replace all', hit Esc
With the text still selected, press [: the closing bracket will be added automatically
For multi-line text:
Select the 'array-to-be', hit Ctrl+R, enable 'Regex'
Type \n + in the first field, , in the second
Click 'Replace all', hit Esc
With the text still selected, press [: the closing bracket will be added automatically
The sequence of actions can be wrapped into a macro and assigned a single shortcut.

Vim + Surround plugin. Enter visual mode, select what you need and press S].

The first group could be created by:
:%s/\v(\w)(\n)*/\1,/g | exec "norm! I[\<Esc>A]"
It takes care of:
a
b
...
\v ........... very magic regex
() ........... regex group
(\w) ......... letters
(\n)* ........ zero or more line breaks
\1 ........... repeat content of the first regex group

Related

How to remove all whitespace from a text file

I am trying to remove all whitespace using Intellij IDEA Ultimate 2019.1.2. I have a simple text file with json data.
I've tried using find and replace with regex enabled, but to no avail.
You can press the CTRL + R to open the replace panel, and enter a whitespace in the first input field, leave the second input field empty.
Then click the replace all button.
If you want remove all whitespace including line break, you can enter \s and enable the regex option.

Visual Studio Code: Select each occurrence of find

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!

How to replace all tab characters in a file by sequences of white-spaces in intellij?

Given a file in my project, I want to be able to replace all of the tab characters in the file with white spaces. Is there any way to do this in intellij?
Go to Edit | Convert Indents , and then choose To Spaces or To Tabs respectively. It's in the documentation: Changing identation
Replace only tabs used for indentation
Ctrl + Shift + A
type "To Spaces" > Enter
Replace all tabs
Ctrl + R
check Regex
Enter \t and spaces
Replace all

How to paste text to end of every line? Sublime 2

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

To ignore linenumber's selection in Less inside Screen

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.