Home Download Buy Blog Forum Support

Proper case?

Proper case?

Postby ChestyPuller on Thu Jan 21, 2010 2:39 pm

Is it possible to convert a selection to proper case? i.e. First letters of each word to uppercase? Thanks!
ChestyPuller
 
Posts: 4
Joined: Thu Jan 21, 2010 2:36 pm

Re: Proper case?

Postby EJ12N on Thu Jan 21, 2010 5:00 pm

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

If you get the PowerUser plugin then it is :)

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 ;)

Code: Select all
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)
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Proper case?

Postby ChestyPuller on Thu Jan 21, 2010 7:25 pm

Awesome, thanks a lot! That was the only thing keeping me from using Sublime Text. :D
ChestyPuller
 
Posts: 4
Joined: Thu Jan 21, 2010 2:36 pm

Re: Proper case?

Postby ChestyPuller on Thu Jan 21, 2010 8:27 pm

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.
ChestyPuller
 
Posts: 4
Joined: Thu Jan 21, 2010 2:36 pm

Re: Proper case?

Postby ChestyPuller on Thu Jan 21, 2010 8:29 pm

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!!
ChestyPuller
 
Posts: 4
Joined: Thu Jan 21, 2010 2:36 pm

Re: Proper case?

Postby EJ12N on Thu Jan 21, 2010 8:39 pm

ChestyPuller wrote: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!!

Your welcome :)
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Proper case?

Postby tgkeul on Thu Jan 21, 2010 9:56 pm

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

Code: Select all
class CapitalizeCaseCommand (sublimeplugin.TextCommand):
   def run (self, view, args):
      transformSelectionText (string.capwords, view)
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm


Return to Technical Support

Who is online

Users browsing this forum: Vlad Ghitulescu and 16 guests