this post was submitted on 06 Sep 2023
5 points (85.7% liked)

Neovim

1728 readers
1 users here now

Neovim is a modal text editor forked off of Vim in 2014. Being modal means that you do not simply type text on screen, but the behavior and functionality of the editor changes entirely depending on the mode.

The most common and most used mode, the "normal mode" for Neovim is to essentially turn your keyboard in to hotkeys with which you can navigate and manipulate text. Several modes exist, but two other most common ones are "insert mode" where you type in text directly as if it was a traditional text editor, and "visual mode" where you select text.

Neovim seeks to enable further community participation in its development and to make drastic changes without turning it in to something that is "not Vim". Neovim also seeks to enable embedding the editor within GUI applications.

The Neovim logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.

founded 3 years ago
MODERATORS
 

I'm trying to use LazyVim https://www.lazyvim.org/ to create and edit ansible playbooks and roles, but for the live of my I don't understand how to enable ansible-language-server.

The installation of lazyvim went flawless and after starting nvim I used the command :Mason to install:

  • ansible-language-server
  • ansible-lint
  • yaml-language-server
  • yamllint

but still, when opening a task or playbook file in nvim, i don't get any of that cool features like snippets and automatic syntax checking like I hoped.

Can anyone give me a hint how to enable those? Mason says the plugins are installed, is it only a problem of nvim not recognizing the filetype as ansible? Do I need to enable some plugins via .config/nvim/lua/plugins? I'm out of my element here, help would be much appreciated.

top 7 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

I created an auto command for this

-- Ansible file pattern
  vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile", "BufEnter" }, {
    group = vim.api.nvim_create_augroup("Ansible", { clear = true }),
    pattern = {
      "*/roles/*/*/*.yaml",
      "*/roles/*/*/.yml",
      "main.yml",
      "main.yaml",
      "Debian*.yaml",
      "Debian*.yml",
      "*/ansible-devbox/*.yaml",
      "*/ansible-devbox/*.yml",
      "group_vars/*.yml",
      "group_vars/*.yaml",
      "files/*.yaml",
      "files/*.yml",
      "environments/*.yaml",
      "environments/*.yml,",
    },
    callback = function()
      vim.opt.filetype = "yaml.ansible"
    end,
  }),
[–] [email protected] 1 points 1 year ago (1 children)

it's working now but ill try that. looks like a better solution then my current .config/nvim/ftdetect/ansible.vim hack. your snipped goes into .config/nvim/init.lua i guess?

[–] [email protected] 1 points 1 year ago

It’s going in my .config/nvim/lua/config/autocmds.lua

I use lazyvim

[–] [email protected] 1 points 1 year ago (1 children)

Can you paste the output of :LspInfo when opening an ansible file? Wait a few seconds after opening the file to give the language server time to load

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

LspInfo

 Language client log: /home/me/.local/state/nvim/lsp.log
 Detected filetype:   yaml
 
 1 client(s) attached to this buffer: 
 
 Client: yamlls (id: 1, bufnr: [1])
 	filetypes:       yaml, yaml.docker-compose
 	autostart:       true
 	root directory:  Running in single file mode.
 	cmd:             /home/me/.local/share/nvim/mason/bin/yaml-language-server --stdio
 
 Configured servers list: lua_ls, yamlls, bashls, ansiblels, tsserver, jsonls

Looks like the file is recognized as yaml but not as ansible.

[–] [email protected] 1 points 1 year ago (1 children)

Try putting # vim:ft=yaml.ansible at the top of your file then re-opening it

[–] [email protected] 2 points 1 year ago

that work, but since I don't want to touch all my yaml files, I looked into the ftdetect file I already created and saw an error in my path definition.

its working now. last thing i haven't found out is, how to tell nvim to check syntax periodically and not only when saving. other then that it works pretty well. thank you