Since you're a beginner, you can get away with what most of us can only dream of now. Gaining muscle AND losing fat very quickly, for a short limited time of course or "newbie gains" as it is called. Since your body is not used to weight training stimulus at all yet, if you start following a basic weight lifting program, cut out junk food, consume adequate protein, get proper rest, etc, you will definitely add some muscle and lose a little bit of fat for a short period of time. I'll try to layout some sort of a basic plan for you as it seems like you're just beginning.
First, pick a well-established weight training program based on compound movements (squats, presses, deadlifts, pulls). I suggest doing either Starting Strength, Madcow 5X5, or if you feel comfortable enough, a regular bodybuilding split (Chest & triceps, Back & Biceps, Legs & Shoulders). I'm more about diet so if you want more information (and you should), go on the internet and look up some beginner weight lifting programs. This is ESSENTIAL because first of all, the more muscle you have, the more calories you will burn (without even doing anything), and second, obviously, you will also burn more calories through the act of lifting weights as well as get stronger and improve mood, confidence, etc...
Now, perhaps the most important, and something that a lot of beginners misunderstand, is your diet. You say you ate mostly carbs and vegetarian, so it's safe to assume you didn't consume enough protein, and as a result, your protein breakdown was greater than your protein synthesis. Basically, you broke down muscle for energy. Since you already know what you did wrong, you already know what to do! Eat more protein! I would focus on consuming anywhere from 1g to 1.5g of protein per lbs of bodyweight that you have, in order to invoke protein synthesis.
Once you get your protein down, you can tweak your macros (carbs and fats). I suggest that you limit your carb intake to right when you wake up in the morning (as you are more sensitive to insulin in the morning) and right before and after your weight training sessions. This will ensure that you use the glycogen provided by the carbs as fuel and not proteins. Make sure you don't eat an excessive amount of carbs any other times, since they will just turn into fat if your insulin is high enough, and if you don't care and still are gonna eat carbs other than the morning and around your workouts, make sure they are complex carbohydrates (i.e brown rice, sweet potatoes, oatmeal), so you don't raise your blood sugar too much.
There are a lot more things to be said, but since you're relatively new, I would just focus on getting your training down, protein intake, and nutrient timing (I shouldn't even have to mention that you don't wanna eat ANY junk at ALL, this means no coca cola, no doritos...no alcohol etc). Once you follow this approach for a few months, you will see some changes, and eventually adapt. THAT's when you can post back here or do your own research, and tweak everything to your needs. Don't worry about cutting first or bulking first, if you cycle your carbs properly, you can do both, easily as a beginner...although it will be near impossible once you become a novice.
Moreover, if you're REALLY unhappy (ive been down this path) with your body fat levels and how you look. You could utilize a low carb high fat diet in order to shed some body fat very quickly (3-4 months). I've done this before in the past and lost about 6lbs of fat in 2 months, and after that I was able to add on 10-15lbs of muscle in 8-9 months and looked better than ever. There are lots of great online articles about this and I suggest the one by Layne Norton, phD in Nutrition the most :
Shoot me a message if you need any more help, or are unclear on something!