Auto-indentation is a cool feature in notepad++ 5.1.x but I think it could be improved.
For years, I'm dreaming of auto-indentation in xml, html and css in notepad++.
For example, if I type "<Item>", I would not only like that the tag auto-close but also to insert 2 newlines between the opening and closing tag and an indentation on the second line. So as soon as I type ">"
I'll get :
<Item>
| (The cursor here)
<Item>
The same behavior could be applied to css, c#, c++,... delimiters "{ }".
It would save a lot of time... We can find such behaviors in some big IDE such as Visual Studio, but I would really like to have them in a light editor.
If you want to do even better, I propose to implements such actions as Rules.
A pseudo-example of rule could be : if the user type "{" in a css document then the action described above will be applied.
Notepad++ could have some rules by default and the user could also add its own rules.
What do you think about this proposition ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It doesn't work because the hotstring ':*b0:>>::' is acting as a hotkey and when you type '>>' instead of typing the hotstring it executes the code under itself
No it doesn't. It throws an error. I would like the code under to be executed... What should I change to make it work ?
prozaker, thank you for you code, but I don't succeed to make it work. I've created a .css file, opened it in npp and typed "{" or "bd" but nothing happened.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not exactly because you have to use a shortcuts for that. I want this to be automatic. Moreover I don't understand how macro work. I click recording, then I do the modifications I need, then I click on stop. But I cannot save the macro and replay it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There's a plugin that helps with writing html code in the Notepad++ Plugins project. I don't remember if it was in the TextFX plugin, or another HTML-specific plugin, but it had an option to automatically add the closing tag immediately after the cursor when you closed the first tag. You can try contacting the author of that plugin to see if he is willing to implement the rest of your suggestion.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
you can also try autohotkey, it's a program that can make 'hotstrings' and describes pretty much what you are saying.
I have my braces autogenerated, on my css files, and most of my html tags on my html files
for example I have :*:<ta::<table width="100%" cellpadding="0" style="border-collapse:collapse;">`n`t<tr>`n`t<td>`n`n</td>`n{backspace}</tr>`n{backspace}</table>{up 3}`t
I've downloaded autohotkey and trying to execute your script but I get an error when trying to load it. It says : "invalid hotkey". are you sure you give the exact script you use ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
» Are you sure you give the exact script you use ?
The script prozaker wrote, works fine.
» It says : "invalid hotkey".
Yes, Autohotkey spit such messages (even if the code seems to be ok), because everything is written on the same line. In Autohotkey, a good way of coding is to type the commands beneath the hotstring/hotkey (even if the commands are shorter)
; type this to have the script running permanently
#persistent
» IfWinActive, % - Notepad++ and regexmatch(WinGetTitle, ".+\xml - Notepad++")
» But it doesn't work. Di you know why ?
• Well, WinGetTitle used this way always yields NOTHING (""). You must specify a variable to keep the winTitle and after that use this variable in RegExMatch function.
• If I've got you right, the hotstring should be fired only if Npp is active and the current document is *.xml. If so the NeedleRegEx is typed badly. I mean what about if we have extension like *.XML or if document's title is for example "blabla.xml - Notepad++.lms". IMHO we need only the end of the document title to be a match.
Possible solution:
:*b0:<ta::
; b0 instructs Autohotkey to disable automatic backspacing
; this command is needed because the hotstring is fired
; always when you type "<ta" and will autoreplace "<ta" with
; nothing if there's no match
IfWinActive, ahk_class Notepad++
{
WinGetTitle, NppTitle
if RegExMatch(NppTitle, "i)\.xml - Notepad\+\+$")
sendinput, ble width="100`%" cellpadding="0" style="border-collapse:collapse;">`n`t<tr>`n`t<td>`n`n</td>`n{backspace}</tr>`n{backspace}</table>{up 3}`t
}
; You can also use #IfWinActive directive to enable the hotstring
; only when Npp is active...
return
LMS_RampagE
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It doesn't work because the hotstring ':*b0:>>::' is acting as a hotkey and when you type '>>' instead of typing the hotstring it executes the code under itself
:*b0:>>::
ifWinActive, ahk_class Notepad++
{
WinGetTitle, NppTitle
if RegExMatch(NppTitle, "i)\.xml - Notepad\+\+$")
{
; at that position Autohotkey expects some command
;but gets only a string
; You should use something like sendinput
; it is the same as :*b0:>>::>`n`n{backspace}{up 1}`t
; but is executed in if statement
SendInput, >`n`n{backspace}{up 1}`t ;{right 3}
}
}
return
» Why do you use i) in the regular expression ?
I used it because the 'i' flag stands for Case-insensitive matching. I mean if you don't type "i)" in a "\.xml - Notepad\+\+$" , when you open document with extension *.XML it won't be a match and the hotstirng won't fire. IMO it should work with lower/upper/mixed letters in the extension.
Cheers,
LMS_RampagE
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It doesn't work because the hotstring ':*b0:>>::' is acting as a hotkey and when you type '>>' instead of typing the hotstring it executes the code under itself
No it doesn't. It throws an error. I would like the code under to be executed... What should I change to make it work ?
prozaker, thank you for you code, but I don't succeed to make it work. I've created a .css file, opened it in npp and typed "{" or "bd" but nothing happened.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello
Auto-indentation is a cool feature in notepad++ 5.1.x but I think it could be improved.
For years, I'm dreaming of auto-indentation in xml, html and css in notepad++.
For example, if I type "<Item>", I would not only like that the tag auto-close but also to insert 2 newlines between the opening and closing tag and an indentation on the second line. So as soon as I type ">"
I'll get :
<Item>
| (The cursor here)
<Item>
The same behavior could be applied to css, c#, c++,... delimiters "{ }".
It would save a lot of time... We can find such behaviors in some big IDE such as Visual Studio, but I would really like to have them in a light editor.
If you want to do even better, I propose to implements such actions as Rules.
A pseudo-example of rule could be : if the user type "{" in a css document then the action described above will be applied.
Notepad++ could have some rules by default and the user could also add its own rules.
What do you think about this proposition ?
It doesn't work because the hotstring ':*b0:>>::' is acting as a hotkey and when you type '>>' instead of typing the hotstring it executes the code under itself
No it doesn't. It throws an error. I would like the code under to be executed... What should I change to make it work ?
prozaker, thank you for you code, but I don't succeed to make it work. I've created a .css file, opened it in npp and typed "{" or "bd" but nothing happened.
Sounds like you need to create a macro to do this behaviour for you.
Not exactly because you have to use a shortcuts for that. I want this to be automatic. Moreover I don't understand how macro work. I click recording, then I do the modifications I need, then I click on stop. But I cannot save the macro and replay it.
Hi, have you tried the QuickText plugin?
http://notepad-plus.wiki.sourceforge.net/QuickText+HowTo
For version 5.1.3 Unicode you can find the source and the dll in this thread: http://sourceforge.net/forum/forum.php?thread_id=2579444&forum_id=482781
Also look at this: http://sourceforge.net/forum/forum.php?thread_id=2819810&forum_id=482781
There's a plugin that helps with writing html code in the Notepad++ Plugins project. I don't remember if it was in the TextFX plugin, or another HTML-specific plugin, but it had an option to automatically add the closing tag immediately after the cursor when you closed the first tag. You can try contacting the author of that plugin to see if he is willing to implement the rest of your suggestion.
you can also try autohotkey, it's a program that can make 'hotstrings' and describes pretty much what you are saying.
I have my braces autogenerated, on my css files, and most of my html tags on my html files
for example I have :*:<ta::<table width="100%" cellpadding="0" style="border-collapse:collapse;">`n`t<tr>`n`t<td>`n`n</td>`n{backspace}</tr>`n{backspace}</table>{up 3}`t
which writes as soon as I type <ta
<table width="100%" cellpadding="0" style="border-collapse:collapse;">
<tr>
<td>
</td>
</tr>
</table>
Thank you prozaker.
I've downloaded autohotkey and trying to execute your script but I get an error when trying to load it. It says : "invalid hotkey". are you sure you give the exact script you use ?
» Are you sure you give the exact script you use ?
The script prozaker wrote, works fine.
» It says : "invalid hotkey".
Yes, Autohotkey spit such messages (even if the code seems to be ok), because everything is written on the same line. In Autohotkey, a good way of coding is to type the commands beneath the hotstring/hotkey (even if the commands are shorter)
; type this to have the script running permanently
#persistent
:*:<ta::
<table width="100%" cellpadding="0" style="border-collapse:collapse;">`n`t<tr>`n`t<td>`n`n</td>`n{backspace}</tr>`n{backspace}</table>{up 3}`t
return
; save it and run it
After that open your favorite text editor (Npp ofc :-|\) and type
<ta. It should look like:
<table width="100%" cellpadding="0" style="border-collapse:collapse;">
<tr>
<td>
</td>
</tr>
</table>
Cheers,
LMS_RampagE
Ok it works. But now I want this script only in npp. I try adding this around it :
IfWinActive, % - Notepad++ and regexmatch(WinGetTitle, ".+\xml - Notepad++")
{
}
But it doesn't work. Di you know why ?
Which other actions do you use with this tool ? Is it possible to have a shortcut wor browsing next/previous directory in the windows explorer ?
let me check my script as i have it only for css files. ill post it tomorrow
» IfWinActive, % - Notepad++ and regexmatch(WinGetTitle, ".+\xml - Notepad++")
» But it doesn't work. Di you know why ?
• Well, WinGetTitle used this way always yields NOTHING (""). You must specify a variable to keep the winTitle and after that use this variable in RegExMatch function.
• If I've got you right, the hotstring should be fired only if Npp is active and the current document is *.xml. If so the NeedleRegEx is typed badly. I mean what about if we have extension like *.XML or if document's title is for example "blabla.xml - Notepad++.lms". IMHO we need only the end of the document title to be a match.
Possible solution:
:*b0:<ta::
; b0 instructs Autohotkey to disable automatic backspacing
; this command is needed because the hotstring is fired
; always when you type "<ta" and will autoreplace "<ta" with
; nothing if there's no match
IfWinActive, ahk_class Notepad++
{
WinGetTitle, NppTitle
if RegExMatch(NppTitle, "i)\.xml - Notepad\+\+$")
sendinput, ble width="100`%" cellpadding="0" style="border-collapse:collapse;">`n`t<tr>`n`t<td>`n`n</td>`n{backspace}</tr>`n{backspace}</table>{up 3}`t
}
; You can also use #IfWinActive directive to enable the hotstring
; only when Npp is active...
return
LMS_RampagE
> Is it possible to have a shortcut wor browsing next/previous directory in the windows explorer ?
What about Alt+Left/Right? :-)
I change the script to :
:*b0:>>::
IfWinActive, ahk_class Notepad++
{
WinGetTitle, NppTitle
if RegExMatch(NppTitle, "i)\.xml - Notepad\+\+$")
{
>`n`n{backspace}{up 1}`t
}
}
return
but it doesn't work. The message is :
This line doesn't contains a recognize action. Do you know why ?
Why do you use i) in the regular expression ?
It doesn't work because the hotstring ':*b0:>>::' is acting as a hotkey and when you type '>>' instead of typing the hotstring it executes the code under itself
:*b0:>>::
ifWinActive, ahk_class Notepad++
{
WinGetTitle, NppTitle
if RegExMatch(NppTitle, "i)\.xml - Notepad\+\+$")
{
; at that position Autohotkey expects some command
;but gets only a string
; You should use something like sendinput
; it is the same as :*b0:>>::>`n`n{backspace}{up 1}`t
; but is executed in if statement
SendInput, >`n`n{backspace}{up 1}`t ;{right 3}
}
}
return
» Why do you use i) in the regular expression ?
I used it because the 'i' flag stands for Case-insensitive matching. I mean if you don't type "i)" in a "\.xml - Notepad\+\+$" , when you open document with extension *.XML it won't be a match and the hotstirng won't fire. IMO it should work with lower/upper/mixed letters in the extension.
Cheers,
LMS_RampagE
I change the script to :
:*b0:>>::
IfWinActive, ahk_class Notepad++
{
WinGetTitle, NppTitle
if RegExMatch(NppTitle, "i)\.xml - Notepad\+\+$")
{
>`n`n{backspace}{up 1}`t
}
}
return
but it doesn't work. The message is :
This line doesn't contains a recognize action. Do you know why ?
Why do you use i) in the regular expression ?
this is the top part of my script you should be able to modify it to your needs.
;Lines that start with a
;semicolon, such as this one, are comments. They are not executed.
SetTitleMatchMode RegEx
#IfWinActive, .css - Notepad\+\+
:?*:{::
Sendinput, {{}`n`n{}}{up}`t
Return
#IfWinActive, .Message
::bd::
Sendinput, Buen día{space}
Return
SetTitleMatchMode 2
#IfWinActive, ahk_class gdkWindowToplevel
:?c*:nN::
Sendinput, {Ctrl Down}{Shift Down}u{Shift Up}{Ctrl Up}00f1{space}
Return
#IfWinActive
:?c*:nN::ñ
;============== basic html strings ==========
:*:<html::`t<{!}DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">`n<html xmlns="http://www.w3.org/1999/xhtml">`n<head>`n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />`n<title>Editme</title>`n<link href="css/main.css" rel="stylesheet" type="text/css" />`n</head>`n`n<body>`n`n</body>`n</html>{up 2}`t
I change the script to :
:*b0:>>::
IfWinActive, ahk_class Notepad++
{
WinGetTitle, NppTitle
if RegExMatch(NppTitle, "i)\.xml - Notepad\+\+$")
{
>`n`n{backspace}{up 1}`t
}
}
return
but it doesn't work. The message is :
This line doesn't contains a recognize action. Do you know why ?
Why do you use i) in the regular expression ?
Check this:
http://sourceforge.net/forum/message.php?msg_id=6113826
LMS_RampagE
It doesn't work because the hotstring ':*b0:>>::' is acting as a hotkey and when you type '>>' instead of typing the hotstring it executes the code under itself
No it doesn't. It throws an error. I would like the code under to be executed... What should I change to make it work ?
prozaker, thank you for you code, but I don't succeed to make it work. I've created a .css file, opened it in npp and typed "{" or "bd" but nothing happened.