Search code examples
sublimetext3

Subline Text paste and indent windows 10


Using sublime text 3 cutting and then paste and indent using Ctrl+Shift+V it doesn't do what I think it should do:

<div>
<div></div>
</div>

function(){
test;
}

The expected result should be:

<div>
    <div></div>
</div>

function(){
    test;
}

Am I missing something?


Solution

  • This is not how Paste and Indent works. It is intended for situations when you copy a line or lines with one indentation and paste it into a block with a different indentation. For example:

    <ul class="list1">
        <li>One</li>
        <li>
            <ul class="innerList">
                <li>OneA</li>
                <li>OneB</li>
    |           <li>Three</li>
            </ul>
        </li>
        <li>Two</li>
        <li>Four</li>
    </ul>
    

    Now, I want to copy the line where the cursor is (containing <li>Three</li>) from innerList to list1. If I just do copy and paste (CtrlV), the indentation is wrong:

    <ul class="list1">
        <li>One</li>
        <li>
            <ul class="innerList">
                <li>OneA</li>
                <li>OneB</li>
                <li>Three</li>
            </ul>
        </li>
        <li>Two</li>
    |           <li>Three</li>
        <li>Four</li>
    </ul>
    

    However, if I do "paste and indent" (CtrlShiftV):

    <ul class="list1">
        <li>One</li>
        <li>
            <ul class="innerList">
                <li>OneA</li>
                <li>OneB</li>
                <li>Three</li>
            </ul>
        </li>
        <li>Two</li>
    |   <li>Three</li>
        <li>Four</li>
    </ul>
    

    The indentation is corrected for the current context. To do what you want to do, you'd need to use one of the many HTML and/or JS formatting plugins available on Package Control. I personally use HTML-CSS-JS Prettify, which runs on top of Node.js, but there are plenty to choose from.