Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a way to automatically insert \item whenever I hit enter within an itemize or enumerate in Sublime Text 2?

share|improve this question
    
Welcome to TeX.sx! A tip: You can use backticks ` to mark your inline code. –  Corentin Nov 13 '12 at 22:43
    
Thanks! I didn't realize that itemize and enumerate was really code. –  Alfred Xing Nov 13 '12 at 23:20
    
Marking them as code makes it clear that you are speaking about environments. –  Corentin Nov 13 '12 at 23:23

2 Answers 2

up vote 1 down vote accepted

If you have the LaTeXTools plugin, it already does that exept that it is mapped on Shift+Enter instead of Enter.

The corresponding code is in the default (PLATFORM).sublime-keymap

// automatic addition of new \items when hitting Shift+Enter in a list environment
{ "keys": ["shift+enter"], "command": "insert_snippet", "args": {"contents": "\n\\item $0"}, 
"context":  
    [
        {"key": "selector", "operator": "equal", "operand": "meta.function.environment.list.latex"},
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
    ]
},

You can duplicate it or modify it in order to map it on another key by replacing the content inside of the first brackets after "keys"

share|improve this answer
1  
Thanks! But when I change "shift+enter" to "enter", pressing enter right after \end{itemize} still inserts \item? Is that just a small glitch? –  Alfred Xing Dec 5 '12 at 23:00
    
@AlfredXing I never noticed this but you are right. It is less annoying with the original shortcut. Maybe that's why they did not choose enter ! –  William Ledoux Dec 6 '12 at 10:39
    
@AlfredXing Tried to dig into this and ended up by opening a thread on ST2 forum to try to know more about this: sublimetext.com/forum/… –  William Ledoux Dec 6 '12 at 11:24
    
Thanks! I'll watch the forum thread. –  Alfred Xing Dec 7 '12 at 22:06

If you're using the LaTeX Tools package, hitting Shift+Enter within any sort of list environment will insert new \items (if you're not, you really should be). If you want change this to just Enter, you'll have to change the user keybindings (Preferences > Package Settings > LaTeXTools > Keybindings – User).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.