Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime text 3 misinterpreting indentation when code is pasted

Love Sublime text, though I have come across an issue which seems to be an inconsistent issue when copying code. I used tab for indentation, and when I need to copy over code, it seems to attempt to interpret the tabs as spaces, but results in sending the indentation wonky.

I know you can go into settings, so I did, and change the values for properties such as tab_size, translate_tabs_to_spaces, but nothing seems to prevent it from happening. Instead of being 4 spaces for indentation, the lines are only one space, and when I hit tab it moves it one space.

Question

How do I force Sublime to only use tab for indentation which is currently set to 4 spaces everytime I create a new document?

like image 538
Patrick McDermott Avatar asked Dec 12 '17 10:12

Patrick McDermott


2 Answers

You don't tell us how you are pasting the code so I am assuming you are doing a simple paste rather than the Sublime Text way with Shift :

Sublime’s Paste and Indent command fixes this by automatically adjusting the indentation of your pasted code to match the surrounding lines.

This command is bound to Ctrl+Shift+V on Windows and Linux or Shift+Cmd+V on Mac. Give it a try—it’s magical.

like image 90
jwpfox Avatar answered Oct 23 '22 05:10

jwpfox


I know this is too late to answer but alternatively for @jwpfox answer, you can switch it in keybindings like so:

{ "keys": ["super+shift+v"], "command": "paste" },
{ "keys": ["super+v"], "command": "paste_and_indent" },

You can switch these 2 keybindings if you want to use the paste and indent by default.

like image 43
Jie Avatar answered Oct 23 '22 04:10

Jie