Sublime Forum

Proper case?

#1

Is it possible to convert a selection to proper case? i.e. First letters of each word to uppercase? Thanks!

0 Likes

#2

If you get the PowerUser plugin then it is :smile:

by default the binding I have for it is alt+k,t but u can change it to whatever you want. Edit the *Default.sublime-keymap *file in the PowerUser folder

If you don’t feel like downloading the whole plugin and use all of its goodies then here’s the code for that command only :wink:

[code]class TitleCaseCommand(sublimeplugin.TextCommand):
def run(self, view, args):
self.transformSelectionText(string.capwords, view)

def isEnabled(self, view, args):
return view.hasNonEmptySelectionRegion()

def transformSelectionText(self, f, v):
for s in v.sel():
if not s.empty():
txt = f(v.substr(s))
v.replace(s, txt)[/code]

0 Likes

#3

Awesome, thanks a lot! That was the only thing keeping me from using Sublime Text. :smiley:

0 Likes

#4

On more quick question. I’m new with Sublime, so forgive my stupid questions. You have the default keymap as alt+k,t…how does that translate into what I press? Alt k, then release and press t or something different. I can’t seem to figure that side of things out.

0 Likes

#5

Nevermind…I just answered my own question. Alt + k, then release and press t is exactly it. I the action I wrote in the last post was the only action I didn’t actually try yet. Thanks a lot for your quick help on this and for that great plugin!!

0 Likes

#6

Your welcome :smile:

0 Likes

#7

I was lazy, I just added this class in Packages/Default/Transform.py

class CapitalizeCaseCommand (sublimeplugin.TextCommand):
	def run (self, view, args):
		transformSelectionText (string.capwords, view)
0 Likes