Shift Left, No Tabs
-
^.{6}
NO!
Did you try it?
It won’t work, in fact it will delete most of the entire document!
References:- https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12695
- https://github.com/notepad-plus-plus/notepad-plus-plus/issues/6194
One way to achieve it:
Find:
(?-s)^.{6}(.*)
Replace:${1}
Search mode: Regular expressionThis assumes that all lines are 6 characters or greater.
-
@Alan-Kilborn Sure I tried it and it erased only the first 6 columns. (I did not check the box
. matches new lines
). -
@Paul-Wormer said in Shift Left, No Tabs:
Sure I tried it and it erased only the first 6 columns.
I think you’d better try it again, as it is not correct; see the references I cited.
(I did not check the box . matches new lines).
That doesn’t change the incorrectness of it anyway.
But if you are providing a solution, and you don’t use
(?-s)
or(?s)
in your regular expression, and you don’t say the state of the. matches newline
checkbox, your solution is incomplete. -
@Paul-Wormer
I used the numbers 1234567890 and duplicated them a number of times. Then only 7890 remained. After your comment I added also some letters: 1234567890abcd and duplicated them, now the first 12 on each line were discarded (only cd remaining). In other words, you are right and my test case was too simplistic. -
Thank you Paul for your prompt reply, and especially Alan for your correct reply! Although I don’t “know” regular expressions beyond their intent, I have printed the cheat sheet and will study it to learn from your example. Regardless, I was able to record a macro in Notepad++ which does exactly what I need to do; so again, THANKS!
PS: It seems like what I want to do should be built-in to Notepad++, but that’s a separate topic. I’m not sure how to request/recommend it, as this is my first post here.
Fred
-
@Fred said in Shift Left, No Tabs:
I have printed the cheat sheet
If you want more in the way of info, see the FAQ entry HERE.
It seems like what I want to do should be built-in to Notepad++, but that’s a separate topic.
Yea…I don’t know… It isn’t really a common thing. Sure, I’ve seen people ask about it before, but not with real regularity.
I’m not sure how to request/recommend it
There’s another topic in the FAQ that tells you how, HERE.
-
Probably an issue was created by the OP (username mismatch, but the timing is coincidental): https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12804
-
Hello, @fred, @paul-wormer, @alan-kilborn,
To solve the @fred problem, it would be necessary to have this additional and simple feature in the
Edit > Line Operations
section :Delete First Character
And, may be, we could add the following one, too :
Delete Last Character
Of course :
-
These new features should act ALSO on a stream selection
-
These new features should be included in the Shortcut Mapper manager
-
These new features should be recordable too
In this case, @fred would just assigned a shortcut to the
Delete First Character
action and would hit it six times to achieve his goal !
In the meanwhile, here are two simple macros which perform, approximately, these features. Just one limitation : these two macros work with a predefined stream selection ONLY !
-
The
Delete First Character
macro deletes the first character of the selection, throughout all the lines selected -
The
Delete Last Character
macro deletes the last character of the selection, throughout all the lines selected
<Macro name="Delete First Character" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s).(.*)" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="$1" /> <Action type="3" message="1702" wParam="0" lParam="128" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> </Macro> <Macro name="Delete Last Character" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s)(.*)." /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="$1" /> <Action type="3" message="1702" wParam="0" lParam="128" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> </Macro>
So :
-
Stop any instance of
N++
-
Insert the
XML
text above in the<Macros>.............</Macros>
node of your activeshortcuts.xml
file and valid the modifications -
Restart N++
-
Click on the
Macro > Modify Shortcut/Delete Macro...
menu option -
Double-click on the
Delete First Character
macro -
Attribute a shortcut to this macro and valid
-
Close the
Shortcut Mapper
with thESC
key -
Do a normal selection, from beginning of line, of a consecutive range of lines
-
Hit this shortcut repeatedly
x times
to delete thex
first characters of each line of current selection
Important :
-
If no selection exist, these two macros do nothing, as EXPECTED
-
Note that if you select, on purpose, a multi-lines range of characters, not beginning the first line and/or not ending the last line, these two macros will just delete characters within the stream selection ONLY !
-
In case of a rectangular selection, these macros consider that there is a stream selection from the beginning of the rectangular selection, in the first line to the end of the rectangular selection, in the last line.
-
And note that if a rectangular selection contains a block of complete lines, these macros act as it was a normal stream selection
Best Regards
guy038
-
-
@guy038 said in Shift Left, No Tabs:
Click on the Macro > Modify Shortcut/Delete Macro… menu option
Double-click on the Delete First Character macroNice Tip! I didn’t know double-click did anything in such a situation.
-
@guy038 said in Shift Left, No Tabs:
Do a normal selection, from beginning of line, of a consecutive range of lines
I would suggest using the “left click in line number margin and drag up/down” technique here for easy selection of full-line data.
-
@guy038 said in Shift Left, No Tabs:
Hit this shortcut repeatedly to delete the x first characters of each line of current selection
Or, select Run a Macro Multiple Times… and then specify the exact number of characters you want to delete.
-
Guy,
Do you think people might have “trouble” with this, maybe thinking it isn’t working right, if they have tab character(s) at start of line, and, because tab characters visually appear as multiple spaces, could possibly lead to confusion?
(Just asking…it isn’t going to happen to me, because I know what’s what.)
-
Hi, @alan-kilborn,
Yes…, you’re right about it, Alan ! But how to get a simple behaviour ? Note that the macro is about deleting the first character, regardless its type !
And, anyway, in your post https://community.notepad-plus-plus.org/post/83341, where you proposed the right regex method to delete the first
6
chars, they could betabulation
chars, as well ?BR
guy038