• Regex - Finding Invalid Characters in HTML Tags

    8
    1 Votes
    8 Posts
    1k Views
    Sylvester BullittS

    @guy038 Wow. I feel like I’m sipping from a fire hose! I bow to far greater experience than mine. Here’s the regex I finally chose:

    (?-si:<(?:title|figcaption|h[1-6])>|(?!\A)\G)(?s:(?!</).)*?\K\xAD

    I like your idea of using the \xAD for the soft hyphen: It clarifies what the regex is doing!

    I ran the regex it against my entire Web site (16,000 HTML files), and it works perfectly.

    I’ll be the first to admit I don’t fully understand why it works, but I can’t argue with success. I’m going to have to study it for a while, but it now has a permanent home in my toolbox.

    Thanks for taking the time to look at this thorny issue!

  • Same line spacing with other view

    6
    0 Votes
    6 Posts
    853 Views
    CoisesC

    @PeterJones said in Same line spacing with other view:

    I haven’t been able to find a way to send a message to Scintilla (the library that Notepad++ uses for the doing the editor commands) to change the height of individual lines.

    “All lines of text in Scintilla are the same height, and this height is calculated from the largest font in any current style. This restriction is for performance; if lines differed in height then calculations involving positioning of text would require the text to be styled first.“
    https://www.scintilla.org/ScintillaDoc.html#TextRetrievalAndModification

  • collapse specified xml-Tags on file opening

    2
    0 Votes
    2 Posts
    467 Views
    PeterJonesP

    @HConBike ,

    In native Notepad++, no.

    If you installed the PythonScript plugin, then a script could be written (and run every time a file is opened with the specific extension you specified) to search for the Fonts block and fold that level.

  • Accidental open

    8
    1 Votes
    8 Posts
    540 Views
    mkupperM

    @Alan-Kilborn said in Accidental open:

    But clearly OP was having trouble getting rid of it.

    That’s part of what seems like the bug I mentioned earlier. I started to write up the issue but it is turning into a long post plus I realized there were hints in the github issues that it has been reported, so I’ve parked the bug report it pending review, testing, and thinking.

    If someone does Ctrl+Tab or Ctrl+Shift+Tab to bring up the document switcher and you then while holcing Ctrl down you type Esc to exit document switcher the Ctrl+Esc or Ctrl+Shift+Esc are sent to Windows. Ctrl+Esc brings up the start menu and Ctrl+Shift+Esc activates task manager. That’s issue one.

    If you then switch back to Notepad++ you’ll see the document switcher dialog box but can’t get focus onto it other then via the mouse. Thus the box can appear to be stuck in the way. That’s issue two. The document switcher dialog box is model which means Notepad++ itself is locked up. It’s not a crisis as you mouse click within the box and it’ll activate the tab you happened to select via the dialog box.

    You can also trigger the second issue’s behavior by Ctrl+Tab and while holding the Ctrl key down you click on the task bar to bring another application the foreground. When you switch back to Notepad++ you’ll be moderately stuck with the document switcher. It turns out that pressing and then releasing Ctrl will clear the document switcher.

    github issue 10950 seems to describe what I saw but at the time that issue was raised it also seemed to be intermittent or hard to reproduce.

  • Select all marked text

    15
    0 Votes
    15 Posts
    9k Views
    Tomasz SałekT

    @Coises said in Select all marked text:

    In quoting you, it appears that you meant your regular expression to be ^\d+/\d\t; but it didn’t come out that way, because the asterisks were interpreted as signaling italics and the backslash before the forward slash was dropped (which you may or may not have intended).

    Right. This supposed to be ^\d+\/*\d*\t. Thanks for an advice.

  • Search Just Within Provided Line Number

    14
    1 Votes
    14 Posts
    507 Views
    Alan KilbornA

    @guy038 said in Search Just Within Provided Line Number:

    I don’t understand because, in my post, I do NOT speak about deleting the 2 digit, at any moment ?

    Ah…you’re right. I supposed I was confused because when you said:

    Leave the Replace with: zone Empty

    It appeared to me like this was setting up a replace-with-nothing aka delete operation!

  • Difference in display between Win11 Notepad and Notepad++

    3
    1 Votes
    3 Posts
    2k Views
    B

    @PeterJones Oh, so it’s actually a super simple issue. Thank you!

  • how to view the line separately where curly bracket are used

    8
    0 Votes
    8 Posts
    812 Views
    Mark OlsonM

    @PeterJones
    FWIW, if all you want is to pretty-print or compress the results of a regex search with PythonScript, you could replace the call to JsonTool’s pretty-print faculty with a quite simple script using Python’s json library.

    import json from Npp import editor PRETTY_PRINT_INDENT = 4 class CompressOrPrettyPrintRegexSearchResult: def __init__(self, compress): self.compress = compress def callback(self, m): parsed_group_2 = json.loads(m.group(2)) indent = None if self.compress else PRETTY_PRINT_INDENT formatted_group_2 = json.dumps(parsed_group_2, indent=indent) return m.group(1) + formatted_group_2 + m.group(3) if __name__ == '__main__': try: COPPRSR except NameError: COPPRSR = CompressOrPrettyPrintRegexSearchResult(True) editor.rereplace('(?s-i)(<fieldMap[^<>]*>)(.*?)(</fieldMap>)', lambda m: COPPRSR.callback(m)) # this will toggle between compressing and pretty-printing COPPRSR.compress = not COPPRSR.compress
  • How to Insert/Import Text from a Separate File

    2
    0 Votes
    2 Posts
    3k Views
    Alan KilbornA

    @AcmeNuclear said in How to Insert/Import Text from a Separate File:

    Does Notepad++ have an easier way to make this text file insertion into the current file - without executing something similar to Open (source file), Select all (source file); Copy; Select target location (receiving file); Paste; Close (source file)?

    Not really.
    But if you’re willing to use a scripting plugin, a simple script can be written:

    from Npp import * import os f = notepad.prompt('Enter file name:', '', '') if f and os.path.isfile(f): notepad.open(f) editor.selectAll() editor.copy() notepad.close() editor.paste()

    The script assumes you have the “MRU” setting selected (otherwise when the script closes the file tab it opens, you won’t be returned to the correct file tab):

    de7fbf65-50c8-42ec-bed9-ec4e218fe5ed-image.png

    And, yes, this script is very simple. It intentionally loads the file into Notepad++ (instead of just reading the file with Python) to avoid making non-Notepad++ assumptions about the encoding of the file, it expects you to know the name of the file you want (instead of a “picker”), it will close the to-be-inserted-file if that file happens to be open in N++ when the script is run, etc.). Many things could be done to make the script more well-rounded.

    For the basics of scripting, see HERE.

  • Add folding rules to an existing language

    3
    0 Votes
    3 Posts
    451 Views
    E

    @PeterJones oh… that seems not feasible, udl was a quite better option. Thank you for helping me make a quick decision.

  • Replace guid with guid from list randomly

    2
    0 Votes
    2 Posts
    615 Views
    Mark OlsonM

    The regex gurus on this forum might come up with some kind of crazy regex-based solution to this, but this is pretty easy to solve with PythonScript.

    # requires PythonScript: https://github.com/bruderstein/PythonScript/releases # ref: https://community.notepad-plus-plus.org/topic/25388/replace-guid-with-guid-from-list-randomly import random import re from Npp import editor, notepad, MESSAGEBOXFLAGS def main(): thing_to_replace = notepad.prompt('Enter the text you want to replace', 'enter text to replace', '') if not thing_to_replace: return is_regex = notepad.messageBox( 'Is the thing you want to replace a regular expression?', 'regular expression?', MESSAGEBOXFLAGS.YESNO) == MESSAGEBOXFLAGS.RESULTYES if not is_regex: thing_to_replace = '(?-s)' + re.escape(thing_to_replace) replacements = notepad.prompt( 'Enter a list of replacements (one per line)', 'list of replacements', '') if not replacements: return replacement_list = replacements.strip().splitlines() def get_random_from_list(_): return random.choice(replacement_list) editor.rereplace(thing_to_replace, get_random_from_list) if __name__ == '__main__': main()
  • save repeat operations in a script?

    19
    0 Votes
    19 Posts
    805 Views
    Furio SassiF

    @mkupper said in save repeat operations in a script?:

    @Furio-Sassi said in save repeat operations in a script?:

    Do you happen to know a text editor that supports scripts?

    Notepad++ has syntax highlighting for scripts but won’t offer help or hints as you are typing.

    There are editors known as IDE “integrated development environment” which allow you to single step through the script with the IDE also showing you what variables are being changed. It’s an area I’m not familiar with and particularly, an IDE that would let you trace or debug a Python script activated from Notepad++ and is doing Notepad++ and/or Scintilla specific things.

    Everything clear, thanks for the help! :)

    And I would also like to make peace with those I argued with, in the world there are so many reasons to argue that it would be stupid to argue even over something stupid like that. I came here in complete good faith, before writing I had also looked for information on macros (as I specified in my second post where I wrote “the macro, if I understand correctly, repeats the recorded operation”) but I had not found any references to scripts , that’s why I asked for help. Then the discussion took a direction I didn’t want.

    Thanks everyone, bye :)

  • Save As takes an other folder then the oriiginal

    3
    0 Votes
    3 Posts
    255 Views
    Arne EverhardA

    @Alan-Kilborn Thank you very much.

  • How to compare & remove all multiple blocks of lines?

    4
    0 Votes
    4 Posts
    530 Views
    Dean-CorsoD

    Hi again,

    thanks for your help guys. So it seems to work using your method @Coises to set # or ## and to change all blocks into single lines. Very good idea and I think it did everything correctly so far on the first quick view.

    @Mark-Olson, just wanted to find & remove all double / multi blocks which are same. The 2 blocks I have posted above are not same so just double them etc. Otherwise the solution from @Coises works pretty well so far to manage & handle that problem for me and now I can merge all files I have into one single file and clean it up so that every block is only present once.

    PS: By the way, just have a small another question about that combination of commands. I would like to create a macro of it. Just wanna know whether I have to enter every single char again each time when I record the macro? I mean this for example “(?<!>)\R(?!<$)”. So what is if I have a larger amount of chars I need to use many times? Do I have to enter it again & again char by char etc?

  • Find and replace except if string contains charecter

    5
    1 Votes
    5 Posts
    298 Views
    Pinto IslamP

    @Coises
    This worked perfect. After I posted, I was doing similar steps, but turns out I put the () in the wrong place and wasn’t getting the right result. Appreciate your help.

  • How to open local git file in remote git in browser?

    4
    0 Votes
    4 Posts
    1k Views
    batagyB

    Okey, now I made it to work.

    Solution:

    Install git-url helper script, according to the readme in that.
    This is a bash script but runs also on Windows if Git Bash installed. Install NppExec plugin to Notepad++ Use below NppExec script , save it to a name like “OpenGitInBrowser” NPP_CONSOLE 0 NPE_CONSOLE v+ cd "$(CURRENT_DIRECTORY)" git url "$(FILE_NAME)" npp_run firefox "$(OUTPUT)#L$(CURRENT_LINE)" If you view or edit a file in git repo in Notepad++, press F6, select the above script, and done.

    It will jump to the actual line number in browser, in the given branch. This URL format is compatible with gitlab. Didn’t test with other git repo services,

    It runs hidden (no console opening for NppExec), and it takes some seconds because of bash script, bit working fine.

    :)

  • Can Letters Be Added to the Margin Along with Numbers?

    11
    0 Votes
    11 Posts
    759 Views
    Troglo37T

    @Alan-Kilborn Here’s a pic of the change log. I used Style one token to illustrate how the colors look. It’s turquoise when that line is clicked. Green when not clicked. Notepad++ Styles-Background.png

  • overwrite the stylers.xml file

    4
    0 Votes
    4 Posts
    510 Views
    PeterJonesP

    @DomOBU said in overwrite the stylers.xml file:

    I don’t see how I can manually edit the xml to find my current settings.
    That’s the drawback of the portable version

    If your portable notepad.exe is in c:\portable\npp\, then stylers.xml is at c:\portable\npp\stylers.xml .

    The config files location is documented in the online user manual at npp-user-manual.org . And that same user-manual page has the description of best-practices for editing Notepad++'s config files from within Notepad++.

  • 0 Votes
    11 Posts
    647 Views
    Alan KilbornA

    @Mark-Olson said:

    I came up with…

    Nice one.

    So then a unicode-ready replacement for the native command Remove Empty Lines (Containing Blank Characters) can be a macro, recorded as:

    Find: ^((?![\n\r])[\s\x{FEFF}])*\R
    Replace: nothing
    Search mode: Regular expression
    In selection: Checkmarked
    Action: Replace All

    I checkmark In selection because the original command can either run on the active selection or the entire file; for the macro it is a bit of a difference because to run on the entire file you’d have to Select All (Ctrl+a) first, but that’s not effort-intensive.

  • Change keybind of multi-edit to ctrl+alt+click

    3
    0 Votes
    3 Posts
    742 Views
    Alan KilbornA

    A feature request was made: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14611

    This is Scintilla behavior, not Notepad++ behavior. It would have to be made configurable via Scintilla before Notepad++ could apply it – thus, it should be a Scintilla feature request.

    EDIT: Well, the Notepad++ could choose to “go rogue” and “hack around” this aspect of Scintilla, like what was done to support “multi-editing” in Notepad++ 8.6 and later. But, I don’t see it happening.