Pressing Enter removes indentation

14 views
Skip to first unread message

Steven Penny

unread,
Feb 16, 2020, 11:06:21 PM2/16/20
to v...@vim.org
If I have a file "a.js" like this:

let a1 = [
];

and I press Enter at the end of the first line, a Tab is inserted. I do not
want this. I added setting "filetype indent off", but then if I have this:

let a1 = [
10,
20
];

I have to manually add tabs for each item. So I added another setting
"set autoindent". These two settings solve the existing problems, but introduce
a new problem. If I move the cursor to the start of one of the indented lines,
and press Enter, the indentation is removed.

Another option is to use "set smartindent", and redo the second example.
However after I press Enter, if I then press Up or Down, the indentation is
removed, repeating the problem. Can I change a setting to resolve this issue?

Steven Penny

unread,
Feb 16, 2020, 11:06:21 PM2/16/20
to v...@vim.org

Steven Penny

unread,
Feb 16, 2020, 11:06:21 PM2/16/20
to vim_use

Tony Mechelynck

unread,
Feb 16, 2020, 11:59:20 PM2/16/20
to vim_use, Vim mailing list
Hm, this sounds like wanting to have your cake and eating it, but maybe not.

If you can describe to yourself exactly what you want when, then maybe
you can write the appropriate :setlocal statement for the appropriate
indent options in ~/vimfiles/after/indent/javascript.vim (for Windows)
or in ~/.vim/after/indent/javascript.vim (for Unix-like systems
including Linux and Mac OSX), overriding what is set by defaut when
you have :filetype plugin indent on. The defaut settings are set in
the script $VIMRUNTIME/indent/javascript.vim, which you should not
modify because any change you make in that script can be silently
unmade by any later update of Vim. But you can override all or part of
it by means of an "after" script in your own user space, as described
above.

Best regards,
Tony.
Reply all
Reply to author
Forward
0 new messages