notepad++ select hyphenated text

2020-02-28 03:16发布

I could'nt find a solution to a problem that has been hindering the use of notepad++.

When you double click text to highlight that text and others like it, camelCase or under_score words work great, but when hyphen-words-are-clicked this does not treat it as a single word and only highlights the segment between the "-".

question: how can you customize notepad++ so that hyphenated words are treated as single words? or does anyone know a text editor that does this?

saw this, but not sure how to implement it: http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Word_Customisation

this was really helpful: Where are the recorded macros stored in Notepad++?

7条回答
乱世女痞
2楼-- · 2020-02-28 03:45

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.

查看更多
劫难
3楼-- · 2020-02-28 03:46

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
查看更多
不美不萌又怎样
4楼-- · 2020-02-28 03:46

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 [ ,.].

查看更多
疯言疯语
5楼-- · 2020-02-28 03:52

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.

查看更多
冷血范
6楼-- · 2020-02-28 04:02

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");

查看更多
Deceive 欺骗
7楼-- · 2020-02-28 04:02

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!

查看更多
登录 后发表回答