Shortcut or button to toggle space or tab as subsequent indentation character in Notepad++?

4

4

I would like to have either a keyboard shortcut or a toolbar button that toggles if I use tabs (ie tab for indentation) or make notepad++ use spaces instead.

It would be a nice extra if a toolbar button could be added to toggle showing whitespace characters on/off, but no new lines.

Is this possible?

n611x007

Posted 2012-05-09T09:16:22.260

Reputation: 5 291

Answers

6

When toggling space/tabs for indentation, would you like the change to only apply to future indentation or all indents, including already existing ones?

To Convert All Existing Spaces to Tabs and Vice Versa

Hotkey: Settings -> Shortcut Mapper -> Main Menu and set hotkeys for the TAB to Space and vice options

Toolbar Button: Install plugin "Customize Toolbar" from Plugins -> Plugin Manager. After installation, Plugins -> Customize Toolbar -> Customize will allow you to add the "Tab to Space" and "Space to Tab" buttons

Toggle indentation character (space or tab) for subsequent indents

  • Install the Python Script plugin and from its menu, Create new script.
  • Choose a file name and save in the given directory
  • In the blank script file add: editor.setUseTabs(not editor.getUseTabs()) and save

From the Python Script -> Configuration menu:

Hotkey: Add a menu item and restart N++. From Shortcut Mapper -> Plugin Commands, set a shortcut for your toggle script.

Button: Add a button. Restart N++. If the toolbar button is not clickable, a conflict with the Customize Toolbar plugin is occuring, so you might have to remove that plugin. If there is a way to get Customize Toolbar and Python Script to add buttons to the toolbar simultaneously, I haven't found it.

Toggling Whitespace Character Visibility

Hotkey: Shortcut Mapper -> Main Menu -> "Show Whitespace and Tab" or

Set Hotkey and/or Toolbar Button for the following N++ Python Script:

# Toggle whitespace visibilty through the following modes
# 0: The normal display mode with white space displayed as an empty background colour
# 1: White space characters are drawn as dots and arrows
# 2: White space used for indentation is displayed normally but after the first visible character, it is shown as dots and arrows
# 
# Mode descriptions from http://www.scintilla.org/ScintillaDoc.html#SCI_GETVIEWWS

editor.setViewWS( (editor.getViewWS()+1)%3 )

protongun

Posted 2012-05-09T09:16:22.260

Reputation: 196

Nice work protongun. @naxa: I assume this is because it reloads the tab setting from the per-filetype setting (Settings > Preferences > Tab Settings > Filetype > Replace by space). Do you want a script which toggles this global setting? Might be the only way. – Nigel Touch – 2015-09-09T19:43:09.183

@NigelTouch it's a plausible theory, yes. I have no idea how to toggle the global 'replace by tab' setting, yet. – n611x007 – 2015-09-09T21:13:51.177

In Notepad++ how can I make a tab be displayed as an arrow instead of as 4 dots? – user3731622 – 2019-02-15T22:31:29.043

I've set a keyboard shortcut for the "subsequent_indents toggler", but every time I use it and then switch to another file tab and back, the setting is reset (without me doing anything). any ideas? – n611x007 – 2013-03-08T15:38:08.990