How to select multiple lines of code and space them all? - ide

This may be a fairly simple answer, or relatively easy; though I haven't been able to find the correct command/way to do so from anywhere.
As the title states, I'm trying to figure out the way as to space multiple lines of code.
Here's an example of what I'm looking for:
testing = "Testing"
work = "Work"
answer = "Answer"
Now I'd like to add spaces to the first two lines (selected together) at the same time, as in:
testing = "Testing"
work = "Work"
answer = "Answer"

Hold CTRL and click at the beginning of each line.
This will create two cursor points and every command will be iterated at every point.
Another tip:
You can highlight a selection of text, and CTRL + D will highlight all matches for that text and activate a cursor next to it. Very useful for mass editing in things like tables or forms.

Related

Moving the code one coloumn to the left

I wrote a code and now my excel template has changed (the first column is no longer in need), is there a way to move the entry code 1 column to the left instant of correcting it step by step?
For example(This is the old code):
.Range("I1:J1") = Array("CHECK", "KEY")
Now I need to change it to:
.Range("H1:I1") = Array("CHECK", "KEY")
But it's a very long code and I want to know if there's any way do to it easier.
Thanks.
I'd suggest simply using the built in Search & Replace function ( Ctrl + f ). Put something like
.Range("I1:J1")
into the "Find What" field and
.Range("H1:I1")
into the "Replace With" field.
If you're really lazy you could hit the Replace All button, but this can be dangerous as in possibly changing parts you didn't want to change. However, using the Replace button and going through all entries can be fairly fast even in a longer code, and this way you can check with each entry if it's really correct to change it.

How to delete the last return in a PowerPoint field?

I have created a function that allows a user to import one or more text files into a field in PowerPoint. This works really well. The user clicks in the field, clicks the button on the custom menu, selects the files from a list and in they go. The problem I have is that I have to put two returns between each imported text, which means there are two left on the end.
This is the usual result to delete a paragraph I have found:
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=27, Length:=1).Select
ActiveWindow.Selection.TextRange.Text = ""
This suggests I would have to calculate the last position int he selected field to be able to delete it.
Could anyone give me an idea of how I would go about this?
This solution is a bit easier (not tested):
dim tmpTXT as string
tmpTXT = ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Text
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Text = Left(tmpTXT, len(tmpTXT) -1)
You could do something similar earlier, before you write text to your shape which would be better.

Simultaneous paste and copy of selection text

Background
I want to be able to select some text, hit a keystroke that pastes what is on the clipboard over that selection, but at the same time copying that selection to the clipboard. I often find myself doing this operation when switching variables, etc from place to place.
Example
First sentence here, I need to switch it with the second sentence below. (ctrl-c)
...
Second sentence here, I am going to put this where the first one is.
///////
First sentence here, I need to switch it with the second sentence below.
...
First sentence here, I need to switch it with the second sentence below. (ctrl-"vc" after selecting second sentence, first sentence pasted, second sentence copied now)
///////
Second sentence here, I am going to put this where the first one is. (ctrl-v)
First sentence here, I need to switch it with the second sentence below.
My question
Does anyone know if any IDE/software supports such a paste/copy functionality? Has anyone ever run into this?
More specifically, does any one know how to set up a keyboard shortcut to do this in sublime text 2?
You can do it with a plugin. I threw this together rather quickly. I don't do anything special for multiple cursors (though it should take the content of multiple cursors as well as paste to all the proper locations).
import sublime
import sublime_plugin
class PasteAndCopyCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
current_content = []
cursors = view.sel()
for cursor in cursors:
current_content.append(view.substr(cursor))
for cursor in cursors:
view.replace(edit, cursor, sublime.get_clipboard())
sublime.set_clipboard("\n".join(current_content))
After you save the plugin, use paste_and_copy as the the command for your key binding or command palette entry.

How to select all instances of a variable and edit variable name in Sublime

