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):
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.
I've been noodling with tiny projects and configs between classes, and my minimalist setup works great: keep it simple and local. In my ~/.vim/ftplugin/javascript.vim I have a few lines:
This gives me 2-space indentation and uses spaces, which keeps diffs cleaner when submitting PRs. If I open JSX or modern files, I sometimes switch smartindent off and rely on a plugin's indentexpr because smartindent can mess up multiline JSX. I also use an .editorconfig file across projects — it’s the easiest way to enforce consistent settings among different editors. For quick tidy-ups, I run gg=G, and for more disciplined formatting I call Prettier through an external tool or plugin, because it handles semicolons, trailing commas, and complex indentation reliably.
Honestly, when I tinker late at night, my aim is predictability with minimal fuss. My go-to is a tiny ftplugin that forces 2-space soft tabs and enable autoindent locally — no global side effects. Example essentials:
If you prefer tabs, change expandtab off and set tabstop appropriately, but beware mixing tabs and spaces. For harder JS constructs I rely on a small indent plugin so Vim knows how to handle template literals and JSX; otherwise I reformat with Prettier on save. One last tip: keep editorconfig in the repo so contributors get the same behavior — it saves so many tiny style arguments.
If I were to outline a checklist for someone who wants clean auto-indent for JavaScript in Vim, I'd do it like this: first, enable filetype indenting; second, set local tab/spaces policy; third, choose an indent engine (smartindent vs cindent vs plugin); fourth, add formatter integration.
Concretely, start with:
filetype plugin indent on
Then use local settings so other filetypes don't inherit JS rules:
Now pick an engine: avoid cindent for modern JS — it’s more C-focused. smartindent is fine for simple code, but for arrow functions, template literals, and JSX I recommend installing a dedicated indent script (search for 'vim-javascript' or 'vim-js-indent'). Those plugins typically set indentexpr for you and handle tricky cases.
I always couple indentation with a formatter: set up an autocommand to run Prettier or ESLint --fix on BufWritePre. That way, even if Vim's indenting slips on odd syntax, the formatter normalizes everything. Also, if you collaborate, respect the project's .editorconfig or package.json style fields to avoid formatting fights.
2025-09-08 00:54:00
17
View All Answers
Scan code to download App
Related Books
Dripping Forbidden: 100 Ways to Make Yourself Wet
Flimxy vic
10
23.8K
If you’re a delicate little flower who clutches pearls and believes sex should only happen in the missionary position with the lights off and your spouse’s permission, close this book immediately. Seriously. Put it down before you ruin your boring little life with uncontrollable wetness and questionable morals.
Still here? Good girl.
Welcome to Dripping Forbidden: 100 Ways to Make Yourself Wet — a ruthless, dripping-wet collection of one hundred filthy, plot-driven taboo stories that don’t just flirt with the line… they bend you over it, fuck you senseless, and leave you leaking.😉 💦
Aliens are a real thing, they are hidden, they are a secret, but they have their own agreement with earth.
They choose humans, ones that no one would miss, hated, forgotten, and abandoned kids, they are sent to a special facility, they are groomed and taught since birth about space, their new life, and their owner/CG/Lover.
Violet is one of those kids, born to an addicted mother, and an MIA father, but she never believed in the system, she didn't believe there was someone out there for her, until he came.
Now she refuses to let him go, space life would be coming sooner than later.
This is a cgl story/fluffy story.
Appologies for any misspelling or grammar mistakes.
Playing With Violet Ashlock
Austin Portwalt
Crazy ambitious billionare who loves making big deals. He loves money and wants more than what he has now. He loves his bachelor life and wants to continue it forever but too bad his parents set him an arrange marriage with Dubai's most successful businessman's daughter but he has no interest dating the half american half italian girl. So he decided to use someone else.
Violet Ashlock
Classy. Arrogant. Proper. That 3 words describe her perfectly. One day, she met Austin Portwalt at her friend's party and hooked up a little bit. She likes him but he doesn't. She tried to take his attention but it never worked until he set his eyes on her suddenly without any warning. Dating her while making deals here and there.
Where to find the perfect man?
You program him of course.
I'm a genius, lonely, touch-deprived genius.
Roman is a top programmer for a robot company, he's trying to create a new program to introduce human feelings to the bots. Deciding to get a Bot for himself to keep him company it all went well until that night.
The robot with the artificial intelligence classified his creator as a little, being treated like a little wasn't that weird first until the first punishment.
Roman just did his biggest mistake, or best decision yet.
Warning: This story is DDLB, MDLB, CGL story, don't like it don't read it.
Apologies for any misspelling or grammar mistakes.
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."
I've sculpted a character based on my boss, Jacob Carter, in my smutty novel.
Jacob, who's a cold, distant, and stern man in reality, is reduced to a lovesick simp in my novel. Apparently, he's maddeningly in love with me there.
But when I tender my resignation letter later on, Jacob rips it into shreds before cornering me.
"Oh? Are you planning to leave now that you've finished writing that novel of yours? How dare you discard me as soon as you're done with me! What am I, a cheap escort?"
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.
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 — 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
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.
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'll be blunt: yes, you absolutely can set up Vim to auto-indent differently per project directory, and I've done it a bunch of times across projects with different coding styles.
When I need a project-specific policy I usually pick one of three safe routes: use a repository-level '.editorconfig' with the EditorConfig Vim plugin (works across editors and is a huge life-saver), add per-project autocommands in my global vimrc that match the project path, or—if I must—use a controlled local vimrc mechanism (with security checks). For example, in your main vimrc you can add an autocmd that applies settings only when the buffer lives under a particular path:
augroup proj_indent
autocmd!
autocmd BufRead,BufNewFile /path/to/myproj/* setlocal shiftwidth=4 tabstop=4 expandtab
augroup END
That keeps the rules scoped to files under that directory. I avoid blindly enabling 'exrc' because executing arbitrary project .vimrc files can be risky; instead I either require a checked-in '.editorconfig' or use a trusted plugin like 'localvimrc' that prompts you before sourcing. Also remember to use setlocal so other projects aren’t affected. For Neovim, the same autocmds work, but I often detect the project root via an LSP/root_pattern helper and then apply settings dynamically. Overall, choose EditorConfig if you want a cross-editor approach, or autocommands if you prefer staying purely in Vim land.
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.
Vim is my go-to editor. The autocomplete plugins I swear by are 'coc.nvim' and 'YouCompleteMe'. 'coc.nvim' is a game-changer because it integrates with the Language Server Protocol (LSP), giving you IDE-like features without leaving Vim. It's incredibly responsive and supports not just autocomplete but also linting, formatting, and even debugging. The setup can be a bit involved, but once it's running, it feels like magic. I love how it suggests imports and even detects errors in real-time.
'YouCompleteMe' is another powerhouse, especially for larger projects. It's fast and supports fuzzy matching, so you don't have to type exact names to get suggestions. The downside is it can be heavy on resources, but if you have a decent machine, it's worth it. I also dabble with 'deoplete.nvim', which is lighter and works well with Neovim. It's not as feature-rich as 'coc.nvim', but it's perfect if you want something minimal and fast. The key is to experiment and see which one fits your workflow.
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.
Customizing the JSON formatter in Vim is a pretty exciting process that can really enhance how you interact with your code. First off, I always start by checking if I have the necessary plugins installed, like 'vim-jq' or 'vim-json'. These plugins make your coding experience way smoother with syntax highlighting and better formatting options.
Once I've got those set up, diving into my .vimrc file is the next step. I might add specific settings that cater to my personal style. For example, I value the readability of my JSON files, so I often go for `set tabstop=2` and `set shiftwidth=2`, which makes my indentation a lot cleaner. This way, when I save or format my files, everything looks neat and tidy.
Moreover, playing around with custom commands like `autocmd FileType json setlocal formatoptions+=cro` can help format comments correctly, which is great when I'm collaborating on projects with others. Trust me, once you start tweaking these little settings, you'll notice a huge difference in how you manage your JSON files in Vim! It even feels more personal and unique to your coding flow.