Search code examples
visual-studio-code

Can VSCode stay at the same column position after pressing arrow keys?


I use VSCode to write all my PHP, and I could swear it used to behave this way by default: When I press <ENTER> or arrow-up or arrow-down, I want the cursor to align intelligently; meaning: I want the cursor to be at the correct indent position depending on context. So, after I press ENTER after a line of code with an IF statement, it should indent 1 tab position (relative to the IF line) after pressing ENTER. It does do this.

But if I press ENTER a few times and then press <UP-ARROW>, the cursor goes to column position 1 at the beginning of the line. This is so annoying. I want the cursor position to remain at the logical tab-stop position when I arrow up and down. If I want to go to the beginning of the line for some reason, I can press <HOME>.

I think one of my settings got tweaked, and now it doesn't behave this way. How I want it is also how NPP behaves by default.

Here is one example:

  1. My cursor is at the end of a line of code with an IF block.
  2. I press enter and the cursor snaps to 1 tabstop in, as expected.
  3. I press enter a few more times, and the cursor remains at 1 tabstop in, as expected.
  4. I press <UP-ARROW> and the cursor snaps to position 1 at the beginning of the previous line. WHY??

I want to be able to arrow-up and arrow-down, and the cursor remains at the correct tab position (whether that be 1 tabstop in, 2, 3, 4...etc), just like when pressing ENTER.

Is there a setting that does this?


Solution

  • Try disabling this setting:

    Editor: Trim Auto Whitespace
    Remove trailing auto inserted whitespace.
    

    Disabling it solves that issue for me (in js/ts files at least).