notepad++ select hyphenated text

只愿长相守 提交于 2019-11-30 11:50:42

Notepad++ rely on Scintilla for word selection. As caoanan noticed in his answer, Scintilla can be configured with the SCI_SETWORDCHARS variable. You can set this variable in Notepad++ with a simple NppExec script:

  1. Install NppExec
    • Menu Plugins -> plugin Manager -> Show Plugin Manager
    • locate NppExec, check the box and hit Install
  2. Create the script

    • Menu Plugins -> NppExec -> Execute ...
    • write this code (you can add other characters, like .$#@ at the end of the list):

      NPP_CONSOLE 0
      sci_sendmsg SCI_SETWORDCHARS 0 "CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
      
    • hit Save...
    • You can now execute it by pressing OK
  3. (optionnal) Execute when Notepad++ starts
    • Menu Plugins -> NppExec -> Advanced Options...
    • Choose your script in the Execute this script when Notepad++ starts drop down

I met with the same problem when editing Lisp/Scheme source codes with Notepad++.

The cure lies in the underlying Scintilla library (SciLexer.dll).

I've tried in a "blunt" way -- hack the code and rebuild SciLexer.dll.
Note the '-' added to the following code

CharClassify.cxx

void CharClassify::SetDefaultCharClasses(bool includeWordClass) {
    // Initialize all char classes to default values
    for (int ch = 0; ch < 256; ch++) {
        if (ch == '\r' || ch == '\n')
            charClass[ch] = ccNewLine;
        else if (ch < 0x20 || ch == ' ')
            charClass[ch] = ccSpace;
        else if (includeWordClass && (ch >= 0x80 || isalnum(ch) || ch == '_' || ch == '-'))
            charClass[ch] = ccWord;
        else
            charClass[ch] = ccPunctuation;
    }
}

Or, the "smart" way, as mentioned at ScintillaDoc.html

SCI_SETWORDCHARS(<unused>, const char *characters)

Scintilla has several functions that operate on words, which are defined to be contiguous sequences of characters from a particular set of characters. This message defines which characters are members of that set. The character sets are set to default values before processing this function. For example, if you don't allow '_' in your set of characters use: SCI_SETWORDCHARS(0,abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");

2018

I tried with the published solutions but when I move to another file I have to run the script again every time. So I did this way, in the menu:

Settings > Preferences > Delimiter

select:

  • Add you character as part of word

insert hyphen:

-

and it worked.

http://sourceforge.net/p/notepad-plus/discussion/1290590/thread/39ba5cd8/

Install Npp_Exec plugin and copy the string from this thread adding the signs you want Npp considers as part of a word.

I don't know that option in Notepad++ yet. Since, you've asked about any other text editor that does so, I would recommend you to use Sublime Text. It's a really cool text editor with lots of smart features. I bet you'll love it. By default, it does not treat the hyphenated words as a single word. But it's way too easy to customize the setting for that. All you need to do is go to 'Preference-> Setting-Default', where you'll find the following setting:

"word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}`~?",

From there, just remove the hyphen and we're done!

A workaround is to:

  • In the Find window, set the text to find to a space

  • In the Shortcut Mapper (Main Menu section) assign "Find Next" to Ctrl+Right and "Find Previous" to Ctrl+Left

Now, so long as the search text is only a space, it will effectively be the only delimiter. If you need other delimiters, for instance comma and period, set the Find text to [ ,.].

If you don't have admin rights and no Plugin Mgr, you can install most plugins by downloading a dll/zip file and saving the dll to the 'plugins' sub-folder under your npp install. Then restart npp.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!