Make tab key just insert 4 spaces, not insert 4 spaces AND move to the first char on the line
-
Let me see if I can describe in words.
1 - Assume I have a line with 8 spaces followed by some text starting at column 9. The cursor is at the head of the line.
2 - In both editors, when I press Tab, four spaces are inserted at the beginning of the line, and the text indents so it’s now starting at column 13.
3 - In Textpad, however, the cursor moves to the end of the newly inserted spaces (i.e. the head of column 5), whereas in NPP, the cursor moves to the text (i.e. the head of column 13).
I’d like the cursor to continue to stay at the end of the newly inserted spaces, and not jump to the beginning of the text.
-
That’s a very much better description.
I don’t think there’s a native way to make it do that.
It does the same thing in the Scintilla demo editor.
Scintilla is the editing component that Notepad++ embeds.
It could be a setting in Scintilla that I just don’t know about… -
Thank you for confirming. I just wanted to make sure I wasn’t missing something.
-
@Alan-Kilborn said in Make tab key just insert 4 spaces, not insert 4 spaces AND move to the first char on the line:
It could be a setting in Scintilla that I just don’t know about…
Agree the new explanation is much clearer and the setting seems to be:
SCI_SETTABINDENTS = 0
By default, N++ has it set to 1. In NppExec, I query it (SCI_GETTABINDENTS ) and it returns 1, but when I set it to 0 and perform the 8 spaces, character at column 9 test described above, I get a tab inserted and my cursor sits at column 4|5.
SCI_SENDMSG SCI_GETTABINDENTS ================ READY ================ ECHO $(MSG_RESULT) 1 ================ READY ================ SCI_SENDMSG SCI_SETTABINDENTS 0 ================ READY ================ SCI_SENDMSG SCI_GETTABINDENTS ================ READY ================ ECHO $(MSG_RESULT) 0
Now, assuming the pipe “|” is my cursor:
| there are 8 spaces before "there"
Press Tab:
| there are 8 spaces before "there"
So a scripting plugin (NppExec, PythonScript, “PerlScript”) could probably do this for you on startup.
Cheers.
-
@VTGroupGitHub
Sorry, forgot to “@” reference you in my previous reply. Also note Scintilla has the “opposite” behavior for going backwards. That is, when you press backspace it can backspace a single space at a time or backspace an entire tab stop. See the Scintilla Docs for what I mean. I’ve addedSCI_SETBACKSPACEUNINDENTS
in my NppExec startup.Cheers.
-
I hope it’s not too late to say thank you, but I just found your answer to my problem after over a year. Testing with the Console shows your solutions works perfectly, so I’ll set it up now to execute on startup. Thanks!
-
I need to resurrect this issue, as I realized today that the behavior has returned to what it was before my fix two years ago. I assume a recent NPP update changed something, and I need to improve my script. While I dig further, I thought I’d see if anyone knew immediately what needs to be done.
To summarize, I created the following script and added it to “Execute this script when Notepad++ starts”:
NPP_CONSOLE 0 SCI_SENDMSG SCI_SETTABINDENTS 0
This gave me the cursor-movement-after-inserting-a-tab behavior I was looking for. Even though nothing’s changed with my script, or the “Execute…” configuration, the cursor is going to the start of the text today.
Any help would be much appreciated.
-
A couple of updates. It does work as expected when creating and editing new files. So, the script must be running in that case on startup. And it also works on existing files, IF I manually run the script after opening the file. So the script is still doing the right thing, but something must be “undoing” the setting while opening new files?
For now, I’ve added a toolbar button that I’ll use to run the script if I really need this behavior (e.g. editing code), and dig deeper later.
-
Most likely, Notepad++ has started sending that message to scintilla internally (or is sending it more often than it used to). So you might need to trigger that sendmsg every time a buffer is activated. I don’t think NppExec can register actions on notifications, though I might misremember.
If you are willing to switch to PythonScript or similar, they do have the ability to hook notifications (using
notepad.callback(my_callback, [NOTIFICATION.BUFFERACTIVATED])
), so once you register that notification during the PythonScriptstartup.py
, then it will trigger that action every time you activate a different tab, so that any tab will always have SCI_SETTABINDENTS at 0. -
@PeterJones Thank you! I’ll give that a shot and report back when I’m done. I do already have Python Script installed, so hopefully it’ll be fairly straightforward.
-
This did work. Thank you again.
In case anyone else is interested, I added the following to “C:\Program Files\Notepad++\plugins\PythonScript\scripts\startup.py”:
def setTabs(arg): editor.setTabIndents(False) notepad.callback(setTabs, [NOTIFICATION.BUFFERACTIVATED])
-
This post is deleted!