Skip to main content

Timeline for Delete 4-spaces as a single tab

Current License: CC BY-SA 3.0

16 events
when toggle format what by license comment
Feb 20, 2024 at 8:07 comment added Vladimir Panteleev C-u <backspace> deletes EXACTLY 4 characters. It does not respect tab stops. It does not respect indentation settings. It will do the wrong thing if there are tab (or other) characters instead of spaces. It just so happens that one C-u means "repeat four times" which is a common indentation width. This answer addresses the letter of the question, but I think an answer that would be more in the spirit of the question (delete whitespace characters until the previous tab stop) would be more useful.
Jul 22, 2016 at 17:56 vote accept CommunityBot
Jul 22, 2016 at 17:56 comment added user11867 It does, I'll try to make a function to do the work pressing DEL. Much appreciated, Kaushal Modi :)
Jul 22, 2016 at 16:51 comment added Kaushal Modi @captainepoch I have updated the answer; hope it is clearer.
Jul 22, 2016 at 16:50 history edited Kaushal Modi CC BY-SA 3.0
added 544 characters in body
Jul 22, 2016 at 16:46 comment added Kaushal Modi @captainepoch That's a perfect screenshot! So basically those are just spaces; forget that you hit TAB to make that indentation. So one DEL will delete just one space. To delete all 4 spaces to the left of the cursor, do C-u DEL as I mentioned above in the answer. If you want to delete 4 spaces to the right of the cursor, do C-u C-d.
Jul 22, 2016 at 16:43 comment added user11867 I selected it, yeah. This is a screenshot without selecting the indentation (i.imgur.com/AQl7uic.png). What I want is deleting the 4 spaces as a tab with the DEL key.
Jul 22, 2016 at 16:35 comment added Kaushal Modi @captainepoch Actually, nevermind, those overlays are related to linum-mode. So those characters do look like physical spaces (tabs) because the ASCII code is 0x20. If you can C-f/C-b 4 times in that indentation, that's another proof that those are physical space characters. Then the above solution should work for you. In your screenshot, did you select all the spaces and then do C-u C-x =? Why does the whole indentation before return look selected?
Jul 22, 2016 at 16:30 comment added user11867 No, I don't. I tried on an HTML file on web-mode, but nothing about before-string appeared... At c-mode I got this settings: github.com/captainepoch/dotfiles/blob/master/.emacs.d/config/…
Jul 22, 2016 at 16:23 comment added Kaushal Modi @captainepoch OK, I added the same code in c-mode in an emacs -Q session and I still cannot recreate your scenario. From the C-u C-x = result (very helpful!), I see that there's a before-string overlay active where the cursor is. I do not use c-mode and so I am not very familiar with it. Do you have any other minor mode or c-mode setting enabled that would put those overlays?
Jul 22, 2016 at 15:41 comment added user11867 I see this (I hope it's what you asked for, large image, that's why I didn't use MD's image syntax) i.imgur.com/3I4a2Ep.png
Jul 22, 2016 at 15:34 comment added Kaushal Modi @captainepoch It's not clear if you are trying to delete 4 ASCII Space characters (0x20) or an ASCII TAB character (0x09). What do you see when you do C-u C-x = with cursor on the area that you call "4 spaces".
Jul 22, 2016 at 15:32 comment added user11867 From the cursor to the point of where the 4 spaces start. It's like treating 4-spaces as a unique tab, not converting it in real time to delete it.
Jul 22, 2016 at 15:21 comment added Kaushal Modi Hmm, then I do not understand your question.. the question says "Kill 4-spaces .."
Jul 22, 2016 at 15:20 comment added user11867 I understand what you tell me, but I don't convert the spaces to TABs or viceversa in real time, I have changed it in the config for every indentation.
Jul 22, 2016 at 15:16 history answered Kaushal Modi CC BY-SA 3.0