How to switch/replace two strings in code fastest way - coding-efficiency

I often need to switch places of two strings while coding. I double click the first one, cut it with CTRL+X, go to the other string string, click at the beginning of second string, CTRL+V to paste first string, then select second string like this: my cursor is already at the start of it, so I pres SHIFT and click mouse button at the end of it, then again CTRL+X to cut it, then go to place of the first string which can be pages away and paste it there.
I do this often and keep thinking to my self there's gotta be quicker way to do this in some editors. I use Sublime usually. But I would switch to another one for this 'feature'.
What I would like to do is:
Select first string by mouse double click
Click special command on keyboard
Select second string by mouse double click
Click special command on the keyboard
This special command should not stretch my fingers too much, so I would prefer something close to CTRL+C, but yes most of it is occupied. So my proposal is this:
CTRL+CC (press C two times)
CTRL+V (does the replace)
This seems very fast and intuitive. Are there some drawbacks?

Don't use the mouse. You'll waste too much time.
Use CTRL + SHIFT + ARROW_RIGHT to select the first word, starting from its first character. Select the second string the same way.
To not stretch your fingers:
- don't use CTRL + C, instead use CTRL + INS
- don't use CTRL + V, instead use SHIFT + INS

Related

Vim - go to next match + change word + paste clipboard does not work

In my Vim, hitting cw (change word) and then command + v (MacOS paste shortcut) is able to replace the word on cursor to the clipboard copied one, but if I search some word then press n to go to the next match, and then do the same thing with cw then command + v, the copied one are not able to be pasted (it dose not show up) until I press ESC. It used to work normally.
What could be the possible cause of this?
It's caused by romainl/vim-cool, it used work without this issue, maybe because I changed vim config or installed some other new plugins that don't fit with it.

Is there a command to select everything between a range of cursors in sublime?

My circumstance:
I'm working with Fortran. Sometimes, I want to select everything that's within a block of code. It's easy for me to select the start/end elements of a block because it all look like this:
SUBROUTINE FOO(BAR)
IF (BAR .GT. 1) THEN
//DO SOMETHING
ENDIF
RETURN
END SUBROUTINE FOO
Move the cursor to SUBROUTINE, Hit Ctrl+D twice, done. Both instances of the SUBROUTINE keyword are highlighted.
But now I want to select everything between the SUBROUTINE keywords. I want a selection that includes everything from the start of the first SUBROUTINE to the end of the second SUBROUTINE. I prefer this be done in language agnostic manner, because I can imagine circumstances like this might occur in other contexts and I don't want to bother accumulating muscle memory for something that only works in Fortran.
Is there a command in sublime to select all text that occurs between the start and end positions of a multicursor selection?
There's a group of commands in sublime that approximate this behavior. They're exposed through the CTRL+K combo keys:
set_mark, CTRL+K, CTRL+Space
select_to_mark, CTRL+K, CTRL+A
delete_to_mark, CTRL+K, CTRL+W
Search for the first result, call set_mark, search for the second, call select_to_mark.

Entering a key stroke 'down arrow' into an excel formula

I have an excel concatenate formula that I need to paste into another program. I have successfully entered the tab keystroke with CHAR(9), but I can't seem to get the down arrow keystroke to work. I have tried using CHAR(40), but the program I am pasting to does not recognize this.
Here is my formula:
=CONCATENATE(M16,CHAR(9),CHAR(9),CHAR(9),CHAR(9),CHAR(9),M17,CHAR(9),CHAR(9),
CHAR(9),CHAR(9),CHAR(9),LEFT(M9,55),CHAR(9),CHAR(9),CHAR(9),CHAR(9),CHAR(9),
RIGHT(M9,100),CHAR(9),CHAR(9),CHAR(9),CHAR(9),CHAR(9),"=",M18,CHAR(9))
I want to replace the 5x CHAR(9), which is 5x the tab key, with just one text entry for down arrow.
Does anyone know another way of doing this other than CHAR(40)?
I'm not entirely clear about what you're after, so I'll try to cover both bases:
If you want the text to start on t new line then:
char(13) will give you a carriage return
char(10) will give you a line feed
If you are (literally) sending these keystrokes to another application then you may also want to investigate the Application.SendKeys method which sends keystrokes to the active application. You can do things like:
Sub MySub()
AppActivate ("Notepad")
SendKeys ("Some text{TAB}{DOWN}{TAB}Some more text")
End Sub

Vim script to indent selected code, insert code before and after selection

How can I script an action in Vim that will take the selected lines, indent them once, jump to the beginning and insert some code, then jump to the end and insert some code?
The code that needs to be inserted at the beginning and end are static and don't need to change (at least, not at this point).
Let's say beginning text is --- and ending text is ***
:execute "normal gv>i---\<Esc>`>a***"
If you want to record it into a macro, say buffer "a", then starting with a visual selection, use:
qa start recording into a
> indent
i insert mode
--- start text
Esc normal mode
`> end of last visual selection
a insert after
*** end text
Esc normal mode
q end recording
The following key sequence steps should work.
search for the start line e.g. /mysearch
qa - starts recoding the a macro
Vxj where x is the needed number of line(s)
>> to indent
ESC
'< jumps to the start of the marked lines
insert whatever you want (e.g. O to start a new line right above)
ESC
'> jumps to the end of the marked lines
insert whatever you want (e.g. o to start a new line right below)
hit q to end recording the macro.
Or something like this.
HTH
This is an old question, but I thought I'd contribute anyway. This is how you can take a paragraph and wrap text around it. Not exactly what you asked for but this one is just much neater if you write small nice small chunks of code. From anywhere in the paragraph type:
>ip (indent paragraph)
ki (jump before the first line and open a new one)
type what you want at the beginning of the paragraph here
<Esc>} (jump to after the last line of paragraph)
type what you want at the end of of the paragraph
<CR><Esc>
Caveats here are, as implied, this must be a "paragraph" (no empty lines) and this will not work properly if there is no new line after the paragraph. To accomodate this, use i instead of o but then you will be an empty line before the bottom bit of code you insert. You would need to write up something in vimscript if you wanted to account for this.
Here are all the strokes I use for setting up macro t to do a begin/rescue/end (for example) block:
qt>ipkibegin<Esc>}orescue<CR>end<CR><Esc>q
There are certainly better ways but this is keeping it at the marco level.

Adding Apostrophe in every field in particular column for excel

How can you add an apostrophe in every field in an Excel spreadsheet without individually typing it in? I have got like 5k fields
I'm going to suggest the non-obvious. There is a fantastic (and often under-used) tool called the Immediate Window in Visual Basic Editor. Basically, you can write out commands in VBA and execute them on the spot, sort of like command prompt. It's perfect for cases like this.
Press ALT+F11 to open VBE, then Control+G to open the Immediate Window.
Type the following and hit enter:
for each v in range("K2:K5000") : v.value = "'" & v.value : next
And boom! You are all done. No need to create a macro, declare variables, no need to drag and copy, etc. Close the window and get back to work. The only downfall is to undo it, you need to do it via code since VBA will destroy your undo stack (but that's simple).
The way I'd do this is:
In Cell L2, enter the formula ="'"&K2
Use the fill handle or Ctrl+D to fill it down to the length of Column K's values.
Select the whole of Column L's values and copy them to the clipboard
Select the same range in Column K, right-click to select 'Paste Special' and choose 'Values'
i use concantenate. works for me.
fill j2-j14 with '(appostrophe)
enter L2 with formula =concantenate(j2,k2)
copy L2 to L3-L14
More universal can be:
for each v Selection : v.value = "'" & v.value : next
and selecting range of cells before execution

Resources