1

I'm having trouble making indentation work as I expect in Vim.

Short version: What I want is to disable Tab mark.

Long version: What I want is to ALWAYS insert four spaces when indenting (i.e. when hitting <Tab> AND when using >>).

Actually, the second part is working.

The problem comes from the <Tab> part: when hitting <Tab>, it inserts between 1 and 4 spaces to go to the next Tab mark. And I don't want that.

Actually, my Vim indentation parameters in .vimrc are:

set expandtab # To get spaces instead of Tab
set tabstop=4 # What actually is giving me trouble
# set softtabstop=-1 # I also tried this one but it gives me the same result
set shiftwidth=4 # To get 4 spaces Tab

I checked the others indentation parameters using:

:verbose set sr? ai? cin? cink? cino? si? inde? indk?

Which result was:

noshiftround
noautoindent
nocindent
    cinkeys=0{,0},0),:,0#,!^F,o,O,e
    cinoption=
nosmartindent
indentexpr=
indentkeys=0{,0},:,0#,!^F,o,O,e

(If you're actually asking yourself why someone would be foul enough to want that, I'm writing some Robot Framework code in Vim and parameter separator are multiple spaces or tab. So when the Tab mark is 1 space after, it doesn't insert enough spaces.)

3
  • I didn't even know there was a stackexchange for vi, sorry. How can I ask for migration? – Matthieu.P Apr 15 '16 at 12:28
  • Let me tag this question, it should be enough for an admin to see it. – nobe4 Apr 15 '16 at 12:29
  • 1
    I use the flag button, don't know if it's the right way but it should work :) – Matthieu.P Apr 15 '16 at 12:31
6

The current behavior is exactly how indentation and tabulation are supposed to work. What you want is neither indentation nor tabulation, therefore you need to find another mechanism.

The simplest solution is to remap <Tab> to always insert four spaces:

inoremap <Tab> <Space><Space><Space><Space>

You'll need the snippet below to make that mapping work only in *.robot files:

augroup robot
    autocmd!
    autocmd BufNewFile,BufRead *.robot inoremap <buffer> <Tab> <Space><Space><Space><Space>
augroup END
1
  • 1
    Exactly what I want! (And even better with the "only *.robot" option!) Thanks a lot! – Matthieu.P Apr 15 '16 at 13:24

Your Answer

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