Notepad++: Record macro will not remember steps taken within Column Editor - macros

I'm trying to remove duplicates in an document. This includes both of entries it finds without moving the order of the entries.
Example
A
B
C
Random info
B
C
Results
A
Random info
I found how to do that via this link and following Method 2. Problem is when recording the macro it doesn't record steps I take when using Column editor. Does anyone know how to fix this or a different method? Thank you

Unfortunatelly, column editor and other plugin actions cannot be recorded because of a bug in notepad++.
However, you can still achieve what you want without using column editor.
Use this macro:
Start macro recording
Control + H to launch "search & replace":
Find what: ^([^\n]*)$\R([\s\S]*?)\R?+^\1$
Replace by: \2
Replace All
Place the cursor at the first position of the file (line 0, character 0) Use the mouse or use Control + G, then 0
Stop macro recording
Now, run your macro with run a macro multiple times and select run until the end of file.
Here is a demo of the process:

Related

VSCode select next occurrence of variable

In VSCode on Mac, I can use the keyboard shortcut Cmd + D to select the next occurrence of my currently highlighted text.
For example, if I highlight the variable order on line 1 in the below code, hitting Cmd + D causes order_form on line 2 to be partially highlighted, and hitting Cmd + D again causes order to be highlighted on line 3.
1. order = "Some string"
2. order_form = create_form()
3. return "Here is your order: " + order
However, I just want to select the actual variable order on lines 1 and 3 (i.e. excluding the text that is part of the variable order_form)
What keyboard shortcut can I use to just highlight the actual variables named order on lines 1 and 3?
The Ctrl+D functionality uses the current Find widget settings "behind the scenes" - whether that Find widget is visible or not.
So you would get the behaviour you want if the Whole Word option was enabled in that Find widget first before you began Ctrl+D'ing.
Alternatively, as the demo below shows when you place your cursor on the word you want order you can then hit Alt+W which will toggle the Whole Word option on and off. Note the little box that opens in the top right of the editor that shows only the Find options.
Then all your find next occurrences with Ctrl+D will find only what you want with that Whole Word option still enabled.
If you want to skip any of those occurrences, you can use the command
Add Selection To Previous Find Match
editor.action.addSelectionToPreviousFindMatch
(which you would have to make your own keybinding for). Just trigger that command to skip the next possible match - so follow this order:
Ctrl+D on the first order
Alt+W to enable whole word matching
trigger the command Add Selection To Previous Find Match
Ctrl+D to select the next order
It sounds like a bit of a hassle but they are common commands to know - to skip the next match and to toggle Whole Word matching.
[That little box that opens with the Find options is a little glitchey in that it seems to sometimes also enable the case sensitivity option as well - which isn't a problem in your example.]

How can I confirm individual changes in a project-wide find and replace?

When I'm in project search (Shift + CMD + F) I can search the whole project for a specific word or expression. I can also enter a word I would like to replace it with.
If I click on one of the search results, it shows me the current version and the replacement version side by side. However, I can't find a way to confirm the replacement instance by instance! I only see a button to replace ALL instances, which is usually not what I want to do.
The reason is that certain words might be used in different context throughout the project, so usually not all search results shall be replaced.
How can I confirm the replacement instance by instance?
The replace one is on the each item that showing when mouse moved on each item.
As an alternative approach, you can press CMD + D repeatedly to select successive instances of a match, and CMD + SHIFT + D to skip any instance you do not want to include, and in this way case by case include each match in your find \ replace.
Also useful is CMD + U to undo the last selection action, in case you screw up during this process so you don't need to start over. Note, your shortcuts may be vary per operating system, but the procedure is the same.

Automatic Code Identation

I have a huge code and now for testing purpose I have to add that whole script into an infinite while loop is there any short way (without pressing space for each row) to add a space for indentation so the whole code is consider part of the one while loop ? Such as for example when we press ctrl +r it comments out the line
Ctrl-I/Cmd-I will automatically indent the file. Other wse you just select multiple row and use Tab/Shift-Tab to move them backwards and forwards.
For indentation is a must, however Matlab as a language does not care so it is not really a must to indent it. Additionally, you can just execute the code from the command line, say that you script or function is called Umar, then from the command line you just type while 1, Umar; end.
You can copy the code into notepad++.
Activate Column mode selection holding alt+shift and use the mouse to select the column of all the text you want to insert a space/tabulation/etc. and just insert it.
Final step is to copy back the code to matlab.
Matlab does not currently support column selection.
MATLAB has the option to select all your code, then press the right click and select smart indent button.
If you like to use shortcuts, just type the combination of Ctrl+A (select all) followed by Ctrl+I (smart indent)

NppExec in Notepad++ to "Run a Macro Multiple Times..."

I use simple NPP_Exec commands in N++ which work fine for macros. Eg.:
NPP_MENUCOMMAND Macro/Action1
NPP_MENUCOMMAND Encoding/Convert to ANSI
NPP_SAVE
But how can I run a specific macro several times?
I have tried NPP_MENUCOMMAND Macro/Run but then I still have to manually select the macro I need and set it to "Run until the end of line" in the pop-up window.
You can use the NppExec plugin for simple loops like this:
:REPEAT
SCI_SENDMSG SCI_GETCURRENTPOS
set pos1 = $(MSG_RESULT)
// put your Macro invocation here instead of the linedown:
SCI_SENDMSG SCI_LINEDOWN
SCI_SENDMSG SCI_GETCURRENTPOS
set pos2 = $(MSG_RESULT)
// if the linedown (or your macro) doesnot give another pos, we have reached the end
if $(pos1) == $(pos2) goto END
// else loop
goto REPEAT
:END
it stores the current position
then it does something that advances the position (in this example a linedown, you would put your Macro invocation there, make sure it changes the cursor position)
then the position is compared with the stored position; we have reached the end, if the position has not changed;
in this case we leave the loop
I just found a simple and easy solution for that. I did not use command lines but it might work as well:
Make sure the macro ends with a Ctrl-Tab key
From Settings -> Preferences -> MISC, disable the doc switcher.
Open all files to be edited.
Use the "Run macro multiple times" dialog, and enter the number of files you have just opened.
Execute
Save all
I did not create this, found it here:https://sourceforge.net/p/notepad-plus/discussion/331754/thread/469ffec9/ , but it worked like a charm for me. I could edit 400 documents in less than 2 min.
I found another way to achieve this. Inspired by Wagner Fontes's answer, we can do the following:
Step 1: Record your Macro
Step 2 (Important): Before you finish the Macro, type the "Ctrl + Tab" as the last record in the Macro. This hotkey means moving to the next opening text file.
Step 3: Save the Marco.
Because of the Step 2, Notepad will move to the next text file after running the macro once. In this method, "Run a Macro Multiple Times" makes "Multiple Files".

Emacs column mode from one file to another: Register does not contain text

I am trying to copy a column from a text file to another with emacs.
I select the text with C-x, r, r, and then try to copy the same in another text with C-x,r,l + Enter. However, at the end it says: Register does not contain text. Is it because I am trying to copy from one file to another?
My crystal ball suggests that maybe you're copying from two different Emacs sessions. Registers only work within a single Emacs session.