Change word after quotation in vim? - vim

I know you can use cw to change the word and ciw to change the inner word, but what i'm trying to do is change the word after the character.
For example I have this
this.option('test');
Now my cursor is at the first quote (') and I want to change the word test. If I press cw it also deletes the first quote my cursor is on. I'm on the other hand looking for a command that imitates the a mode (where it inserts after the cursor), so in my case deletes the word after cursor and puts it in insert mode?

cw is not "change the word", it's "change to next word".
With the cursor on either of the single quotes, you can use ci' to "change between single quotes".
With the cursor on the first single quote, you could also do:
wciw move to next word then change inner word
wcw move to next word then change to next word
wct' move to next word then change until next single quote
wce move to next word then change to end of the word
lciw move to next character then change inner word
lcw move to next character then change to next word
lct' move to next character then change until next single quote
lce move to next word then change to end of the word
<Right>ciw move to next character then change inner word
<Right>cw move to next character then change to next word
<Right>ct' move to next character then change until next single quote
<Right>ce move to next word then change to end of the word
See :help navigation.

If your cursor is at ( ' ) than you can use
ci'
This will delete the text and sets you in insert mode to make the change.
So it's change inside the '.

Related

How do I listen to a specific text string on Mac OS X in a livecode application

I want to create a Mac app similar to Textexpander or Atext. Both these applications allow the user to define snippets along with their respective trigger words. Typing the trigger words in any app, replaces that trigger word with the actual snippet defined.
I presume that the app listens to all strings being typed in any app and when it detects a string matching one of the trigger words defined, it replaces it with the snippet.
Is that how it actually works, or is there some other way?
Make two fields. In field 2 put something like:
time xyz
come ABC
In the script of field 1:
on textChanged
if the last char of me = space then
put the last word of me into temp
if temp is in fld 2 then
repeat for each word tWord in fld 2
put the last word of line lineOffset(temp,fld 2) of fld 2 into the last word of me
exit repeat
end repeat
end if
select after text of me
end if
end textChanged
Now type into fld 1, you know, "Now is the time for all good men to come to the aid of their country". This can be better done with an array, but the concept may be more accessible here.
This is a better handler, since it will not react to the trigger word:
on textChanged
if the last char of me = space then
put the last word of me into stringOfInterest
put fld 2 into dataToSearch
if stringOfInterest is in dataToSearch then
repeat for each line tLine in dataToSearch
if word 1 of tLine = stringOfInterest then
put word 2 of tLine into the last word of me
exit repeat
end if
end repeat
end if
select after text of me
end if
end textChanged

I have text in separate lines inside same box, How to make it all in one line

Some of my text are in different lines inside same cell. I want them in single line. How do I bring them in single line ?
Example:
first cell contains:
Hi Ram, I want to go to movie today.
Are you willing to join?
If yes, let me know early.
Example:
Expected output:
Hi Ram, I want to go to movie today.Are you willing to join?If yes, let me know early.
New line in a cell A1 caused by alt+Enter for example, may be removed using a formula such as:
=SUBSTITUTE(A1,CHAR(10)," ")
Where A1 is the cell containing the text to be changed. You can enter the formula above in a different cell of course.
The parameter " " indicates 1 space to replace the line break. You could use any other character.
Another type of line break is CHAR(13). You can remove CHAR(13) using the same function again:
=SUBSTITUTE(SUBSTITUTE(A1, CHAR(13)," "), CHAR(10), " ")
In case you had some spaces already before the new-line character, you need to wrap the above formula in a TRIM function like so:
=TRIM(SUBSTITUTE(A1,CHAR(10)," "))
OR
=TRIM(SUBSTITUTE(SUBSTITUTE(A1,CHAR(13)," "),CHAR(10)," "))
Always make a copy of your file before you apply formulas that could change the data.
Note-1:
char(13) is officially called "carriage return" and char(10) is called "line feed".
CHAR(10) returns a line break on Windows, and CHAR(13) returns a line break on the Mac. This answer is for Windows. You can't visually see it but you can see its effect.
Note-2:
As #kojow7 answered, a text wrap can cause the text to appear on more than 1 line depending on the cell width and the text length. This answer does not resolve this case.
Related discussion can be found here: Remove line breaks from cell.
Two things you may need to fix here: 1) Line breaks and 2) Text Wrapping
To fix line breaks:
Select the cells that need to be changed
Press CTRL+H to open Search and Replace
In the Find box type CTRL+J to insert the line break character (it may look like nothing was inserted in the field, but it does insert a line break)
Decide whether to replace the line breaks with a space or with nothing
Press Replace All
To turn off text wrapping:
Select the cells that need to be changed
Go to the Home Tab
In the Alignment Group check to see if the Wrap Text button is clicked.
If it is, click on it again to deselect it.
Depending on your situation, you may need to fix either one or both of these.
Depending on your document it might contain linefeeds or carriage returns or BOTH.
Alexander Frolov (https://www.ablebits.com/office-addins-blog/2013/12/03/remove-carriage-returns-excel/) has written a very good blog post about different technics of finding and removing linebreaks in an Excel file. We will use the “macro way” of doing that – as it is the one that works either on Windows AND Mac. The search replace method offered here too will not work on Mac but on windows.
Add the below Macro to your document (slighlty modified from the original)
Change the value of “ReplaceWith” from ” ” (space) to anything you like a linebreak to be replaced with.
E.g. ReplaceWith = “-” will result in “Line1-Line2-Line3”
Run the Macro (Extras > Macro) while all cells are selected.
Sub RemoveCarriageReturns()
ReplaceWith = " "
LinefeedChar = Chr(10)
Dim recordRange As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each recordRange In ActiveSheet.UsedRange
If 0 < InStr(recordRange, LinefeedChar) Then
recordRange = Replace(recordRange, LinefeedChar, ReplaceWith)
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
If your separate lines are not gone by now please change "LinefeedChar" from "Chr(10)" to "Chr(13)" and run it again

How to select a word with special characters in LIvecode

How to select a word with with special characters (eg: usa-uk). the following code will select text but it's doesn't select the words like usa-uk. How I change my code
select the mouseText
If you don't have a huge text in your field you might use:
on mouseMove
if the mouseLoc is within the rect of me then
put the mouseChunk into tChunk
# Check if chars before or after is a "spacing char"
put word 2 of tChunk into tstart
put word 4 of tChunk into tEnd
repeat with i = tStart down to 1 step -1
if matchText(char i of me, "\s") then exit repeat
end repeat
put i+1 into tStart
repeat with i = tEnd to the number of chars of me
if matchText(char i of me, "\s") then exit repeat
end repeat
put i-1 into tEnd
select char tstart to tEnd of me
end if
end mouseMove
How are you selecting? For example, if this was in the field script:
on mousemove
select the mouseText
end mouse move
You would be selecting the text under the cursor. In order to select compound text such as "usa-uk" you would have to group that text fragment. This sets the textStyle of that fragment to "link".
Craig Newman

Delete from cursor to end of line under visual selection in vim

I have a code segment like below.
type Account struct {
Id int
UserId int
Name string
Address string
City string
State string
CountryId string
}
I want to delete all the data types. Is there a key combination to this?
I tried <C-V> and select the first letter of all data types in a vertical line, hoping d + $ would work post that, however vim only takes the first input d and deletes the first letter.
Use <C-v> to enter visual block mode, select the lines you want to change and then D to delete until the end of those.
From :h v_D :
{Visual}["x]X or *v_X* *v_D* *v_b_D*
{Visual}["x]D Delete the highlighted lines [into register x] (for
{Visual} see |Visual-mode|). In Visual block mode,
"D" deletes the highlighted text plus all text until
the end of the line. {not in Vi}
Note that, as mentioned in the help, X and D are not equivalent in visual block mode (X only deletes the current selection, not until the end of the line).
You can move to the left brace, press the % key and issue:
s/ \+[^ ]* *$/
to get:
type Account struct
Id
UserId
Name
Address
City
State
CountryId
}
The substitution removes all non-white-space characters at the end of the line.
You can use C-V and select the first column of all data type, then do $ to select until the end of the line, followed by x or d to delete.
Visually select all those lines with v6j.
Remove the extra stuff with :'<,'>norm ElD ('<,'> is added automatically for you).
Also, watch out for trailing space!
Not the shortest possible sequence but following is more natural to me
vi{ - Visually select the inner paragraph
'<,'>norm weld$ (typed as :norm weld$)
witch breaks down to
'<,'>norm - Apply normal commands over the selection
wel - jump to the end of the first word
d$ - delete until the end of the line

Paste yanked text in several sequential lines

If I have multi-line line snippet:
length = 1;
keys = NewKey(value);
gt_backref = NULL;
ls_backref = NULL;
And I need to paste yanked (<ctrl>-V+y) node-> between every line of snippet:
node->length = 1;
node->keys = NewKey(value);
node->gt_backref = NULL;
node->ls_backref = NULL;
How do I paste yanked text in several sequential lines? Something like <ctrl>-V+<shift>-I but for paste, not for typed text.
<C-v>{motion}I<C-r>"<Esc>
Enter visual block mode with <C-v>.
Extend your selection.
Hit I to enter insert mode.
Do <C-r>" to insert the content of the unnamed register.
Hit <Esc> to apply the change to all the selected lines.
Or with :normal:
:[range]norm I<C-r>"<CR>
Well, if you select the text with Shift-V, then do a regex
:'<,'>s/.*/node->&/
that would add node-> to the selected lines.
or I guess even simpiler
:'<,'>s/^/node->/
If it's more complicated, maybe you would create some kind of macro with a search to find the type of lines you want to replace and run the same regex replace on each of those lines
This answer based on #Shaun's answer. This really needs a macro. But the correct regexp is
:'<,'>s/\(^\s\+\)/\1node->/
Because I need to take into account indentation.
But this approach does not universal. For every particular case we need new regexp.

Resources