1

I want to be able to delete indenting spaces one at a time.

If I set shiftwidth to 4, it deletes 4 spaces at a time if vim counts them as indentation. Setting shiftwidth to 1 fixes the problem, but makes vim autoindents using 1 space instead of a tab and inserts 1 space when I try to insert a tab.

Is it possible to delete spaces counted as indentation one at a time while keeping shiftwidth equal to 4?

2

I think some of your confusion comes down to terminology. There are two separate characters, space " " and tab "\t". Tabs are a single character, but get displayed as several blank columns. This can be configured with "shiftwidth". If you do :set shiftwidth=4 this means

When I press tab, insert a tab character, and display it as 4 blank columns (or as 4 spaces).

When you hit backspace, it deletes a single tab character that looks like 4 spaces. Now, if you want a tab character to insert 4 actual space characters, you should use expandtab. If you :set expandtab, it means:

When I press tab, enter tabstop spaces instead of a tab character.

So, if you :set tabstop=4, the tab key will insert 4 spaces, and backspace will delete one of them at a time. For reference, here are the relevant lines in my .vimrc:

"Indent settings
set autoindent
set expandtab
set tabstop=4
set shiftwidth=4

I also have:

filetype plugin on
1

Since you actually want indentation to be four spaces, I assume that this is a once-in-a-while thing you want to do. You could always use dh in normal mode. In the worst case, you'd be typing dh three times. Any more than three and you might as well be pressing the backspace key. To be a little bit more efficient with these four spaces, you could type dh, then start mashing . to repeat the deletion.

Given that you're only dealing with four spaces, the math is simple enough to use a count such as d2h without needing to think hard about it. Again, d2h is repeatable with . so you can delete 2 spaces at a time.

0

Figured out the answer. Set softtabstop to 0. Wasn't working with my version of neovim, but it works when tested with original vim.

0

A simple solution would be pressing x in normal mode. This will delete spaces one by one, no matter what are your settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.