2

I've used vim for ages and am really used to inserting four spaces by hitting tab, but then being deleting them one by one. Now that I've switched to neovim this has changed to it inserting four spaces in one go but also deleting four in one go, which means I often delete far too much.

This is my .vimrc file - some of it might be nonsense, it's "evolved" over the years, but thought I should show it in full here:

set nocompatible              " be iMproved, required

source ~/.vim/plugins.vim

execute pathogen#infect()

syntax enable    


"automatically source .vimrc whenever saved (instead of typing :so %)
augroup autocommands
    autocmd!
    autocmd BufWritePost .vimrc source %
augroup END

"--------------------------Mappings------------------------------"

"quick route to editing vimrc file
nmap ,ev :tabedit $MYVIMRC<cr>
"add simple highlight removal
nmap ,<space> :nohlsearch<cr>
nmap <F1> :NERDTreeToggle<cr>
nmap <F2> <C-w><C-w>

filetype plugin indent on
set tabstop=4                       " show existing tab with 4 spaces width
set shiftwidth=4                    " when indenting with '>', use 4 spaces width
set expandtab                       " On pressing tab, insert 4 spaces

set nowrap                          " no wrap
set number                          " gutter numbers

if has('mouse')
    set mouse=a                     " mouse works
endif

set backspace=start,indent,eol      " set standard backspace behaviour

set t_Co=256                        " colourscheme stuff
colorscheme molokai                 " colourscheme
highlight LineNr ctermfg=239        " make gutter numbers more subtle
highlight LineNr ctermbg=233        " make gutter numbers more subtle

highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/

let php_sync_method = 0             " this makes sure that the syntax highlighting always works


" autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
" autocmd InsertLeave * if pumvisible() == 0|pclose|endif
""" autocmd FileType php set omnifunc=phpcomplete#CompletePHP
"" set completeopt=longest,menuone

" The encoding displayed.
set encoding=utf-8
" The encoding written to file.
set fileencoding=utf-8


let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 15

autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
let g:NERDTreeDirArrowExpandable = '>'
let g:NERDTreeDirArrowCollapsible = 'V'

if has('nvim')
    " disable the auto-search - I prefer to finish typing and hit enter
    set nois
    " disable the fact that you can delete 4 spaces in one go
    set softtabstop=0
endif

I thought from googling that adding that penultimate line set softtabstop=0 would make the difference, but it doesn't seem to.

  • 1
    I would expect sofftabstop=0 to be the difference as well. Can you confirm it gets set properly? Also check if you have any mappings on <BS> – D. Ben Knoble Nov 21 at 14:45
  • I've replaced that line with the accepted answer (set nosmarttab) and it works as expected now. – Codemonkey Nov 21 at 18:16
4

Neovim sets smarttab by default, which will cause this behaviour. Try turning it off:

:set nosmarttab
  • 1
    Perfect, thank you. – Codemonkey Nov 21 at 18:14

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.