Sublime text 3 not recognizing html files when using templates - sublimetext3

Can't seem to find the exact problem elsewhere...
Basically in my html file at the top I have:
<%inherit file="base.html"/>
This proceeds to screw up all the highlighting in the file and also confuses the commenting shortcut.
This:
Changes into this:

Found the issue. Wasn't aware that this was using Mako as the templating system rather than a more well known one. This package allows you to set the syntax at HTML(Mako)
https://github.com/OmeGak/sublime-text-user-settings

The problem is <%blabla> and </%blabla> are not considered closed.
I'm using a workaround like this: line 4 will close line 1
1 <%block name="content">
2 <%
3 #
4 %>
5 <div>
6 Syntax highlight as before. Emmet works too.
7 </div>
8 </%block>

Related

Django if statement with beginning tag in conditional breaking next div

I have the following code in a file in my template folder
{% if permission <= 4 %}
<div class='row'>
The < in my conditional is breaking my next div.
If I use > then it works but that's not how I have my permissions and I don't want to switch it around.
vim detects a break in this conditional by changing the color and the template never loads the div even though the conditional is true.
Session output:
('permission', 0)])
I feel like I'm missing something simple but I can't quite get my search strings to give me what I am looking for.
Someone helped me here: https://forum.djangoproject.com/t/conditional-conflict-in-template-with-following-div/14476
I got distracted by the VIM error and went in the wrong direction.
I changed 'permission' to 'request.session.permission' and it works now.

Sublime Text 3 Search and Replace Project Using Regex

I'm using Sublime Text 3 on Ubuntu 18.04. I need to do a Search and Replace across 100+ pages in a project directory. I'd like to do this with a regex, if possible, but I cannot figure out how to do it.
I want to find tabindex="nbr" where nbr is an actual number. I.e: tabindex="2". I want to replace every instance with tabindex="0".
I've tried this:
Find: tabindex="\d"
Where: /home/me/path/to/project/
Replace: tabindex="0"
But this does not work. I get a 0 matches found pop up. I've tried other regex's with the same 0 matches found message.
This has to be easier than I am making it.
Thanks for any advice.

How to jump to beginning of Tag in HTML vim which has long html content

Following is code
<p>
Some Content
Some Content
My Cursor is here
Some Content
Some Content
</p>
How do I directly Jump to beginning of Tag <p> or </p>
% command needs your cursor to be on tag, I tried other based on 10G. I cant expect number to visible all time.
I think there might be some smarter way to do this.
Using key sequence vatoESC will do it.
Check out the answer here: https://stackoverflow.com/a/10881471/5039312
If you’re open to using a plugin, I use this: https://github.com/tmhedberg/matchit

PhpStorm new line in HTML replace

For over a year I have been trying to do the simplest thing - do an HTLM/PHP search and replace in several files.
For exapmle if I want to replace
<!DOCTYPE html>
with
<!DOCTYPE html>
<!--
TODO UNIVERSAL
Favicon
Page title
Active page
-->
I get
<!DOCTYPE html> <!-- TODO UNIVERSAL Favicon Page title Active page -->
I realize search and replace is probably considered old fashioned but I have found it an incredibly useful tool for 30 years.
I have scoured JetBrains web site with no avail and searched here and elsewhere.
I have tried /n, \n, \\n, \\n\\r etc etc and nothing seems to work.
I am sure I am being a dunce but could some other PhpStorm user please enlighten me.
Search for:
\<\!DOCTYPE HTML\>
Replace with:
\<\!DOCTYPE html\>\n\<\!\-\-\nTODO UNIVERSAL\nFavicon\nPage title\nActive page\n\-\-\>
Make sure that Regex option is checked
(here on screenshot you see the result of such replacement)
P.S.
PhpStorm (and other IDEA-based IDEs) uses \n internally (while editing) for all line endings. And then, when saving, it uses detected/proper line ending.
This can be achieved with simple and tiny application geany.
I don't know on which platform you are, but it's available on Ubuntu and Windows both.
You can open all files in whclich you want to search and replace.
Open replace dialog
Enter text in find and replace text box.
Here make sure one thing that you copy and paste "replace" text with new line character from a file opened in geany. New line character will be converted to some non readable character, but don't worry just replace it will be as new line after replace.

How to format html onliner?

Say I have a line of html code,
<div><p><span>foo</span></p></div>
I want to convert it to something like
<div>
<p>
<span>foo</span>
</p>
</div>
Is there any plugins or native solution to do this?
Use the tidy program (or its HTML5 sibling).
That's what it has been designed for and that's what regular expressions are not designed for.
if you work on linux box, usually xmllint was already installed. try this command:
:%!xmllint --format -
this will change the text to what you wanted. but there is <?xml version="1.0"?> at the beginning. don't know if it is ok for you.
if you want to remove, after executing the command, the cursor will be at line, type dd to remove. or you can write it in a mapping.
:%s/></>\r</gEnterggShift-vShift-g=Enter
(you will nee to :set ft=html if you haven't already)
When I do the above, I get
<div>
<p>
<span>foo</span>
</p>
</div>
Unfortunately VIM does really poorly with most front-end related indenting (html, javascript). It's a common complaint, and will probably never have a good solution despite all of vim's customizable power.

Resources