1

I am using Javascript with typescript if it matters (I don't think it does for this question for reasons that I will explain later) and I have the following code:

veryLongFunctionName(arg1: type,
                     arg2: type,
                     arg3: type) {
  /* ... */
}

But when I try to make a new line in the function body it auto indents to one indent past the arg3's column in the header. For example, since my indentation is set to two spaces, typing osomeCode<ESC> when my cursor is on arg3 results in the following.

veryLongFunctionName(arg1: type,
                     arg2: type,
                     arg3: type) {
                       someCode
  /* ... */
}

Which is obviously not what I would like, I want its indentation level to be based upon the indentation of the function header itself. Even when I remove the typescript and javascript syntax plugins from my .vimrc, it bases its indentation on the wrong line like so.

veryLongFunctionName(arg1: type,
                     arg2: type,
                     arg3: type) {
                     someCode
  /* ... */
}

Only when I completely remove the filetype plugin indent on line from my .vimrc does the cursor not auto-indent to the column of arg3 (because it doesn't indent at all).

Is there a simple solution to this problem?

  • The code responsible for this is your indent plugin for the filetype you're editing. :set filetype? will tell you the filetype, which may very well be Type Script. You'll then need to find and edit the plugin responsible. Depending on what you want, this could be very tricky to get right: your example is one of many corner cases, and it's tricky to make them all work right at the same time: that's why indentation is sub-optimal in every editor. – jpaugh Jul 17 '17 at 19:29
  • If it's too frustrating to deal with, as with a few obscure filetypes I've dealt with, then turning off filetype indent, and then :set autoindent is a reasonable compromise. – jpaugh Jul 17 '17 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.