If you've ever opened a file that looks like a bento box of tabs and spaces, Vim's auto-indent behavior is surprisingly predictable once you know the pieces involved.
Auto-indent (the basic 'autoindent' option) simply copies the leading characters from the previous line — literally. That means if the previous line starts with a tab, then two spaces, Vim will start the new line with that exact sequence. Nothing clever, just a straightforward copy. Where things get interesting is when you press Tab or when you run reindent commands: Tab insertion is governed by 'expandtab' and 'softtabstop'. If 'expandtab' is set, inserting a tab character from Insert mode actually inserts spaces. If it's unset, Vim inserts a real tab character, and 'softtabstop' affects how many spaces the Tab key represents while editing.
Reformatting with commands like '=' or using cindent/smartindent is different: Vim computes the desired indentation in columns based on 'shiftwidth' and the language indent rules, then writes the indentation according to your tab settings (usually honoring 'expandtab' to decide whether to use spaces, or using tabs where possible when it's unset). Practical tips: use ':set list' to reveal hidden whitespace, ':set tabstop=4 shiftwidth=4 softtabstop=4', ':set expandtab' to normalize new indentation to spaces, and ':retab' to convert existing characters if you want to clean the file up.
I tend to think about this like a little mechanical copier followed by a formatter. First the copier: with simple auto-indent on, Vim just copies the previous line's indentation characters verbatim — tabs, spaces, whatever sits at the start of the line. That’s why files can look inconsistent when they were edited by multiple people or different editors.
Then the formatter: when you ask Vim to fix indentation (operators like '=', or rules driven by 'cindent'/'indentexpr'), Vim calculates how many columns of indent the language rules demand. After that it writes that number of columns according to your settings. If 'expandtab' is enabled, it writes only spaces. If not, it will try to use tabs (based on 'tabstop') and then spaces for any leftover columns. This is why 'shiftwidth' controls the logical indent step, but 'tabstop' controls how those steps become physical characters.
Practical suggestions from my toolbox: install a tiny plugin like 'vim-sleuth' to auto-detect existing indentation, use ':set list' or ':set listchars' to inspect, and when you want uniform output pick either ':set expandtab' plus ':%retab' to convert tabs to spaces, or ':set noexpandtab' and a consistent tabstop to keep tabs. Also watch out for Makefiles and similar where literal tabs are required — in those files I explicitly force 'noexpandtab' so the copier/formatter won’t break them.
Okay, here’s the short technical walk-through from my desk: the plain auto-indent feature copies the prior line’s leading bytes — tabs and spaces — exactly as they are. So if you’ve got a mix on the previous line, the next line will start with that same mix.
What changes behavior is what you do next. Hitting Tab in Insert mode respects 'expandtab' and 'softtabstop' (so Tab can mean spaces or a real tab). Reindenting with '=' or using 'cindent' computes indentation in terms of columns (using 'shiftwidth' as the unit) then converts that column count into characters. That conversion will use spaces if 'expandtab' is set; otherwise Vim will insert tabs where they fit (using 'tabstop' to know tab width). To normalize a file I usually: turn on ':set list', pick a canonical tab/shiftwidth/softtabstop, ':set expandtab' if I want spaces, and then run ':%retab' followed by 'gg=G' to reindent everything.
If you need to preserve literal tabs (like in Makefiles), be careful: modelines or filetype plugins might alter behavior, so set options explicitly per-file.
Quick, friendly checklist from my late-night editing sessions: Vim’s basic auto-indent copies the previous line’s leading characters exactly, so mixed tabs+spaces are preserved on the next line.
If you press Tab or reformat, the editor's other settings matter. 'expandtab' makes Tab insert spaces; 'softtabstop' affects how Tab behaves in insert mode; 'shiftwidth' defines the size used by '>' '<' and reindent commands; 'tabstop' tells Vim how wide a real tab is when converting columns into characters. When reindenting, Vim computes the correct column amount and then emits tabs or spaces according to 'expandtab' and 'tabstop'.
To fix a messy file: reveal whitespace with ':set list', choose your canonical settings, then use ':%retab' and a full reindent. Simple, but it saves hours of annoying diffs.
2025-09-08 20:02:08
13
View All Answers
Scan code to download App
Related Books
SIN BETWEEN THE SHEETS
Abby
0
46.4K
“You wear these little skirts… are you trying to seduce me?” His eyes dragged down my body.
“I—I don’t know what you’re talking about”
Before I could finish, his hand slid up my thigh, fingers brushing beneath the edge of my skirt. My breath hitched. He shoved my panties aside and pressed two thick fingers inside me.
“Ahh. . . Kelvin. .” My knees buckled against the sink as he started slow, then thrust rougher, stretching me with every push.
“You like that, baby girl?” he whispered against my lips.
“Yes… oh God, yes.”
His mouth hovered over mine, stealing the sound of my moans before he spun me around to face the mirror. My own reflection stared back at me wide eyes, flushed cheeks while Kelvin loomed behind, his heat swallowing me whole.
“Watch while I fuck you,” he growled, shoving down his zipper.
The heavy length of him slammed into me in one rough stroke, knocking the air from my lungs.
“F-fuck!” I cried out, gripping the sink for dear life.
He yanked my hair back, forcing me to look at myself as he pounded into me. “Be my slut today.”
Dripping Wet is a collection of straight-up filthy stories about raw, no-limits sex.
Bodies crashing together in hard fucks. Holes stretched wide, throats used rough, sheets drenched in cum and sweat.
Each one dives deep into pure hunger, cocks slamming in deep, pussies taking it hard, asses getting claimed with no mercy. All the taboo stuff you crave, laid out in brutal detail.
No romance. No sweet talk. Just hard, wet, pounding sex that leaves you spent. This book isn't about love. It's about need and giving in until you're soaked.
One night, as I was making my way to the bathroom around 3 a.m., I saw my dormmate, Yvonne, squatting in front of our door. She was rearranging all our shoes so that their tips were pointed inward.
I thought it was funny, so I rearranged them to have their tips pointed outward.
The next day, I found that all of them had been positioned inward again.
This kept happening for a week, and I continued to scramble things up, hiding the shoes, even, or tying the shoelaces together.
But they always ended up being repositioned neatly inward.
I started observing my dormmate and found her mumbling to the shoes while squatting at the door.
I ranted about it online, only to have my first reply send chills down my spine.
[Do you also get the weird feeling that something paranormal is happening around you? You have to move out before it’s too late!]
I'm the type who has the urge to overshare my life with him.
It can be anything, be it the flowers blooming by the side of the road, the unpleasant coffee I end up having, or the sunset I've seen when I'm on my way home from work.
Heck, when I think of Edwin Howell all of a sudden, I can't resist texting him at all. His replies are always short and perfunctory, though I suppose they count as a form of response from him.
Hence, over the past six months, I've relied on these cold-sounding yet present replies to give me enough strength to deal with the engagement party, go wedding gown shopping, and choose the wedding venue all by myself.
Somehow, I've managed to hang in there till the week before the wedding.
But five days before the wedding, I discover an AI program that's installed within Edwin's computer. It can categorize every single sentence that I've sent to Edwin and extract the keywords. Then, it'll draft the most perfunctory responses that will never go wrong.
If I miss Edwin, the AI will reply, "Mm-hmm."
If I feel aggrieved, the AI will reply, "Got it."
When I try to vent my frustrations to Edwin, the AI will reply, "Don't make such a big deal out of it."
It turns out that Edwin isn't the one who has been responding to my need to overshare. The thing is, he has been texting another woman nonstop in another private chat. They talk about anything and everything under the sun, from exchanging simple good mornings and good nights to asking, "What are you having for lunch today?" and "Do you wanna go to the beach someday?"
Finally, I realize that Edwin isn't the silent type who keeps his love in. If anything, he's the flashy type who will proclaim his love anywhere, anytime.
It's just that… his love has never been mine to have.
As for me, I've finally made up my mind to stop spending my life waiting for a response that will never come.
I was in the office bathroom stall when I heard them trash-talking me.
The intern I'd trained for three months whined, "She's a heartless witch—like a robot with zero brain cells."
I was about to swing the door open when another voice jumped in, laughing.
"Documents incomplete."
"Receipts don't match."
"No signature? Denied."
"Seriously, we've all memorized the freaking rulebot's script!"
Once they were gone, I headed back to my desk.
The intern stormed in and slammed a fat stack of reimbursement forms in front of me.
"Don't go on another power trip and block everyone's claims."
I skimmed the obviously fake receipts. Normally, I'd tear into her.
But this time, I just smiled.
"My head's killing me. Can't read the fine print."
Even though it's the New Year holidays, I'm still cooped up in the company while churning out the paperwork needed for the company's listing process.
That's when my keyboard suddenly types a paragraph on its own.
"Stop working already! Your boss is about to fire you, and yet you're still slaving away for his sake!"
I'm stunned by the information I see. The keyboard goes on typing, "He said you only have a bachelor's degree. If not for the fact that you're a walking lucky charm, you wouldn't have gotten into this company in the first place!
"Now that the company is in the process of getting listed, it's costing far too much just to keep you around! Even though you're being paid a high salary every month, you can't even provide the company with any value!
"He intends to dismiss you the moment the company gets listed! Since it's the new year, new blood should be joining the company!"
I've been holding my coffee mug the whole time. At that moment, I can feel my hands starting to tremble.
For five years, the projects that I've manned never got into any problems. The final round of funding always came through. Even when we were choosing a new office, we came across the situation of an owner who was all-too happy to get rid of the building.
I can say with great confidence that I'm 90% of the main reason how this company expanded from a tiny office to the entire building. To think that I'm the first person to be discarded right after my boss reaches his goal…
I can feel my stomach twisting uneasily. Even my throat goes tight from the anxiety.
Just as I'm about to leave, a few angry voices ring out in the office.
"I'm an office chair! I'll break during the board meeting tomorrow and make sure that your boss falls right on his ass!"
"I'm a printer! I'll make sure to print all the documents he wants with nothing but gibberish on them!"
"I'm a coffee machine! Tomorrow, I'll whip him a special brew that ensures he will never get to leave the toilet bowl for the rest of the day!"
The HR manager slid a severance agreement across the table and said coldly, "You're fired."
I froze. "Why?"
Just one week ago, my boss had praised me in the company meeting and called me one of the team's most valuable people.
The HR manager shrugged. "Ms. Lyttle, you're already 35. You don't have the energy of younger employees anymore, and you're not what you used to be. You no longer fit the company's future."
I joined this company when I was 29. Over the past six years, I wrote countless lines of code and worked through more sleepless nights than I could remember.
Every time the company faced a major system failure, I led the emergency response and saved it from catastrophic losses. And now they were telling me I was too old and too slow.
I laughed in disbelief. "So you've already copied all my experience and skills into an AI, haven't you?"
The HR manager paused for a moment before answering confidently, "AI never gets tired, never takes time off, and never asks for a raise. Once the company has an employee like that, why would we keep you?"
I looked at her. "Are you sure the AI has learned everything I know?"
She smiled. "Absolutely."
The moment I heard that, I finally relaxed.
Long ago, I had already hidden a trap inside my code to keep my skills from being copied.
The moment their AI employee went live, the company would only have three days before everything fell apart.
Honestly, getting Python auto-indent working in vim is one of those tiny victories that makes editing a joy. My go-to is to enable vim's filetype detection and then set sensible Python indentation rules in my config. Add these lines to your ~/.vimrc or init.vim for Neovim:
filetype plugin indent on
set autoindent
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
The first line turns on filetype-specific plugins and indent scripts (this loads vim's python indent file). The rest make tabs into spaces and use four spaces per indent, which is the common Python convention. If you want the setting to apply only to Python buffers, drop the global lines into ~/.vim/ftplugin/python.vim and use setlocal instead of set.
If indentation still feels off, check the buffer's filetype with :set filetype? and inspect loaded scripts with :scriptnames. I sometimes install a plugin like 'vim-python-pep8-indent' or use external formatters like 'black' called via a formatter plugin to normalize whitespace. Try opening a .py and typing an indented block — it should behave. If not, tell me what output :set filetype? and :verbose set shiftwidth? give and we can debug further.
Man, that frustration is so real — I’ve been there. First thing I do is check whether vim even thinks it should indent: open the file and run :set filetype? and :verbose set autoindent. If filetype is empty or wrong, indent scripts won’t run. If :verbose shows autoindent being turned off by some script, that points to the culprit.
Next, consider obvious toggles that silently kill indentation: if you’ve got 'set paste' enabled (or you toggled paste mode earlier with a mapping), indentation won’t behave. Also check whether you disabled 'autoindent', 'smartindent', or 'cindent' by mistake. Use :set paste? and :set autoindent? to inspect current state.
If those look fine, source your vimrc manually (:source ~/.vimrc) and watch :messages for errors — a syntax error early in the file can stop the rest of the config from loading, so later indent settings never get applied. Also run vim -u NONE (or nvim -u NORC) to see if a vanilla session indents correctly; if it does, a plugin or a line in your vimrc is to blame. Useful commands: :scriptnames (shows loaded scripts), :verbose set shiftwidth? tabstop? expandtab? and checking ~/.vim/indent or plugin ftplugin files for overrides. If you want, paste the problematic snippet and I’ll poke at it with you.
Okay, this is the hot take I give my friends when they ask how to stop JavaScript files from turning into a jagged mess: treat indentation as a filetype thing, not a global, and use 2 spaces plus an actual JS-aware indent engine. I usually put this in my vimrc (or better, in ftplugin/javascript.vim):
filetype plugin indent on
autocmd FileType javascript,typescript setlocal shiftwidth=2 softtabstop=2 tabstop=2 expandtab
autocmd FileType javascript,typescript setlocal autoindent smartindent
Those lines give you consistent 2-space soft tabs (the de facto style for many JS projects) and rely on Vim's smartindent for basic braces. But honestly, for real-world code with ES6/JSX/template literals, install a javascript-indent plugin (like the popular one that provides an indentexpr) and let it set indentexpr for you; it handles arrow functions, template literals and some weird edge cases better than plain smartindent. I also map = to re-indent visually: vmap = = or use gg=G to reformat a whole file.
Finally, I pair this with an on-save formatter — 'prettier' is my go-to — so even when teammates differ, my local formatting is predictable. If you want the exact plugin names or a sample ftplugin that runs Prettier on save, I can paste that too.
Okay, here's a practical and friendly way I handle Vim's auto-indent when I need it out of the way for a few moments.
If I just want to paste something without Vim reformatting it, I usually toggle paste mode: :set paste to turn it on, paste the text, then :set nopaste to go back. I often map a key for that so it’s painless, for example :set pastetoggle= or put in my config nnoremap :set paste! to flip it. Paste mode stops auto-indent, indentexpr, and other niceties, so your pasted code won't get mangled.
If I need to disable automatic indentation for editing (not just pasting), I prefer buffer-local switches so I don’t mess with other files: :setlocal noautoindent nosmartindent nocindent and, if needed, :setlocal indentexpr= to clear any expression-based indent. To restore, use :setlocal autoindent smartindent cindent or reopen the buffer. Little tip: :set paste? shows whether paste is on. Personally, I use paste for quick fixes and :setlocal for longer edits — keeps things predictable and quiet during a frantic refactor.
Okay, I’ll gush a bit: if you want auto-indent to actually behave instead of randomly guessing, start by combining a detector, a language-aware indenter, and a formatter. I like using vim-sleuth to sniff tabs vs spaces and shiftwidth automatically; it fixes half my headaches before I even open the file.
After sleuth, for Neovim I plug in nvim-treesitter with its indent module turned on — it understands syntax much better than old regex-based indent scripts. Pair that with either null-ls or coc.nvim (or ale if you prefer linters/formatters) to run real formatters like prettier, clang-format, shfmt, or rustfmt on save. That lets the language tools correct structural indentation rather than vim guessing.
Small extras that helped me: editorconfig-vim to respect project settings, indent-o-matic as a fallback detector in weird repos, and indent-blankline.nvim for visual guides so you can spot mistakes. Also don't forget filetype plugin indent on and sensible defaults (autoindent, smartindent/cindent where appropriate). With those layered, indentation accuracy improves dramatically and my diffs stop being a jungle of whitespace edits.
If you've ever opened a file in Vim and wondered why indentation behaves one way in one project and differently in another, the way filetype plugins and indent scripts interact is the usual culprit. In my messy but beloved setup I keep separate snippets in ~/.vim/ftplugin/ and ~/.vim/indent/ and they each have a job: ftplugin files generally set buffer-local editing options (things like shiftwidth, tabstop, expandtab, mappings) while indent scripts (under indent/) provide indentation logic by setting 'indentexpr', 'cindent', 'indentkeys', or related buffer-local options. Because these are buffer-local, whichever script writes a particular option last wins for that buffer.
Practically that means you can get conflicts. An ftplugin might set 'shiftwidth' to 4 for 'python' and an indent script might expect 2; or an indent script will set 'indentexpr' to a custom function that overrides simpler behaviors such as 'autoindent'. The usual fixes I use are: enable both with :filetype plugin indent on, then put overrides in after/ftplugin/ or after/indent/ so they load later; or explicitly set local options with setlocal in a ftplugin; or prevent an indent script with let b:did_indent = 1 if you deliberately want to skip it. For debugging, :scriptnames shows what got sourced, and :verbose setlocal shiftwidth? / :verbose setlocal indentexpr? tell you who last changed a setting. I like keeping ftplugin for styling and small mappings, and leaving indentation math to indent scripts — but I always keep an 'after' copy for those moments when I need the last word.
Okay — let me walk you through this like we’re debugging a stubborn editor together. In my experience inconsistent Vim indentation across buffers usually comes down to a few culprits: buffer-local options, filetype-specific plugins, modelines in files, or external tools like an .editorconfig plugin.
First, check what each buffer actually has set. Use :setlocal and :verbose set shiftwidth? tabstop? softtabstop? expandtab? and :set filetype? and :verbose set autoindent? — the verbose form tells you where a setting was last changed. If you see different values between buffers, that’s your clue: something is changing options per file. Often a ftplugin or indent script is overriding global settings, or a modeline inside a file is setting tabs/spaces.
To fix it, pick a consistent baseline in your vimrc/init.vim: filetype plugin indent on (or in Neovim, enable filetype and indentation early), then set sensible defaults like set tabstop=4 shiftwidth=4 softtabstop=4 expandtab or use set noexpandtab for projects that prefer tabs. If a project has specific rules, add an .editorconfig file and install the editorconfig plugin or add autocmds to apply per-filetype settings. When you need to find the source of an override, :scriptnames shows loaded scripts and :verbose set
If you're fiddling with Vim's indentation and want precise control, the trio I reach for is :set shiftwidth, :set tabstop, and :set softtabstop.
shiftwidth (sw) controls how many spaces a single indentation level uses for operations like >>, <<, and automatic indentation. I usually do :setlocal shiftwidth=4 for projects that use four-space indents. tabstop (ts) sets how many spaces a literal TAB character displays as; use :set tabstop=4 to make existing tabs line up visually with your intended width. softtabstop (sts) affects insert-mode behavior: :set softtabstop=4 makes pressing Backspace or Tab behave like you're working with 4-space logical tabs even if actual file uses tabs.
A couple of other practical commands I keep in my .vimrc: :set expandtab to insert spaces instead of real tabs (or :set noexpandtab to keep tabs), :set autoindent to keep the previous line's indentation, and :set cindent or :set smartindent for C-like auto-indenting. If you want the changes to apply only to the current buffer, use :setlocal sw=2 ts=2 sts=2. To reformat an entire file after changing settings, I often run gg=G to reindent the whole buffer, or :retab to convert tabs to spaces (or the reverse with :retab!). These little tweaks saved me hours when I was switching between Python, Makefiles, and Go projects.
Vim's expandtab feature is a lifesaver for anyone who prefers spaces over tabs for indentation. I stumbled upon this while working on a collaborative project where mixing tabs and spaces caused chaos in the codebase. To enable it, just type ':set expandtab' in command mode. This ensures every tab press inserts spaces instead of a tab character. You can customize the number of spaces with ':set tabstop=4' (or any number you prefer).
What's cool is that this pairs beautifully with 'autoindent' and 'smartindent' for seamless formatting. I once spent hours debugging an issue only to realize inconsistent indentation was the culprit—expandtab would've saved me the headache. Now it's the first thing I configure in my .vimrc for any new environment.
Vim's expandtab and tabstop settings are like the secret sauce for clean, readable code—especially if you collaborate with others. I learned the hard way after a project where mixing tabs and spaces caused chaos in version control. Now, I swear by 'set expandtab' to convert tabs to spaces, paired with 'set tabstop=4' for consistent indentation. It's not just about aesthetics; it prevents alignment issues across editors.
For languages like Python, where indentation is syntax, this setup is non-negotiable. I also combine it with 'set softtabstop=4' to make backspacing behave intuitively. Pro tip: If you ever need real tabs (e.g., Makefiles), just toggle 'noexpandtab' temporarily. It's one of those small tweaks that saves endless headaches.