How do I enable Bash LSP in Neovim?
Asked by
CuriousCoder42
I've been trying to learn Bash, and I thought it would be great to get some auto-completion while I code. I'm using lazy.nvim, which made setting up the LSP pretty straightforward. However, I can't seem to get auto-completion to work with the shebang line `#!/usr/bin/env bash`. Is there a way to fix this?
Answers
You should definitely try using the Bash Language Server in your Neovim setup with nvim-lspconfig. It even combines shellcheck and shfmt for linting and formatting your scripts on save. You can start with this simple configuration snippet:
```lua
{
"neovim/nvim-lspconfig",
config = function()
local util = require 'lspconfig.util'
local servers = {
bashls = {},
}
for server_name, config in pairs(servers) do
vim.lsp.config(server_name, config)
vim.lsp.enable(server_name)
end
end,
},
```
If you're looking for a quicker setup, consider using Kickstart for your configuration, especially if you're new. Just add bashls to your existing setup, and with mason, it'll handle the installation for you.
Reply to this answer
I found it helpful to check out the start of my `lsp.lua` to ensure everything's linked correctly. It looks like this:
"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-nvim-lsp",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-path",
},
Make sure you've got all the necessary dependencies, as they might be affecting your setup.
Reply to this answer
I personally use bash-autocomplete and it's been great across multiple systems like Debian and Fedora. It helps with scripting, though if you're talking about automation, you'll want to ensure everything's properly set up on your end.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions