Swap text around equal sign

notepad++ reverse text
notepad++ regex replace
notepad++ reverse lines
replace text between two strings
regex replace text between
notepad++ regular expression replace between

Is there an easy way to flip code around an equal sign in vi/vim?

Eg: I want to turn this:

value._1 = return_val.delta_clear_flags;
value._2._1 = return_val.delta_inactive_time_ts.tv_sec;
value._2._2 = return_val.delta_inactive_time_ts.tv_nsec;
value._3    = return_val.delta_inactive_distance_km;
(...)

into this:

return_val.delta_clear_flags = value._1;
return_val.delta_inactive_time_ts.tv_sec = value._2._1;
return_val.delta_inactive_time_ts.tv_nsec = value._2._2;
return_val.delta_inactive_distance_km = value._3;
(...)

on A LOT of lines in a file.

I know this seems a little trivial, but I've been running into lots of cases when coding where I've needed to do this in the past, and I've never had a good idea/way to do it that didn't require a lot of typing in vim, or writing a awk script. I would think this would be possible via a one liner in vi.

Explanations of the one-liners is very welcome and will be looked upon highly when I select my accepted answer. :)

Something like this:

:%s/\([^=]*\)\s\+=\s\+\([^;]*\)/\2 = \1

You might have to fiddle with it a bit if you have more complex code than what you have shown in the example.

EDIT: Explanation

We use the s/find/replace comand. The find part gets us this:

  1. longest possible string consisting of anything-but-equal-signs, expressed by [^=]* ...
  2. ... followed by one or more spaces, \s\+ (the extra \ in front of + is a vim oddity)
  3. ... followed by = and again any number of spaces, =\s\+
  4. ... followed by the longest possible string of non-semicolon characters, [^;]*

Then we throw in a couple of capturing parentheses to save the stuff we'll need to construct the replacement string, that's the \(stuff\) syntax

And finally, we use the captured strings in the replace part of the s/find/replace command: that's \1 and \2.

Swap order of text using notepad++, In Notepad++ press CTRL + H. Find what: (^.*); (.*?$); Replace with: \2; \1;; Check Regular expression option. This way, whenever you type the text APROX=, Word will think that you actually wanted to type ≈ and will convert it into the Approximately Equal symbol automatically. What I like about the AutoCorrect tool is that you can assign any code you want to the symbol and Word will be more than glad to insert it for you whenever you type the code.

PC Mag, The Recent Reference List command is the only other technique available to maneuver around documents. Press Alt-Equal sign to get a list of links you've visited. features enable you to search and replace text, set margins, number pages,  Re: Excel VBA - Flip text around EQUALS sign Hi! I actually remedied my issue by pasting my code into the sheet and using Excel's Text-to-Columns feature and setting the delimiter to "=" to split the text.

:%s/^\s*\(.\{-}\)\s*=\s*\(.\{-}\)\s*;\s*$/\2 = \1;/

should work nicely.

Find and Replace text between ^ and ~ in Notepad++, I have a large text file where I want to remove all text between the ^ symbol and the ~ symbol. This needs to work across  Swap or switch text around within one cell by using VBA code. As above example shown, you can also run the following VBA script to swap or switch text around within one cell. 1. Press the Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window. 2. In the Microsoft Visual Basic for Applications window, click Insert > Module. Then copy and paste the below VBA code into the Module window.

:%s/\([^ =]*\)\s*=\s*\([^;]*\);/\2 = \1;/

Access 2007: The Missing Manual: The Missing Manual, To perform both these operations, you use the familiar equal sign, just as you would with properties. The following code puts It uses a variable to swap the content of two text boxes. ' Copy the text from  All formulas in spreadsheet programs, like Microsoft Excel, OpenOffice Calc, and Google Sheets start with an equal sign (=). To display an equal sign in a cell, but not have it start a formula, you must escape the cell by entering a single quote (') at the beginning. For example, to put the text "=hope" in a cell, type the text below in the

swap text before and after a character, Using awk with " = " as field separator, and simply turn around the fields. awk -F " = " '{OFS=FS;print $2  AutoLISP: Swap Text & Attributes Posted on August 24, 2011 by AutoCAD Tips Here is a good quickie that lets you swap text objects – even Attributes that are within the same block and even attributes within different blocks.

Regular Expressions Cookbook, Pass your regular expression as the first parameter, your replacement text as the For example, you want to match pairs of words delimited by an equals sign, and swap those words in the replacement. World's simplest text column order swapper. Just paste your text or file in the form below, press Swap Text Columns button, and you columns swapped. Press button, swap columns. No ads, nonsense or garbage.

How can I replace text after a specific word using sed?, Search for a line that starts with projdir , and replace the whole line with a new one: sed -i 's/^projdir . A way of writing "approximately equal to" ("almost equal to" \ "equals approximately" \ "approximately equals") in standard internet-based text * or plain text applications: This text can be read aloud as " equals approximately " or " is approximately equal to ".

Comments
  • I understand. I meant to say that if other parts of your code are more complex, e.g. have more than a single '=' or a ';' on a line (even in a quoted expression) my solution will not work without further tweaking.
  • That's fine. Usually when I have to flip stuff like that, they lines are of the format "lvalue = rvalue;" above, so your solution hits the nail on the head.
  • Is it a problem that this one requires spaces around the equals? It won't work for "lvalue=rvalue;" I believe. depesz's solution doesn't have that problem.
  • Spaces are (technically) optional, but I usually write assignment statements with spaces between the lvalue,rvalue and the operator.
  • I didn't know you could record macros like that in vim.
  • I always find that to be one of the killer vim features; before macros I would often end up in one of those repetitive loops performing the same brainless action on 20 sequential lines.
  • I tend to use macros like this a lot in combination with :g... for exmaple :g/something/normal @q
  • you can use ranges directly with the normal command ":.,+20 normal @q". I sometimes select a range of lines (shift+V) and then do a :normal <command-mode commands>
  • This works, I tried it, but I'm not sure about the \(.\{-}\) parts work. I know those match the code pieces on both sides of the equals sign. Can you explain how those code segments work?
  • ... and don't be greedy, unlike '*'
  • Please add some explanation to this, such that others can learn from it
  • Character by character level explanations for more than 2 or 3 inches of a compressed regex would take several pages to describe to a layman. Describing it generally considered socially unacceptable, as is unwanted medically correct psychoanalysis or calling someone fat in the grocery store.