Change the comment character in Sublime 2 for a specific syntax - sublimetext2

Sublime's Haml syntax uses // for comments when I hit cmd-/. I would like to override it use -# instead. How do I do that?

Which Haml package are you using in ST2?
Take a look inside this bundle ~/Library/Application Support/Sublime Text 2/Packages/Rails/Ruby Haml Comments.tmPreferences and change the // to -# i.e.:
Before
<string>TM_COMMENT_START</string>
<key>value</key>
<string>// </string>
After
<string>TM_COMMENT_START</string>
<key>value</key>
<string>-# </string>
This works if you are using the HAML bundle that is available via the ST2 package manager

Related

How to change View at revision editor in TortoiseHg?

I currently use TortoiseHg version 3.0.2
How to specify a custom editor for viewing at a specific revision?
Percisely, I would like to use SublimeText for it.
Edit the file
C:\Users\XXXXX\mercurial.ini
and add :
[tortoisehg]
editor = "C:\Program Files (x86)\Notepad++\Notepad++.exe" ["$FILE" -n$LINENUM] -multiInst -nosession
(this is when using notepad ++, for your case you have to put the path of sublime text

HTML indenting not working in compiled Vim 7.4, any ideas?

In trying to get vim to indent .html files properly, I followed the examples set out here.
Given the following file index.html:
<html>
<body>
<p>
text
</p>
</body>
</html>
I tried opening it like so (ignoring my .vimrc to make sure it isn't interfering negatively)
vim -u NONE index.html
Then I set the options to enable automatic indenting:
:filetype plugin indent on
:set filetype=html # abbrev - :set ft=html
:set smartindent # abbrev - :set si
And then I indented the entire file with gg=G, and this is the result:
<html>
<body>
<p>
text
</p>
</body>
</html>
I checked to make sure that the html.vim file existed, and it's definitely there
$ head -2 ~/.vim/after/ftplugin/html.vim
" Vim syntax file
" Language: HTML
$ head -2 ~/.vim/ftplugin/html.vim
" Vim syntax file
" Language: HTML
My version of vim is 7.4:
$ vim --version | head -1
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep 23 2013 16:12:20)
And it includes smart indent:
$ vim --version | grep smartindent
-ebcdic +mouse +smartindent +xim
I'm at a loss as to why the indentation isn't working! Any clues or ideas to research this problem further?
FWIW, I'm running Ubuntu 13.04.
As mentioned in Cory's answer, the currently distributed version is Vimscript 2075. If you go to that plugin page you can see documented all the tags that by default will increase indent.
None of the tags you gave in your example are in this default list, but there are plenty of them.
Since indentation of HTML is very open to user preference, the plugin maintainer has included an option to add or remove tags to or from the list of tags that increases indent. See :help html-indent, where it suggests:
You can add further tags with:
:let g:html_indent_inctags = "html,body,head,tbody"
Between versions 7.3 and 7.4, the bundled html.vim file located in $VIMRUNTIME/indent changed. The currently distributed version is actually Vimscript #2075, and it doesn't indent some html tags by default.
I recommend Ben's solution above, but alternatively you can revert to a previous version of the distributed html.vim file.
To do this, just replace the existing 7.4 html.vim file with the one from 7.3.
wget ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2
tar jxf vim-7.3.tar.bz2
cp vim73/runtime/indent/html.vim ~/.vim/indent/
As of 7.4.52
within vim:
:let g:html_indent_inctags = "html,body,head,tbody"
:call HtmlIndent_CheckUserSettings()
else in .vimrc:
let g:html_indent_inctags = "html,body,head,tbody"
I wanted to just to add this to a comment on the top answer, to give back, after spending too much time not getting the answer to work, but apparently don't have enough reputation :(
The first troubleshooting step is to run :scriptnames. If you don't see .../indent/html.vim, then that means the plugin is not loaded correctly and indenting won't work properly. It will probably just left indent every line. (The problem is that vim doesn't give an error, so it seems like the indenting is doing an awful job.)
The most reliable way to get it working is to put this line in your ~/.vimrc.
filetype plugin indent on
Then open the file with vim again, and run :scriptnames. You should see .../indent/html.vim now. Then type gg=G to autoformat the entire file.
One important note that tripped me up for a while: If you don't put it in ~/.vimrc and just type :filetype plugin indent on after you've opened the file, you will have to re-open the file again with :e. The indent plugin has to be loaded before you open the file. Run :scriptnames to confirm.
Side note: you don't need to worry about smartindent or autoindent settings, those are for something else.

Sweave syntax highlighting for Sublime Text

Currently Sublime Text 2 with installed LaTeXTools bundle stumbles over Sweave/knitr code blocks. How can I tell ST to either ignore everything of the form
<<arguments here>>=
#
or, even better, to treat it as R source code?
The Sweave Textmate bundle (or at least the essential parts) will also work with Sublime Text 2. Just download the bundle from https://github.com/textmate/sweave.tmbundle and move it to the Packages directory.
There's now the SublimeKnitr bundle that's made specifically made for Sublime Text. Install from GitHub source or via Package Control.

Set default syntax to different filetype in Sublime Text 2

How do I set a default filetype for a certain file extension in Sublime Text 2? Specifically I want to have *.cfg files default to having Ini syntax highlighting but I cannot seem to figure out how I could create this custom setting.
In the current version of Sublime Text 2 (Build: 2139), you can set the syntax for all files of a certain file extension using an option in the menu bar. Open a file with the extension you want to set a default for and navigate through the following menus: View -> Syntax -> Open all with current extension as... ->[your syntax choice].
Updated 2012-06-28: Recent builds of Sublime Text 2 (at least since Build 2181) have allowed the syntax to be set by clicking the current syntax type in the lower right corner of the window. This will open the syntax selection menu with the option to Open all with current extension as... at the top of the menu.
Updated 2016-04-19: As of now, this also works for Sublime Text 3.
Go to a Packages/User, create (or edit) a .sublime-settings file named after the Syntax where you want to add the extensions, Ini.sublime-settings in your case, then write there something like this:
{
"extensions":["cfg"]
}
And then restart Sublime Text
In ST2 there's a package you can install called Default FileType which does just that.
More info here.
You can turn on syntax highlighting based on the contents of the file.
For example, my Makefiles regardless of their extension the first line as follows:
#-*-Makefile-*- vim:syntax=make
This is typical practice for other editors such as vim.
However, for this to work you need to modify the
Makefile.tmLanguage file.
Find the file (for Sublime Text 3 in Ubuntu) at:
/opt/sublime_text/Packages/Makefile.sublime-package
Note, that is really a zip file. Copy it, rename with .zip at the end, and extract the Makefile.tmLanguage file from it.
Edit the new Makefile.tmLanguage by adding the "firstLineMatch" key and string after the "fileTypes" section. In the example below, the last two lines are new (should be added by you). The <string> section holds the regular expression, that will enable syntax highlighting for the files that match the first line. This expression recognizes two patterns: "-*-Makefile-*-" and "vim:syntax=make".
...
<key>fileTypes</key>
<array>
<string>GNUmakefile</string>
<string>makefile</string>
<string>Makefile</string>
<string>OCamlMakefile</string>
<string>make</string>
</array>
<key>firstLineMatch</key>
<string>^#\s*-\*-Makefile-\*-|^#.*\s*vim:syntax=make</string>
Place the modified Makefile.tmLanguage in the User settings directory:
~/.config/sublime-text-3/Packages/User/Makefile.tmLanguage
All the files matching the first line rule should turn the syntax highlighting on when opened.
The best solution for me turned out to be to used the ApplySyntax package.
The steps are as follows:
Install the package via Package Control
CTRL + SHIFT + P and enter ApplySyntax: Browse Syntaxes. Find your desired syntax here and note the exact line shown, e.g. I was looking to set it to Markdown from the Markdown Editing package, so for me the line was MarkdownEditing/syntaxes/Markdown.
CTRL + SHIFT + P and enter ApplySyntax: Settings.
On line "new_file_syntax": "XYZ", enter the line from Step 2.
See here for further documentation.
I found this to work better than the DefaultFileType package, because it isn't limited to just new files created by pressing CTRL + N and captured new tabs opened by clicking the empty space to the right of an open tab.
I hope is useful to someone 11 years after the original question was asked. 😅

Formatting code in Notepad++

Is there a keyboard shortcut to format code in Notepad++ ?
I'm mainly working with HTML, CSS and Python code.
For example:
<title>{% block title %} {% endblock %}</title>
<link rel="stylesheet" href="/media/style.css" type="text/css" media="screen" />
</head>
To:
<head>
<title>
{% block title %}
{% endblock %}
</title>
<link rel="stylesheet" href="/media/style.css" type="text/css" media="screen" />
</head>
I remember Visual Studio doing it with Ctrl+K+D and NetBeans having the feature too but can't find it within Notepad++, if it can even do it.
TextFX -> HTML Tidy -> Tidy: Reindent XML
Remember to have the HTML code selected before you do this.
there is such a plugin as UniversalIndentGUI, it can be installed right from the plugin manager and has possibilities to reindent the most used programming languages.
If you go to TextFX menu and go to TextFX Edit, you will see a menu item Reindent C++ Code.
That will also format C# code.
ANSWER AS OF June 2019
Install the XML Tools plugin from the Plugin Admin (in Notepad++ 7.7 at least)
Then click Plugins -> XML Tools -> Pretty Print (XML Only with Line breaks)
That did it for me.
Here is a list of the available shortcuts in Notepad++.
In case your desired functionality is not available, you are able to define own macros and assign them to a custom shortcut (i am not used to use macros).
UPDATE: I will post the shortcuts here in case the link gets invalid:
Shortcut Command
Ctrl-C Copy
Ctrl-X Cut
Ctrl-V Paste
Ctrl-Z Undo
Ctrl-Y Redo
Ctrl-A Select All
Ctrl-F Launch Find Dialog
Ctrl-H Launch Find / Replace Dialog
Ctrl-D Duplicate Current Line
Ctrl-L Delete Current Line
Ctrl-T Switch the current line position with the previous line position
F3 Find Next
Shft-F3 Find Previous
Ctrl-Shft-F Find in Files
Ctrl-F3 Find (volatil) Next
Ctrl-Shft-F3 Find (volatil) Previous
Ctrl-Shft-I Incremental Search
Ctrl-S Save File
Ctrl-Alt-S Save As
Ctrl-Shft-S Save All
Ctrl-O Open File
Ctrl-N New File
Ctrl-F2 Toggle Bookmark
F2 Go To Next Bookmark
Shft-F2 Go To Previous Bookmark
Ctrl-G Launch GoToLine Dialog
Ctrl-W Close Current Document
Alt-Shft-Arrow keys or Alt + Left mouse click Column Mode Select
F5 Launch Run Dialog
Ctrl-Space Launch CallTip ListBox
Alt-Space Launch Word Completion ListBox
Tab (selection of several lines) Insert Tabulation or Space (Indent)
Shft-Tab (selection of several lines) Remove Tabulation or Space (outdent)
Ctrl-(Keypad-/Keypad+) or Ctrl + mouse wheel butto Zoom in (+ or up) and Zoom out (- or down)
Ctrl-Keypad/ Restore the original size from zoom
F11 Toggle Full Screen Mode
Ctrl-Tab Next Document
Ctrl-Shft-Tab Previous Document
Ctrl-Shft-Up Move Current Line Up
Ctrl-Shft-Down Move Current Line Down
Ctrl-Alt-F Collapse the Current Level
Ctrl-Alt-Shft-F Uncollapse the Current Level
Alt-0 Fold All
Alt-(1~8) Collapse the Level (1~8)
Alt-Shft-0 Unfold All
Alt-Shft-(1~8) Uncollapse the Level (1~8)
Ctrl-BackSpace Delete to start of word
Ctrl-Delete Delete to end of word
Ctrl-Shft-BackSpace Delete to start of line
Ctrl-Shft-Delete Delete to end of line
Ctrl-U Convert to lower case
Ctrl-Shft-U Convert to UPPER CASE
Ctrl-B Go to matching brace
Ctrl-Shft-R Start to record /Stop recording the macro
Ctrl-Shft-P Play recorded macro
Ctrl-Q Block comment/uncomment
Ctrl-Shft-Q Stream comment
Ctrl-Shft-T Copy current line to clipboard
Ctrl-P Print
Alt-F4 Exit
Ctrl-I Split Lines
Ctrl-J Join Lines
Ctrl-Alt-R Text Direction RTL
Ctrl-Alt-L Text Direction LT
F1 About
The latest plugin is tidy2, which can be installed through Plugins>Plugin Manager>Show Plugin Manager.
I suggest editing config 1 and setting quote-marks: no, especially if you have script that makes use of quotes.
Also, tidying more than once can result in inserting ampersands the first time and then replacing the ampersands the second time. You may want to play with the config to get it to where you need it.
For JavaScript Formatting I use Notepad ++ JSMin Plugin.Quite Handy
This isn't quite the answer you were looking for, but it's the solution I came to when I had the same question.
[update - I'm using vscode now for everything. I think it works better in a lot of cases.]
I'm a pretty serious Notepad++ user, so don't take this the wrong way. I have started using NetBeans 8 to develop websites in addition to Notepad++ because you can set it to autoformat on save for all your languages, and there are a ton of configuration options for how the formatting looks, down to the most minute detail. You might look into it and find it is a worthy tool to use in conjunction with notepad++. It's also open source, completely free, and has a bunch of plugins and other useful things like automatically compiling Sass if you use that too. It's definitely not as quick as NP++ so it's not great for small edits, but it can be nice for a long coding session.
In my notepad++, it seems TextFX needs a perl environment to format HTML files. Tidy2 demands nothing so I think it's more handy.
If all you need is alignment, try the plugin called Code Alignment.
You can get it from the built-in plugin manager in Notepad++.
We can use the following shortcut in the latest version of notepad++ for formatting the code
Alt + Ctrl + Shift + B
In Plugins > Plugin Admin > Search 'XML Tools' > Install.
The window will restart and install XML Tools under plugins.
Open your file and click Ctrl + Alt + Shift + B
No. Notepad++ can't format by itself. Formatting can easily be accomplished in many IDEs like Eclipse, NetBeans, Visual Studio [Code].
Another Potential Solution
Okay, so it's been 12 years since this question was asked. I think that I've found a another acceptable solution, that is perhaps better for formatting files, using Prettier.
What is Prettier?
Prettier is described as: "an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary."
Prettier Supports the Following Languages
HTML
CSS, Less, and SCSS
JavaScript
TypeScript
JSX, Angular, Vue
JSON, Markdown, YAML
And a few others.
If You Want to Use Other Languages, You Can Either Use:
Plugins made by the community to Prettier, which allow support for other formats such: Java, Rust, PHP, SQL, and others.
Non-Prettier formatters supporting other languages such as clang-format (npm version) (C / C++ / Java / JavaScript / JSON / Objective-C / Protobuf / C#), or Black (Python).
How To Install
You're going to need to install Node.js for this tutorial.
Note: There may be other work arounds for using the subsequent
mentioned software without using Node.js. But to keep this tutorial
simple and the fact that Node.js already carries widespread
familiarity among developers, I'm going to be using this software
without explaining how to install it.
After installing Node.js, install prettier globally to your system, allowing yourself to run prettier anywhere from the command line.
# NPM is the package manager used by Node.js
# And --global allows you to use prettier anywhere on your local computer.
npm install --global prettier
# To install other plugins (example):
npm install --g prettier-plugin-rust prettier-plugin-java
# To Install clang-format using NPM
npm install -g clang-format
# Usage Examples
prettier --write jquery-min.js # Formatting a JavaScript file
clang-format -i Test.cpp # Formatting C++ file
On Notepad++, install a plugin called NppExec from Menu> Plugins Admin...> Available> NppExec.
You can now run NppExec by either pressing F6 or by clicking Menu > Plugins > NppExec > Execute NppExec Script...
Now you should have a window pop up, giving you the option of executing a command.
You can either use prettier on a (1) specific file or (2) all files in a folder or (3) all files in a directory recursively.
You can always reload a file after it's better overwritten by Prettier using Ctrl+R, and enabling the following setting: Menu > MISC. > Update silently.
Commands and Screenshots of NppExec + Prettier.
REM Using Prettier on Current File (use cmd or powershell /c)
cmd /c prettier --write "$(FULL_CURRENT_PATH)"
REM Using Prettier on Current Folder (a single asterisk)
pwsh /c prettier --write "$(CURRENT_DIRECTORY)\*"
REM Using Prettier on Current Directory Recursively (double asterisk)
pwsh /c prettier --write "$(CURRENT_DIRECTORY)\**"
Install NppExec Plugin
Running NppExec Plugin
Executing Commands on NppExec
NPP+ v7.9.1 with the latest version of XMLTools can't format exported VBA code from Office 2016/2019 Word. It puts all the code on the same line since it strips the CRLF out. Moreover, when you enable "auto validation" it errors out on the first VBA line that is, Attribute VB_Name = "The VBA module name". So any of the xml tool validations apparently can't be used for VBA validation.