If I select a variable (not just any string) in my code, all other instances of that variable get a stroke (white outline) around them:
Is there a keyboard shortcut that will let me select all of those instances of the variable and edit them all at once?
Things I've Tried:
⌘D, ⌘K, and ⌘U lets me select them one-by-one, but I have to manually exclude the non-variable string matches:
And using Ctrl⌘G simply selects all the string matches:
Clearly, Sublime is able to differentiate between variable and string matches. Is there no way to select just the variable matches?
Put the cursor in the variable.
Note: the key is to start with an empty selection. Don't highlight; just put your cursor there.
Press ⌘D as needed. Not on a Mac? Use CtrlD.
Didn't work? Try again, making sure to start with nothing selected.
More commands:
Find All: Ctrl⌘G selects all occurences at once. Not on a Mac? AltF3
Undo Selection: ⌘U steps backwards. Not on a Mac? CtrlU
Quick Skip Next: ⌘K⌘D skips the next occurence. Not on a Mac? CtrlKCtrlD
Sublime Docs
I know the question is about Macs, but I got here searching the answer for Ubuntu, so I guess my answer could be useful to someone.
Easy way to do it: AltF3.
Despite much effort, I have not found a built-in or plugin-assisted way to do what you're trying to do. I completely agree that it should be possible, as the program can distinguish foo from buffoon when you first highlight it, but no one seems to know a way of doing it.
However, here are some useful key combos for selecting words in Sublime Text 2:
Ctrl⌘G - selects all occurrences of the current word (AltF3 on Windows/Linux)
⌘D - selects the next instance of the current word (CtrlD)
⌘K,⌘D - skips the current instance and goes on to select the next one (CtrlK,CtrlD)
⌘U - "soft undo", moves back to the previous selection (CtrlU)
⌘E, ⌘H - uses the current selection as the "Find" field in Find and Replace (CtrlE,CtrlH)
This worked for me. Put your cursor at the beginning of the word you want to replace, then
CtrlK, CtrlD, CtrlD ...
That should select as many instances of the word as you like, then you can just type the replacement.
The Magic is, you have to start with an empty selection, so put your cursor in front of the word/character you want to multi-select and press Ctrl+D .
To me, this is the biggest mistake in Sublime. Alt+F3 is hard to reach/remember, and Ctrl+Shift+G makes no sense considering Ctrl+D is "add next instance to selection".
Add this to your User Key Bindings (Preferences > Key Bindings):
{ "keys": ["ctrl+shift+d"], "command": "find_all_under" },
Now you can highlight something, press Ctrl+Shift+D, and it will add every other instance in the file to the selection.
As user1767754 said, the key here is to not make any selection initially.
Just place the cursor inside the variable name, don't double click to select it. For single character variables, place the cursor at the front or end of the variable to not make any selection initially.
Now keep hitting Cmd+D for next variable selection or Ctrl+Cmd+G for selecting all variables at once. It will magically select only the variables.
It's mentioned by #watsonic that in Sublime Text 3 on macOS, starting with an empty selection, simply ⌃⌘G (AltF3 on Windows) does the trick, instead of ⌘D + ⌃⌘G in Sublime Text 2.
At this moment, 2020-10-17, if you select a text element and hit CTRL+SHIFT+ALT+M it will highlight every instance within the code chunk.
Just in case anyone else stumbled on this question while looking for a way to replace a string across multiple files, it is Command+Shift+F

Algorithm to find word on Boggle board

I'm building a boggle game in vb .net. Right now, my dices are as a 2d array (0,0 0,1 ) etc...
What I want it to do is, as I'm typing the word, that it highlights it on the board using the button(x,y).doclick sub which highlights it. Right now my implementation finds the first letter, then keeps trying each letter until it meets the 8 corner condition (ie it is neighbored to the last one) but this does not always work. If there are say 2 "G"'s on the board and I want the bottom one, this will not work. Can somebody give me an example of psuedocode of what needs to happen. I've been stumped for almost 6 hours trying to figure this out. Thanks
If I understand correctly, given a string you want to highlight one path through the dice that matches the string. Sometimes there are several possible choices, so adding a letter may completely change what is highlighted. It may be a good approach here to keep results from the previous substring, so we don't have to start over. Then a reasonable thing to do would be to compute all possible paths.
The answer for a given string s would be a list of paths, where a path is a list of grid coordinates. Each path is something you could reasonably highlight, so you just highlight the first one. When adding a letter to the string, you find paths you can expand and remove the ones you can't expand.
I'm afraid I don't know how to write vb code. Since you asked for pseudocode, here's some rough python-like pseudocode instead. I'm coding the boggle grid as a list of 16 items. The neighbors(x) function returns a list of the neighboring positions (except for edge cases that's going to be [x-1, x+1, x-4, x+4]).
def firstLetter(typed):
answer = []
for pos in range(16): if grid[pos]==typed: answer += [pos]
return answer
def addletter(partialanswer, typed):
answer2 = []
for partial in partialanswer:
for neighbor in neighbors(partial[-1]):
if grid[neighbor]==typed:
# partial+[neighbor] is a list. answer2 is a list of such lists.
answer2 += partial + [neighbor]
return answer2
If the player types "go", for example, then
(a) player types "g", code calls firstletter("g") and gets a list "answer" of the positions in the grid that have a "g" in them. Highlight, say, the first one.
(b) player types "o", code calls addletter(answer, "o") and gets a list of the paths in the grid that say "go". Again, highlight the first one.