File Specific word wrap (vs. global enable)

  • Is it possible to get a setting that allows word wrap to only wrap a single file?

    Here and there I find that I don’t CARE what is on the end of a long line of code, except in a file where I am validating a line. Selecting this ON makes ALL files word wrap, which for all the files that I do NOT care to see wrapped lines of code I have to deselect word wrap.

    Not a big deal, I should probably just set a keyboard shortcut, but I thought I would ask to see if there is any interest in adding this. Maybe it would become part of the right click menu for the file tab? This way you can easily tell the difference between word wrap for JUST a file and word wrap (global).

    Thanks for an awesome app!

  • Hello Dan-Rozwood ,

    if you want a semiautomated way doing it you can use python script plugin
    and this script

    # this is the callback function which get called
    def npp_callback_BUFFERACTIVATED(args):
        # check if the current document should be wrapped
        if editor.getProperty(args['bufferID']) == '1':
    # to prevent multiple callback registration per editor set a variable
    if editor.getProperty('callback_already_set') != '1':
        editor.setProperty('callback_already_set', '1')
        # this registers the callback function
        notepad.callback(npp_callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])
        # if run the second time callback gets cleared
        editor.setProperty('callback_already_set', '0')
    # get bufferid from current document
    current_bufferID = str(notepad.getCurrentBufferID())
    if editor.getProperty(current_bufferID) != '1':
        editor.setProperty(current_bufferID, '1')
        editor.setProperty(current_bufferID, '0')

    and if you modify the contextMenu.xml you can have the script listed in the mouse right click conext menu.
    I just added the line

    <Item PluginEntryName=“Python Script” PluginCommandItemName=“file_word_wrap” />

    at the end of the file.

    file_word_wrap is the name of the python script I created you can choose what ever you want.

    What does this script?
    It registers a callback function which gets called everytime you either open a new document or
    switch between documents.
    Then it checks if the current document, identified by its bufferID,
    is one which should get wordwrap enabled or not.
    The bufferID is retrieved when you execute the script and here there is a little drawback.

    If you want to have it set for multiple (but of course not all) files you need to run the script
    for every document. Which means you register multiple callbacks for the same purpose as
    each document gets an unique editor assigned.

    If you want to delete the wordwrap on a document, just run the script a second time.


  • Hi Dan , and Claudia,

    Up to now, the individual properties, memorized by Notepad++, in the Session.xml configuration file, for each file and each view, are the following :

    • File firstVisibleLine
    • xOffset
    • scrollWidth
    • startPos
    • endPos
    • selMode
    • lang
    • encoding
    • filename
    • backupFilePath
    • originalFileLastModifTimestamp

    So, Claudia, your Python script, seems valuable, to customize N++, for some other properties, than Word Wrap, which can, only, be set for all the opened files. I thinking of :

    • The show symbols

    • The line numbers margin

    • The bookmark margin

    • The vertical edge line

    • The smart highlighting

    • The zoom level

    • The text direction

    So, I’m wondering, if these properties could be set, as the Word Wrap one, individually, for few opened files, only ?

    For instance, the Python script command, for displaying the line numbers margin, should be :


    Not sure, Claudia, that is the exact syntax, anyway !!

    Best Regards,


  • Hi guy038,

    I disagree, the script is a global word wrap hack, correct, but it does what it was asking for. If you run this script on the opened document, only this document
    has the word wrap done. The other documents stay without having the word
    wrap done. It cannot be saved, not in the current state of it version, to survive
    a restart of npp but I can think of possible solutions to overcome this as well.
    Something like

    • create a file and store the status of the files which should have the word wrap
    • in, run code to load that file on npp startup.

    Just out of my mind, nothing tested but I strongly believe that it could be done.


  • Hi guy038,

    I missed this one

    So, I’m wondering, if these properties could be set, as the Word Wrap one, individually, for few opened files, only ?

    Yes, I assume this can be done. Let me check it and do some tests.

    and in regards to


    yes, only change first letter to be lowercase.


    then it will work. ;-)


    Btw. don’t know if you celebrate christmas, if so merry christmas ;-)

  • Hi Claudia,

    I’ve already understood, as you clearly explained, that your script :

    • allows to set the Word Wrap feature, for the current file A

    • allows to reset the Word Wrap feature for the same current file A, by running file_word_Wrap, a second time

    So, in my previous post, I shouldn’t have spoken about the Session.xml file, which stores some parameters, for each file of a session, for the next sessions to come. This behaviour is quite different from your script’s behaviour, of course and my post was a bit confusing :-(

    However, I do think that your script could be useful for other properties than the Word Wrap one !

    For instance, before sending a new post, I, generally, write it, first, in a text file, with N++. For these different text files, I usually don’t need the Line Numbers margin. So, it would be interesting, from time to time, to display the line numbers for one/two specific file(s), only :-)



    P.S. :

    I think that we replied to each other, simultaneously ! Thanks for your correction. And I’m rather glad for getting my first right command, in the Python Script help file !

    Have a look, again, at my post below. I added, in post-scriptum, the main differences between an Encoding and a Converting N++ action :

  • Hi guy038,

    thanks for the hint to the updated encoding thread. Hard work done ;-)

    Regarding the line number, book mark, folding columns I did some test
    and discovered a slight inconsistency here.
    Assuming you have checked

    • display line number
    • display bookmark
    • display folding (doesn’t exist, I know you are aware, it’s just for completeness and should mean is visible)

    you can hide bookmark and folding columns for different documents
    but you cannot hide line number column.
    There is a flickering so I assumed that either npp or a plugin
    checked the visibility state of that column.
    I started notepad with only python script plugin
    and issue still existed, so, I guess it’s npp itself.

    OK, this means we need to revert the conditions and
    assume nothing has been checked and the script
    makes it visibile on demand.
    This works - no problem, as long as you do
    not switch between tabs to fast.

    I will see what else can be made and will come back on this.


  • Hi guy038,

    here are some methods you were thinking about.

    Show Symbols

    • editor.setViewWS(1) # 0 to hide
    • editor.setViewEOL(1) # 0 to hide

    Margins (scintilla supports up to 5, npp uses only three 0, 1, 2)

    • line numbers
      editor.setMarginWidthN(0, 38) # standard value

    • bookmark margin
      editor.setMarginWidthN(1, 14) # standard value

    • folding margin
      editor.setMarginWidthN(2, 14) # standard value

    First parameter is the margin id (0,1,2) and second parameter means width in pixel.
    A second parameter being 0 hides the margin

    • line numbers
      editor.setMarginWidthN(0, 0)

    • bookmark margin
      editor.setMarginWidthN(1, 0)

    • folding margin
      editor.setMarginWidthN(2, 0)

    • Show Vertical edge line

    • Zoom level
      A positive number to increase font size, a negativ to decrease or 0 to reset to standard

    • Text direction
      notepad.menuCommand(MENUCOMMAND.RTL) # or MENUCOMMAND.LTR (left-to-right)

    • Indentation Guides
      editor.setIndentationGuides(1) # 0 to hide

    I didn’t found a MENUCOMMAND equivalent for smart highlighting, maybe this hasn’t been ported.

    A more generic version of the script.

    def func2call(i):
        if i == 1:
            editor.setWrapMode(1)                               # activate word wrap
            editor.setMarginWidthN(0,38)                        # show line number column
            editor.setMarginWidthN(1,14)                        # show bookmark column
            editor.setMarginWidthN(2,14)                        # show folding column
            # editor.setMarginWidthN(3,0)                         # not used or usage not found yet
            # editor.setMarginWidthN(4,0)                         # not used or usage not found yet
            editor.setViewWS(1)                                 # show whitespaces
            editor.setViewEOL(1)                                # show end of line chars
            editor.setIndentationGuides(1)                      # show indention guides
            editor.setZoom(+5)                                 # ZOOM
            notepad.menuCommand(MENUCOMMAND.VIEW_EDGELINE)      # show edge line
            notepad.menuCommand(MENUCOMMAND.EDIT_RTL)           # text right to left
    def npp_callback_BUFFERACTIVATED(args):
        if editor.getProperty(args['bufferID']) == '1':
    if editor.getProperty('callback_already_set') != '1':
        notepad.callback(npp_callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])
        editor.setProperty('callback_already_set', '1')
        editor.setProperty('callback_already_set', '0')
    current_bufferID = str(notepad.getCurrentBufferID())
    if editor.getProperty(current_bufferID) != '1':
        editor.setProperty(current_bufferID, '1')
        editor.setProperty(current_bufferID, '0')

    The margin columns seem to be special cases.
    One issue I had when trying to hide the line column
    even when setting to display has been enabled
    and another one is the folding column.
    It reapears if pixel width is set to 0 by
    switching to different document. Hmm … ???
    Assume that both are handled by npp and/or lexer as well.
    Will see if I can work around.


  • Hi Claudia,

    I’ve just installed the Python Script plugin, on the last v6.8.8 version and I tested your script, choosing successively a particular property : It worked nice !

    Of course, we get, from time to time, some weird effects. One example :

    I previously changed your script, in order to ONLY use the Word Wrap feature ( I put the other lines in comments )

    I suppose that the Word wrap is UNSET, on starting N++, and that it contains four opened tabs

    • Select tab #2 and run your script, then select tab #4 and run your script again. Well, if you select from tab #1 to #4, tabs #2 and #4 have the property Word wrap ENABLED and tabs #1 and #3 DON’T. Logical !

    • Then, click again on tab #2 and run your script => all the tabs seem to have the Word Wrap DISABLED ?

    • Finally, click, a last time, on tab #2 and run your script => Again the tab #2 ( as well as tab #4 !! ) have, again, the property Word Wrap ENABLED :-))

    There are some other cases like that. However, Claudia, it doesn’t matter. The main fact is that a displaying property, which is managed, on the whole, by N++, for all the opened files, can be set, with a Python script, individually, for 1 or few files ONLY :-))

    This valuable script may be useful, from time to time. Many thanks, for your “Python” work !



  • Hi guy038,

    your welcome but you are right, strange, need to dig deeper to see what happens there.
    Let’s see if we find the bug ;-)


  • Hello guy038,

    I guess I found the problem and a work around because
    I’m not 100% convinced of this solution.

    I did some additional console.write statement wihtin the code and found out,
    that the notepad callback needs to be set once only. Indeed it was the source of the
    problem as it seems that it has confused the python script plugin.

    So what needs to be done is to comment (or delete) the following lines

    # if editor.getProperty('callback_already_set') != '1':
        # editor.setProperty('callback_already_set', '1')
        # notepad.callback (npp_callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])
        # console.write('{0}\n'.format('callback registered'))
    # else:
        # notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
        # editor.setProperty('callback_already_set', '0')
        # console.write('{0}\n'.format('callback deleted'))

    and add the line before or afterwards the commented block.

    notepad.callback (npp_callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])

    The changes do have a drawback so, it means that the script doesn’t do the clearcallback anymore.
    Not sure if this is an issue but if so, you can always run


    from python script console or restart npp. ;-)


  • Hi Claudia,

    I tested your changed script. It woks great, indeed ! Referring to my last try, each time I ran this new version of your script, the state of the word wrap option, for the current file was changed into the opposite state, even, when using two simultaneous views !

    And, when running the command, below :


    In the Python console, I noticed that it sets the Word wrap state of the current document of each view, to all the opened documents of that associated view !

    Of course, after using the Python script, you can’t, seriously, rely on the visual appearance, of the Word Wrap button and/or the v indication, in menu View - Word wrap, as well as a click action, on this button/option !

    Just remember to use the Claudia script, exclusively, to get the right state of the Word Wrap ( or an other property ! ) that you want, for the current document !

    Thanks again, Claudia, for that nice Notepad++'s improvement !



    P.S :

    However, there’s, still, a limitation. For instance, if your create two ( almost ) identical scripts :

    • The first one, to modify a displaying property of the current document

    • The second one, to modify an OTHER property, of the current document

    The python script get confused and the properties can’t be set, simultaneously. Rather normal, however. We just have to be aware about this fact !

  • @Claudia-Frank 's FIRST Pythonscript in this thread really shines if the Wrap status is added to the status bar using the technique shown in the following thread: In that thread, the read-only status of the current file is shown (based upon a script in yet-another thread…sorry), but that can be modified to show the wrap status as follows:


    line_col_sel_info_for_sb = 'Ln : {user_line}     Col : {user_col}     Sel : {sel}     {ro}r'.format(
        ro='+' if editor.getReadOnly() else '-'


    line_col_sel_info_for_sb = 'Ln : {user_line}     Col : {user_col}     Sel : {sel}     {w}'.format(
        w='W' if editor.getWrapMode() == 1 else ''  # show 'W' in status bar if wrap mode is on for this file

  • Scott,

    don’t dig to deep to find my all of my youthful follies. ;-)


  • @Claudia-Frank

    Yea, I can tell that is earlier code from you, but it works!

  • I know this topic old but I tried the referenced solution and could not get it to work.
    I went to PLUGINS > PYTHON SCRIPT > NEW SCRIPT and saved the example code as file_word_wrap.

    I also added …
    <Item PluginEntryName=“Python Script” PluginCommandItemName=“file_word_wrap” />
    … at the bottom of contextMenu.xml as instructed but did not see it as a right-click option.

  • Hi @Clyfton-In , All:

    I also know that this topic is old, but tried today the python script and it worked fine for me.

    The following picture includes the relevant code and highlights the status bar zone that shows the requested info:



  • The Pythonscript is great and all, but this surely feels like something that should be offered as a feature in stock Notepad++. My 2c.

  • @Alan-Kilborn

    I think so. I also think that the regex indicators —not shown in my picture— are a nice and helpfull add-on.

  • @astrosofista said in File Specific word wrap (vs. global enable):

    regex indicators

    What “regex indicators” are you referring to? Did I miss something?

Log in to reply