"preserving" current indentation in javascript

23 views
Skip to first unread message

Stefan Zehl

unread,
Apr 28, 2024, 8:07:53 AMApr 28
to vim...@googlegroups.com
Hi,

I have stumbled upon the following issue with the default javascript
indentation:

Let's assume that I have the following function with incosistent indenting:

function hello(loc){
console.log("hello",loc);
if (loc == "world"){
console.log("the whole world");
}
return true;
}

Now if I move the cursor to the "the whole world" line and press o to open a
new line, the cursor sits at column 9, not at column 7 where the
previous line started.

I have found that this seems to be, because at that point I had
shiftwidth set to 4.

The issue is, I'm editing code (written by someone else) that has
inconsistent indentation, so if I set "sw" to "2", it just breaks the
same way in other locations (this time for example with first
console.log line)

Is there a way to fix it so it honors the indentation of the current
block by default much like the builtin "c" indenting that vim has?

CU,
Sec
--
"Life is pleasant. Death is peaceful. It's the transition that's
troublesome." - Isaac Asimov

Doug Kearns

unread,
Apr 29, 2024, 6:16:29 AMApr 29
to vim...@googlegroups.com
On Sun, 28 Apr 2024 at 22:07, Stefan Zehl <s...@42.org> wrote:

<snip>

Is there a way to fix it so it honors the indentation of the current
block by default much like the builtin "c" indenting that vim has?

I agree that this would be the most desirable behaviour.

The file looks complex enough that ad-hoc suggestions would probably be counter productive so I'd suggest reporting it to the maintainer listed in the header, https://github.com/pangloss/vim-javascript, and see what they think.

Regards,
Doug
Reply all
Reply to author
Forward
0 new messages