Sublime Forum

Capitalizing the first letter after punctuation



As I have solved part of this question, I have amended this text to include the partial solution. The remaining issue is: How to stop the capitalization after specific abbreviations, i.e. ‘i.e., etc. bf.’ and the like?

The solved part: How to automate capitalization after punctationmarks?
I found a suggestion here that did not fully work:
github dot com/SublimeText/LaTeXTools/issues/1217

After a lot of trial and error, I got it to work.
As suggested in the link, first make a new plugin:
Open Tools > Developer > New Plugin… , paste, and save in the (default provided) User directory:

import sublime_plugin

class InsertUppercaseCommand(sublime_plugin.TextCommand):
    def run(self, edit, character=""):
        self.view.run_command("insert", {"characters": character.upper()})

Open Preferences > Keybindings… and add this keybinding to your user binds:

    "keys": ["<character>"],
    "command": "insert_uppercase",
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex.latex" },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "(^|\\.\\s+|\\!\\s+|\\?\\s+|\\:\\s+)$" },

This solution works for new lines and these marks: ‘. : ! ?’. If you don’t want capitalized letters after new lines, you may use [\\.\\!\\?\\:]\\s+$ instead of (^|\\.\\s+|\\!\\s+|\\?\\s+|\\:\\s+)$

And lastly, I am not an expert in python and have very little coding experience, and I hope you’ll keep it in mind when answering.


Capitalization does not work for new line

Solved this one myself.

I replaced:
{ "key": "preceding_text", "operator": "regex_contains", "operand": "(?:^|\\.)\\s*$" }
{ "key": "preceding_text", "operator": "regex_contains", "operand": "[\\.\\!\\?\\:]\\s+$" }



hi, this works after dot, question mark, and exclamation mark, but it does not capitalize the first letter in a new line. Do you figure out how to fix it?



add this instead:

1 Like


Yes, it worked. I guess you mean (^|\\.\\s+|\\!\\s+|\\?\\s+|\\:\\s+)$, because on my side, it does not allows for single backslash



OK, I see the problem, if you put double slash in quotation mark, it will show up as single slash. Anyway, thanks.



That’s because the file is a JSON file, and a single slash introduces a character escape; there are a limited number of valid escapes and everything else is an error.

The sequence of two slashes is itself an escape sequence that tells the system to treat that as a regular slash, which is why this works (and is the correct way to do something like this).

1 Like


I see, my mistake. I have edited my comment so that it is corrected. Thanks.