From 2cb873297882f21ffe5dacaa838b70596c742e25 Mon Sep 17 00:00:00 2001 From: sharpchen Date: Mon, 30 Jun 2025 07:42:15 +0800 Subject: [PATCH] Add indentation solution for powershell in vim/neovim --- docs/guide/getting_started.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/guide/getting_started.md b/docs/guide/getting_started.md index 696e102af..1b6a98776 100644 --- a/docs/guide/getting_started.md +++ b/docs/guide/getting_started.md @@ -122,3 +122,26 @@ require('lspconfig')['powershell_es'].setup { settings = { powershell = { scriptAnalysis = { settingsPath = custom_settings_path } } } } ``` + +### Indentation + +Vim/Neovim does not contain default `:h indentexpr` for filetype `ps1`. +So you might notice indentation on newline is not behaving as expected for powershell files. +Luckily powershell has similar syntax like C, so we can use `:h cindent` to fix the indentation problem. +You can use the following snippet to either callback of an autocmd or ftplugin. + +```lua +--- ./nvim/lua/ftplugin/ps1.lua + +-- disable indent from powershell treesitter parser +-- because the parse isn't mature currently +-- you can ignore this step if don't use treesitter +if pcall(require, 'nvim-treesitter') then + vim.schedule(function() vim.cmd([[TSBufDisable indent]]) end) +end + +vim.opt_local.cindent = true +vim.opt_local.cinoptions:append { 'J1', '(1s', '+0' } -- see :h cino-J, cino-(, cino-+ + +vim.opt_local.iskeyword:remove { '-' } -- OPTIONALLY consider Verb-Noun as a whole word +```