When file type plugin indent is enabled, Vim struggles to properly indent the text

I currently have the filetype plugin indent setting in my ~/.vimrc file, but it seems to be causing issues with the indentation of JSON objects.

When I start vim using

vim -N -u NONE <filename.js>

I am enabling both :filetype plugin indent on and :set sw=4 fileetype=javascript

However, this is the result I am seeing:

var foo = {
    Bar: function(){
         },
    Baz: function(){
         } 
}; 

This is how I would like it to look -- is there a way to achieve this? :

var foo = {
    Bar: function(){
    },
    Baz: function(){
    } 
};

The reason behind enabling the indent plugin was to make block commenting easier. If I type /* <enter>, it should assume I'm starting a block documentation comment. However, if it continues to affect the ending brace of my JSON object, then I will refrain from using it.

Answer №1

A fantastic indent script by Ryan Fabella can be found here; it perfectly indents your code snippets according to your preferences.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I need to show a DIV element when a specific anchor is in an active state within an HTML document

Is there a way to make the code below only visible when the url ends with #404? <!--404 code--> <style> .div1 { width: 300px; height: 100px; border: 1px solid blue; border-color: #ff0263; box-sizing: border-box; } < ...

Erase the dynamically loaded page using ajax and conceal the div

Currently, I am utilizing the .on() method with jQuery to display a specific div, and also using .load() to fetch a particular div from a web page hosted on my server. My query is how can I close this div when clicking outside of it, along with removing i ...

What could be causing an error to be thrown when I call the destroy function for my waypoints

After experimenting with waypoints.js (jQuery version), I decided to share my progress so far. If you want to take a look, click here. In my current setup, the 'destroy' function for waypoints has this code snippet attached: $('.destroy&ap ...

Fail to properly implement Volley's JSON onResponse function

I am having trouble extracting the result from the onResponse when I call getData. It seems like this current approach is not effective. Can anyone provide assistance in resolving this issue? getData() private void getData(){ //Creating a string req ...

Swap out a web link for an embedded iframe

Currently working on updating internal links: <div class="activityinstance"> <a href="http://website.com/hvp/view.php?id=515512">activity</a> </div> The goal is to convert them into: <div class="activityinstance"> ...

JavaScript tip: How to disregard symbols that affect the length of text in a textbox?

I am working on a task which involves counting only the text, excluding symbols, entered in a textbox. For instance, if a user types email_ex_3/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="05374568646c692b666a68">[email ...

How can you exclude selected values in React-select?

Here is how I have defined my select component: this.state.list = [{label: "test1", value:1}, {label:"test2", value:2}, {label:"test3", value:3}] this.state.selected = [{label:"test2", value:2}] let listMap = this.state.list let list = this.state.list { ...

Utilizing Grunt with Bootstrap 5 for streamlining and optimizing JavaScript code bundling

After successfully bundling the Bootstrap 5 SCSS files using Grunt, I now want to do the same with the JavaScript files. I am using grunt-contrib-uglify for this task: uglify: { site: { options: { sourcemap: false }, ...

The following page shrouded in mystery is experiencing technical issues

Encountering some issues on the live server with this code. It's functioning perfectly fine on my local machine, but once I try to deploy it on Netlify, I'm running into this error message: ⨯ useSearchParams() should be wrapped in a suspense bo ...

Uploading an image to the server using JQuery library and FormData

I have reviewed numerous solutions, but I am unable to identify the issue in my code. HTML: <div id='image-uploader-view'> <input type='text' id='rename' name='rename'/> <input id='fileu ...

Retrieve data from an AngularJS scope within Directives

I am facing an issue with accessing a scope variable from the app controller in order to update it on a click event triggered by a custom Directive. It appears that the isolated scope of the Directive is unable to access the global scope. The scope variab ...

What is the best way to create a slideshow that automatically starts upon loading and pauses when hovered over?

I have recently set up a div element for my slideshow. I've included a script to enable navigation using next and previous arrows. However, I am looking to add an automatic slideshow feature that stops on hover. As a beginner, I would appreciate any a ...

Guide to retrieving the data type of a List Column using SharePoint's REST API

I am currently attempting to determine the type of columns in my SharePoint list so that I can accurately populate a form with the appropriate field types. During my research, I stumbled upon this informative article in the documentation which discusses ac ...

Troublesome issue with custom select feature in foundation when used within a button

I'm currently incorporating Zurb Foundation 4 into my website and using the "custom forms" feature for special styling on form elements. The issue I'm facing is that HTML select elements aren't functioning properly when placed inside a butto ...

The problem with the CSS Grid effect

Looking for assistance in creating a grid layout similar to the one on this website: Upon inspecting the page source, I found the following code snippet: http://jsfiddle.net/o45LLsxd/ <div ng-view="" class="ng-scope"><div class="biogrid ng-scope ...

Error: The node.js V12.18.2 software encountered a problem and is unable to read the property 'startsWith' of an undefined variable

I'm new to this platform, so please forgive any errors in my formatting. I'm facing an issue with Node.js on my laptop - it doesn't work here but works perfectly fine on another computer. Below is the code I am using: const Discord = require ...

How to remove a specific item from an array in MongoDB using JavaScript

So, I've retrieved a nested array from a database query. The query brings back the following data: { _id: new ObjectId("623rf3f22275f399f88bb"), first_name: 'Are', last_name: 'You', email: '<a href="/cdn-cgi/l/email ...

Is it possible to retrieve JSON output from the "call db.schema.nodeTypeProperties()" function in C# or Java when using Neo4J CYPHER?

Is there a way to fetch the JSON schema returned by db.schema.nodeTypeProperties() in the Neo4J Browser using C# or Java with the Neo4J.Driver? I need to deserialize this JSON data into C# classes. Screenshot of the Response drop-down from db.schema.nodeT ...

Transferring values with jQuery

I attempted to customize the appearance of the select dropdown options, but unfortunately, the value of the options is not being transferred to the new jQuery-created class. Due to this issue, I am unable to achieve the desired outcome. The expected behavi ...

How come the method $.when().pipe().then() is functioning properly while $.when().then().then() is not working as expected

I'm still grappling with the concept of using JQuery's Deferred objects, and am faced with a puzzling issue. In this code snippet, my attempt to chain deferred.then() was unsuccessful as all three functions executed simultaneously. It wasn't ...