How to find a string in a file and moving the cursor to it using a macro in sublime text - sublimetext2

As per the question. Using a macro in sublime text how can I:
Find a matching string
Move to the end of line where that string is found
Insert something at the end of line

I don't believe this is possible in a single step using the built-in macros, because Sublime macros don't support find and replace out of the box. You can manage it easily enough in two steps, though:
Given the following trivial example:
<ul>
<li>one
<li>two
<li>three
</ul>
If I wanted to close these tags, I could:
type </li>, select it, then cut it to my clipboard
start recording with ctrl-q
cmd-rightArrow to move to the end of the line
cmd-v to paste
ctrl-q to stop recording
cmd-f and enter a search string (possibly regex!)
hit enter to focus on the selection back in the document
Now you can alternate:
shift-ctrl-q to play back the macro
cmd-g to advance to the next match
Of course, for such a simple example, using multiple cursors (maybe with SelectUntil) would be a quicker, simpler solution.
For more complex or repeatable operations, RegReplace may be useful.

Related

VSCode How do I skip past an automatically generated end </tag>?

Say I were typing
<h2>Show Subject*</h2>
How would I jump to the end of the brackets if my cursor was at the *. Usually I would just arrow key right 4 times or use my mouse to select the next line. I see others on youtube doing this easily.
example: https://youtu.be/PlxWf493en4?t=567
Her cursor instantly jumps to the end of the . My < > also do not highlight as hers does when I autogenerate them.
The magics you're seeing in the linked video are features of Emmet. For example there's Emmet: Go to matching pair, which you can bind to something convenient using the Keyboard Shortcuts dialog (Ctrl-k Ctrl-s). Try Ctrl-Shift-p to bring up the command pallete and then type Emmet to see all of the available commands. I would suggest taking some time to read the docs and discover what functionality is available to you.
What looks like jumping to the outside of the end tag in the video is really just jumping to the end of the line, which is bound by default to the End key. Also useful is word jumping (Ctrl+RightArrow/Ctrl+LeftArrow) and word selection (Ctrl+Shift+RightArrow/Ctrl+Shift+LeftArrow). You might take a look at this wiki article for a fairly comprehensive list of common shortcuts.

Visual Studio Code: How to remove html tags and write to multiple lines at the same time?

How does one do this:
I found many useful tricks here Multiline editing in VSCode
I know I could use Ctrl+Alt+Shift+Up/Down
I know I could just press Shift+Up/Down to and delete the opening li tags together. But the closing li tags are not in the same line of sight.
How does one do what is being shown in the above example.
Alright, combining valuable comments by #Nick and #Strelok (thanks guys), Here is the answer:
Step 1: Select <li> using Shift+Right
Step 2: Press Ctrl+D several times till all the <li> tags are selected.
Step 3: Press Del
Step 4: Press End
Step 5: Press Backspace to delete closing </li> tags
Step 6: Press Home
Step 7: Press Left key till you are at the right spot inside <a> tag. And then type whatever you wish to.
Even though I could deduce this answer only from the comments by #Nick and #Strelok, I decided to post the answer myself because it would be unfair to mark one as answer when both the comments were equally helpful. I am going to keep the question open for now just in case someone comes up with a better way. Perhaps a way to avoid pressing Ctrl+D multiple times.
There is an emmet command that will remove a tag for you: editor.emmet.action.removeTag. It is currently unbound to any keybinding but you could easily make your own. Here is a demo without binding that command:
Select your <li>'s however you choose [I use Ctrl-Shift-L in the demo - but that selects all of them in the file which may or may not be appropriate for your use case.]
Trigger the editor.emmet.action.removeTag
Arrow over to your insertion points.
Pretty easy especially if you give that emmet command a keybinding.
You have the entire keyboard shortcut overview directly in VSC Ctrl + K or Ctrl + R or Help menu 'Keyboard Shortcuts Reference'
Mark your desired characters.
Hit Ctrl + F2 to mark all similar occurrences.
Change everything simultaneously.
Repeat for additional changes.

Atom Editor Next Line Shortcut

I added a package to the Atom code editor that closes HTML tags for me. This feature is included in many code-editors, so it isn't Atom-specific.
For example, I type
<h1>
and it conveniently changes the line to
<h1></h1>
and places my cursor between the two tags.
This is where the dilemma occurs: My cursor is placed between the words and the closing tag, and I wish to go to the next line. Moving my hand to the mouse and clicking to the end of the line and then pressing enter is out of the question, especially with long documents where this phenomenon occurs hundreds, if not thousands of times.
Is there any way, perhaps a keyboard shortcut that skips to the end of the line, to solve this?
In Atom, CmdEnter (Mac) or CtrlEnter (Windows/Linux) will make a new line and go there, skipping past whatever is presently on the line.
You can just push the end button. Mine is located above my backspace key, but it might be with the number pad if you have a separate number pad.
If you add the same element over and over again, you could copy & paste it. And for the sake of an empty element you could copy & paste something like <br /> (you can even leave out the space, I just like to add them to make self-closing tags easier to identify).
PS: empty headlines? shame on you!

Sublime Search/Replace adds New Line

When I do a simple search/replace, without any regex, ST2 adds a newline to each replacement. What am I doing wrong?
Below, I want to change spaces to commas. It does so, but also throws in a newline.
If the text you would like to replace is somewhat limited in size, here is a workaround. It doesn't even incorporate the builtin replace feature, and it can be somewhat slow for large text files.
Hit CMD + F (or CTRL + F) to bring up the Find dialog on the bottom of the window. Enter whatever string you'd like into the text field. Click the "Find All" button, and you'll get multiple write positions into the file. You can write in two places at once! If you've done it correctly, you'll see not just one blinking vertical line (which usually indicates the position in the file that the read/write pointer is at), but multiple. You can then type as usual into the file, and it should add text in multiple places.

Multiple ST2 Cursors

I am in need of being able to select multiple cursors for thousands of lines that would then let me add content before each of them at the same time. Is there a way to select all and then select the multiple cursor option to put the cursor before each character of each line? Hope that does not sound confusing :-(
On Windows / OS X
Make sure you have View > Word Wrap off
Select all: Ctrl / Cmd+A
Split into Lines:Ctrl / Cmd+Shift+L
Put the cursor at the beginning of the line: Home / Ctrl+A
Yes, though I don't know how well multiple selections works with thousands of lines.
Start with Select All or select the lines that you need to edit.
From the Selection menu -> Split into lines. This will create multiple selections, one for each line.
Move the cursor to the beginning of each line by using the Home key.
Insert your content.
You can do as was suggested in other answers, it will work perfectly fine, sublime can handle thousands of selections for sure, but it might get bit slow sometimes.
Use regex in search n' replace, that's what it's for.
ctrl+h opens search and replace tab
make sure "Regular expressions" is pressed, "wrap" is pressed and "in selections" is NOT pressed.
type ^ to top field, it will mean "beginning of line" in this context
type your text in bottom field
ctrl+alt+enter or whatever the shortcut is to "replace all"