Home Download Buy Blog Forum Support

Basic code writing questions

Basic code writing questions

Postby Lukk on Sun Mar 18, 2012 2:02 pm

Hey there,

Recently I've started to use Sublime Text 2 and I'm loving it :) I always used dreamweaver but it had so many options I didn't use. Anyways, I have a couple of very basic questions.

1) When I'm writing code (for example CSS). I usually type this:

body {
color: green;
}

Sublime text automatically creates ; at the end (which is great!) but I always have to use my arrow keys on my keyboard to get behind the ; and press enter to create a new line. (because right now I am typing between the 'n' from 'green' and the ; ) This is pretty annoying. Is there any other way than using my arrow keys or just typing the ; instead? (I have the same problem when making jQuery functions, I always have to press the right arrow key to continue typing because Sublime Text 2 automatically creates these parenthesis. () {} I dont want to turn this function off I just want to type faster without having to use my arrow keys all the time to navigate in the code.

2) copy pasting. Whenever I copy paste a code it creates extra space. For example I'm using CTRL + C to copy and CTRL + V to copy this:

<ul>
<li> 1 </lil>
<li> 2 </lil>
<li> 3 </lil>
</ul>

and it comes out like this:

___________ <ul>
<li> 1 </lil>
<li> 2 </lil>
<li> 3 </lil>
</ul>

____ = spaces

is there any way to make this easier so I dont have to remove the unnecessary space?

3) Sometimes I see people just typing ul>li and it automatically creates an unordered list items. How do I do this? or just typing .hello creates a div with a class 'hello'.

4) When I'm typing <ul> I can press enter and it also creates a </ul> (which is good). But then I have to press enter twice and it's pretty difficult creating a vertical space between the <ul> and </ul>. For example to create this:

<ul>
<li> 1 </li>
<li> 2 </li>
<li> 3 </li>
</ul>

Thanks in advance :)
Lukk
 
Posts: 12
Joined: Sun Mar 18, 2012 1:41 pm

Re: Basic code writing questions

Postby C0D312 on Sun Mar 18, 2012 2:11 pm

1. Add the following to your user keybindings:
Code: Select all
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "following_text", "operator": "regex_contains", "operand": "^[)\"'\\]\\};]", "match_all": true },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false },
        { "key": "has_next_field", "operator": "equal", "operand": false }
    ]   
  }


2. Add this to your user keybindings as well:
Code: Select all
  { "keys": ["super+shift+v"], "command": "paste" },
  { "keys": ["super+v"], "command": "paste_and_indent" }


3. Install the ZenCoding plugin

4. I'm not really sure what your question is here. If you install the Tag plugin, it will auto-close tags when you press </. Alternatively, you can change autocomplete to commit on tab instead of enter.

For tab autocompletion, add this to Preferences > Settings - User:
Code: Select all
"auto_complete_commit_on_tab": true
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Basic code writing questions

Postby vitaLee on Sun Mar 18, 2012 2:31 pm

Sublime text automatically creates ; at the end (which is great!) but I always have to use my arrow keys on my keyboard to get behind the ; and press enter to create a new line.

you might want to check Edit -> Text -> Insert line before/after shortcuts
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: Basic code writing questions

Postby Lukk on Sun Mar 18, 2012 2:59 pm

Thank you for the responses :) I still don't know how to get to the end of a line of code. Any help there?
Lukk
 
Posts: 12
Joined: Sun Mar 18, 2012 1:41 pm

Re: Basic code writing questions

Postby atomi on Sun Mar 18, 2012 3:06 pm

ctrl+enter
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Basic code writing questions

Postby C0D312 on Sun Mar 18, 2012 3:07 pm

If you added my first keybinding, tab should move you past the semi-colon. However, if you want to move directly to the end of the line no matter where you are, you can add this:
Code: Select all
  {
    "args": {
      "extend": false,
      "to": "hardeol"
    },
    "command": "move_to",
    "keys": [ "ctrl+quote" ]
  }
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 35 guests