+1  A: 

The main problem is that you add another keydown event handler each time focusin fires. Try this:

$('textarea').live("keydown", function(e){
    var code = e.which;
    if(code === 13) { 
        var prevIndex = parseInt($('#linenumbers li:last').text());
        $('#linenumbers').append('<li>' + prevIndex++ + '</li>');
    }
});

karim79
It only add 1, 1, 1, and after 3 enter keydown it ad like 10 li
Frozzare
@Frozzare, in my initial answer, prevIndex was not incrementing based on the last LI. You might like to try it now. Also, it would be extremely helpful if you provided your HTML.
karim79
@karim79 i added my html to my question, it any more then that. Yes, your code works but the focus problem is there. when you focus the second time it add 2 li, and so on.
Frozzare
@Frozzare - I now understand. The problem is that you are adding *another* keydown event hander *each time* the textarea focusin event fires.
karim79
Thanks! That works.
Frozzare