Minimal but nice neovim configuration

I’m trying to set up neovim to be i tiny bit nicer and more modern.

I was trying to search github for examples, but I only find huge elaborate bloated configurations which are hard to disect.

I have a base setup using home-manager, and all I want is for it to drop down suggestions for nix language (and maybe nixpkgs?). Highlighting nix syntax errors would also be nice.

And I would really want it to stay small and not bloated. Having a language server running in bg, eating 1+GB of ram is not an option.

does anyone have any suggestions?

2 Likes

You can run distrobox on Nixos.
So you can then run a plain vanilla Linux OS, and run Neovim from there.

There are lots of choices for how to run Neovim within Nixos. It can be overwhelming. Sticking Nixvim on Home Manager seems to be the fashionable route.
Thereafter the complexity of the setup is up to you. You can just stick all your config in one file…

1 Like

I’ve really enjoyed the kickstart.nvim template. Everything is clear and documented and it’s helped me set neovim the way I want to.

For the LSP side, I’m passing the tools I need from home-manager like this and in neovim I it check if I’m in NixOS like this so it doesn’t install the tools through Mason, but still load them in lsp-config. The advantage of doing this is that my config is portable in other distros where Mason will download the tools I need.

There is kickstart-nix.nvim which is based on kickstart.nvim and is tailored to run on Nix out of the gate, so I suggest you take a look at that first if you want something simple that just works.

2 Likes

oh my! running neovim is a VM is the most bloated configuration i could think of )

the thing is that I have 2 problems here:

  1. i don’t know how to set up vim to do autocompletion+syntax check for nix+nixpkgs (also without bloat)
  2. i don’t know how to do 1) with home-manager config :slight_smile:

i’ll check that kickstart,nvim, thank you

as for LSPs - i’m just trying to be cautious, i want my vim to stay sorta minimal, will investigate the things you suggested

1 Like

Here is my recommendation:

  1. Create a vim configuration you ‘like’ outside of nix.
  2. use nixvim to recreate the configuration in nix.

This is a minimal vim config using nixvim. should get you started:

{ pkgs, nixvim, programs, ...}:
{
  programs.nixvim = {
    enable = true;
    globals.mapleader = " ";

    options = {
      relativenumber = true;
      incsearch = true;
    };

    colorschemes.onedark.enable = true;
    plugins.lualine.enable = true;
    plugins.nix.enable = true;

    plugins.treesitter.enable = true;

    plugins.telescope.enable = true;

    plugins.harpoon = {
      enable = true;
      keymaps.addFile = "<leader>a";
    };

    plugins.lsp = {
      keymaps = {
        silent = true;
        diagnostic = {
          "<leader>k" = "goto_prev";
          "<leader>j" = "goto_next";
        };

        lspBuf = {
          gd = "definition";
          K  = "hover";
        };
      };
    };
  };
}

type or paste code here

1 Like

Just to make something clear: to have nix & nixpkgs autocompletion, you need a tool to provide those. And given the structure of Nix I believe the only thing to properly provide that is nil - which in your words is “too bloated”. Your request is not “just autocompletion”', in technical terms it’s “even autocompletion”. It might be possible to get autocompletion for “simple” languages like C without an LSP (e.g. by using ctags), but it’s hard (or even impossible?) for functional languages like Nix.

I know your situation. I’ve been in more than enough situations where I just wanted something seemingly simple. But this sadly doesn’t work out most of the time. I’d recommend you take 2-3hours to try and write your own configuration. It took me over a year to take that step for neovim (have used vim for forever, just didn’t want to learn the nvim lua style when I decided to switch back from emacs) and I finally wrote a config a few months ago. It’s well worth it IMO

2 Likes

As a tip, set neodev.nvim to this:

  -- `neodev` configures Lua LSP for your Neovim config, runtime and plugins
  -- used for completion, annotations and signatures of Neovim apis
  {
    'folke/neodev.nvim',
    opts = {
      library = {
        runtime = false, -- runtime path
        types = true, -- full signature, docs and completion of vim.api, vim.treesitter, vim.lsp and others
        plugins = false, -- installed opt or start plugins in packpath
      },
    },
  },

