0

When inserting a block comment in a (TypeScript) buffer in Neovim, the line after the /**<Return> is not automatically indented. How can I achieve the expected behavior described below?

Neovim

NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@BigSur

expected behavior


function f() {
  /**<hit return>
   * <cursor is here>
  return 0;
}

actual behavior


function f() {
  /**<hit return>
* <cursor is here>
  return 0;
}

(potentially) relevant option states


:verbose set autoindent? smartindent? cindent? cinkeys? indentexpr? comments? fo-table?
  autoindent
        Last set from ~/.config/nvim/init.vim line 51
nosmartindent
        Last set from /usr/local/Cellar/neovim/0.7.2_1/share/nvim/runtime/indent/typescript.vim line 16
nocindent
  cinkeys=0{,0},0),0],:,0#,!^F,o,O,e
  indentexpr=nvim_treesitter#indent()
        Last set from Lua
  comments=sO:* -,mO:*  ,exO:*/,s1:/*,mb:*,ex:*/,f://
        Last set from ~/.config/nvim/init.vim line 187
  formatoptions=cro/n
        Last set from ~/.config/nvim/init.vim line 186
E488: Trailing characters: fo-table?

init.vim

autocmd!
scriptencoding utf-8
if !1 | finish | endif

set nocompatible
set number
syntax enable
set fileencodings=utf-8,sjis,euc-jp,latin
set encoding=utf-8
set title
set background=dark
set nobackup
set hlsearch
set showcmd
set cmdheight=1
set laststatus=2
set scrolloff=10
set expandtab
set shell=fish
set backupskip=/tmp/*,/private/tmp/*

if has('nvim')
  set inccommand=split
endif

set t_BE=

set nosc noru nosm
set lazyredraw
set ignorecase
set smarttab
filetype plugin indent on
set shiftwidth=4
set tabstop=4
set autoindent
set smartindent
set nowrap "No Wrap lines
set backspace=start,eol,indent
set path+=**
set wildignore+=*/node_modules/*

set number

autocmd InsertLeave * set nopaste

set shortmess=I

set cursorline

highlight Visual cterm=NONE ctermbg=236 ctermfg=NONE guibg=Grey40

highlight LineNr cterm=none ctermfg=240 guifg=#2b506e guibg=#000000

augroup BgHighlight
  autocmd!
  autocmd WinEnter * set cul
  autocmd WinLeave * set nocul
augroup END

if &term =~ "screen"
  autocmd BufEnter * if bufname("") !~ "^?[A-Za-z0-9?]*://" | silent! exe '!echo -n "\ek[`hostname`:`basename $PWD`/`basename %`]\e\\"' | endif
  autocmd VimLeave * silent!  exe '!echo -n "\ek[`hostname`:`basename $PWD`]\e\\"'
endif

au BufNewFile,BufRead * if !expand('%:t') | setlocal shiftwidth=4 | endif
au BufNewFile,BufRead * if &syntax == '' | setlocal shiftwidth=4 | endif
au BufNewFile,BufRead * if &buftype == '' | setlocal shiftwidth=4 | endif

au BufNewFile,BufRead *.es6 setf javascript
au BufNewFile,BufRead *.tsx setf typescriptreact
au BufNewFile,BufRead *.md set filetype=markdown
au BufNewFile,BufRead *.mdx set filetype=markdown
au BufNewFile,BufRead *.flow set filetype=javascript
au BufNewFile,BufRead *.fish set filetype=fish

set suffixesadd=.js,.es,.jsx,.json,.css,.less,.sass,.styl,.php,.py,.md

autocmd FileType json setlocal shiftwidth=2 tabstop=2
autocmd FileType javascript setlocal shiftwidth=2 tabstop=2
autocmd FileType typescriptreact setlocal shiftwidth=2 tabstop=2
autocmd FileType typescript setlocal shiftwidth=2 tabstop=2
autocmd FileType markdown setlocal shiftwidth=4 tabstop=4
autocmd FileType sql setlocal shiftwidth=4 tabstop=4
autocmd FileType vue setlocal shiftwidth=2 tabstop=2
autocmd FileType html setlocal shiftwidth=2 tabstop=2
autocmd FileType css setlocal shiftwidth=2 tabstop=2

runtime ./plug.vim
if has("unix")
  let s:uname = system("uname -s")
  " Do Mac stuff
  if s:uname == "Darwin\n"
    runtime ./macos.vim
  endif
endif
if has('win32')
  runtime ./windows.vim
endif

runtime ./maps.vim
runtime ./commands.vim

if exists("&termguicolors") && exists("&winblend")
  syntax enable
  set termguicolors
  set winblend=0
  set wildoptions=pum
  set pumblend=5
  set background=dark
  " Use NeoSolarized
  let g:neosolarized_termtrans=1
  runtime ./colors/NeoSolarized.vim
  colorscheme NeoSolarized
endif

autocmd BufEnter * lua vim.diagnostic.disable()

set exrc
set signcolumn=yes
set clipboard+=unnamedplus

au Filetype * set formatoptions=cro/n
au Filetype * set comments-=:// comments+=f://

let g:vimwiki_key_mappings =
  \ {
  \   'all_maps': 1,
  \   'global': 1,
  \   'headers': 1,
  \   'text_objs': 1,
  \   'table_format': 1,
  \   'table_mappings': 0,
  \   'lists': 1,
  \   'links': 1,
  \   'html': 1,
  \   'mouse': 0,
  \ }

7
  • Welcome to Vim :-). Could you tell what is the filetype of your buffer? What is the result of the :set ft?? Feb 16, 2023 at 7:36
  • From the content of your file I have supposed your buffer type is lua. Using Neovim 0.8.2 I fail to reproduce your problem. But indentexpr is set to GetLuaIndent() Feb 16, 2023 at 7:45
  • You want to use :setlocal in the last command there to make sure you are not looking at the global options, I think.
    – D. Ben Knoble
    Feb 16, 2023 at 15:31
  • the filetype of my buffer is TypeScript
    – KIYZ
    Feb 16, 2023 at 20:16
  • I tried setlocal comments and setlocal formatoptions but got the same behavior.
    – KIYZ
    Feb 16, 2023 at 20:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.