Skip to content

Commit ff5386b

Browse files
authored
Add indentation solution for powershell in vim/neovim (#2238)
1 parent 8d89c94 commit ff5386b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/guide/getting_started.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,26 @@ require('lspconfig')['powershell_es'].setup {
122122
settings = { powershell = { scriptAnalysis = { settingsPath = custom_settings_path } } }
123123
}
124124
```
125+
126+
### Indentation
127+
128+
Vim/Neovim does not contain default `:h indentexpr` for filetype `ps1`.
129+
So you might notice indentation on newline is not behaving as expected for powershell files.
130+
Luckily powershell has similar syntax like C, so we can use `:h cindent` to fix the indentation problem.
131+
You can use the following snippet to either callback of an autocmd or ftplugin.
132+
133+
```lua
134+
--- ./nvim/lua/ftplugin/ps1.lua
135+
136+
-- disable indent from powershell treesitter parser
137+
-- because the parse isn't mature currently
138+
-- you can ignore this step if don't use treesitter
139+
if pcall(require, 'nvim-treesitter') then
140+
vim.schedule(function() vim.cmd([[TSBufDisable indent]]) end)
141+
end
142+
143+
vim.opt_local.cindent = true
144+
vim.opt_local.cinoptions:append { 'J1', '(1s', '+0' } -- see :h cino-J, cino-(, cino-+
145+
146+
vim.opt_local.iskeyword:remove { '-' } -- OPTIONALLY consider Verb-Noun as a whole word
147+
```

0 commit comments

Comments
 (0)