The lua lsp won’t autocomplete plugin/runtime, but at least it won’t start with 1GB+ of memory.

nil runs with <1MB of memory for me. I believe sirphobos meant the configs he found were bloated in general.

This is absolutely true, though. The more time you invest in your configs the best they will be and the more you’ll be comfortable using them.

Ah, ok. Well given your criteria, why not switch to Helix?

2 Likes

i understand that i have to have some kind of LSP, but what I would consider bloated is if that LSP requires 100 nodejs modules and is eating 500+ MB of ram - then I’d better just stretch my human memory a bit :slight_smile:

I was very much expecting possibility that such setup is impossible, so no problem with that. I do have my minimal vim config, so it works both in tty, and in graphical mode, and eats below 10 MB of ram, i just wanted to improve it with LSP features while trying to keep it minimal.

now that is interesting - will try it too

googling Helix… :slight_smile:

first thoughts:

  • oh my, having hotkeys similar to vim, but not the same just broke my brain :slight_smile:
  • It seems that it doesn’t come with embedded LSPs, so then what benefit do I get in switching? it seems that my original question would apply to helix the same way, no?
1 Like

It’s actually the opposite. You just need to add the tools you need in extraPackages and they will automatically be loaded. For example:

  programs.helix = {
    enable = true;
    extraPackages = [
      nil
    ];
  };

Then when you open a nix file, nil will be automatically configured and working.

I find helix to be quite fast and comfortable since it shares a lot of its default keys with vim. However, it still lacks a lot of things (no file tree :frowning:) and is still not as extensible as Neovim. Hopefully this gets solved in the future, though.

wooooooooow! now it actually does everything i’ve wanted ! Just like that, with no configuration!

now then a side question: does it worth re-learning helix hotkeys, or is there a fully working vim keymap available?

1 Like

This is the first time I use it so I’m not sure, but I suppose you can remap your keys. Maybe you can look around, there is a possibility that someone has already done this.

You can also read the documentation and try to run it for a few days to see how it feels.

https://docs.helix-editor.com/title-page.html

Remapping
https://docs.helix-editor.com/remapping.html

Helix is selection:action
Neovim is action:selection

I actually prefer Helix, but probably just me

1 Like

You need to install nil as a package, then:

[:penguin:]/.config/helix took 6s :palm_tree::palm_tree: ln
drwxr-xr-x - marcus 2 mai 07:53 .
.rw-r–r-- 249 marcus 16 mai 18:58 ├── config.toml
.rw-r–r-- 558 marcus 16 mai 21:37 └── languages.toml

[[language]]
name = “nix”
scope = “source.nix”
injection-regex = “nix”
file-types = [“nix”]
roots = [“shell.nix”, “default.nix”]
auto-format = true
diagnostic-severity = “Hint”
comment-token = “#”
indent = {tab-width = 2, unit = " "}
language-server = {command = “nil”}

[:penguin:]/.config/helix :palm_tree::palm_tree: hx --health nix
Configured language server: nil
Binary for language server: /run/current-system/sw/bin/nil
Configured debug adapter: None
Highlight queries: ✓
Textobject queries: ✘
Indent queries: ✘

I am just playing about, need to debug

1 Like

And someone already did, indeed. Worth looking at if that’s what you want to do: helix-vim

I don’t know if you need to define all of this in the configs as it seems to work fine by default.

PS: The example in the Wiki is quite nice.

1 Like

Ah ok.
I was just following the manual

https://docs.helix-editor.com/lang-support.html

So in fact there is no auto-indent for nix

1 Like

thank you all,
resolution to my problems was just to use helix
but later i’ll try to set up vim in a similar way too

2 Likes

https://nix-community.github.io/nixvim/

Nixvim is great for neovim.

I really have split loyalties between Helix and Nvim…

But I’m like you, I really like Helix’s simple approach

2 Likes