Skip to content

Commit

Permalink
rewrite neovim config
Browse files Browse the repository at this point in the history
  • Loading branch information
ksevelyar committed May 31, 2024
1 parent c4bc1d5 commit c9bd045
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 287 deletions.
10 changes: 1 addition & 9 deletions packages/neovim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@
pkgs,
...
}: {
programs.neovim = {
enable = true;
withRuby = false;
withPython3 = false;
configure = {
customRC = builtins.readFile ../users/shared/nvim/init.vim;
};
};

environment.systemPackages = with pkgs; [
neovim
# nix
nil
alejandra
Expand Down
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ This repo is just a bunch of NixOS modules, so you can pick or override anything
* [Terminus](http://terminus-font.sourceforge.net/shots.html) and [NerdFonts](/sys/fonts.nix)
* [Brutal Doom](https://github.com/ksevelyar/brutal-doom), [Quake](https://github.com/ksevelyar/quake), [Steam](https://github.com/ksevelyar/idempotent-desktop/blob/main/packages/games.nix)
* [battery optimisation](/hardware/power-management.nix) for laptops
* [picard][picard], [mpd](/services/mpd.nix), [ncmpcpp][ncmpcpp], [mpdscribble](https://listenbrainz.org/user/ksevelyar/)
* [picard][picard], [mpd](/services/mpd.nix), [ncmpcpp][ncmpcpp], [mpdscribble](https://listenbrainz.org/user/ksevelyar/)
* [mpv](/users/shared/mpv), [imv][imv]
* [live-usb](/live-usb/live-usb.nix)
* [tealdeer](https://github.com/dbrgn/tealdeer) aliased to h

## Linux as IDE
* Tiling with [leftwm](/users/shared/leftwm/config.toml), polybar, dunst and [tmux](/packages/tmux.nix)
* [fish](/doc/fish.md), direnv, alacritty, ripgrep, rsync, fzf, [zoxide][zoxide], [delta][delta], gitg, bat, exa
* [Neovim with LSP](https://github.com/ksevelyar/idempotent-desktop/blob/main/users/shared/nvim/init.vim) for Elixir, Rust, Nix, Lua and others
* Tiling with [leftwm](/users/shared/leftwm/config.ron), polybar, dunst and [tmux](/packages/tmux.nix)
* [fish](/doc/fish.md), direnv, alacritty, ripgrep, rsync, fzf, [zoxide][zoxide], [delta][delta], bat, exa
* [Neovim with LSP and TS](https://github.com/ksevelyar/idempotent-desktop/blob/main/users/shared/nvim/init.lua)
* fuzzy search by apps [`mod`](/doc/run-rofi-with-one-key.md), emojis `mod + z` and clipboard history `mod + c` wih [rofi](https://github.com/ksevelyar/idempotent-desktop/blob/main/users/shared/rofi/grey.rasi)
* [copy color of pixel under mouse cursor](/services/x.nix#L5-L14) to clipboard with `mod + k`
* [`PrtScn`](https://github.com/ksevelyar/idempotent-desktop/blob/ea28dfc28596d8edb3b88683e9960b4a32cc9c46/users/shared/leftwm/config.toml#L180-L184) to capture region, `mod + PrtScn` to capture fullscreen, record desktop videos with `vokoscreen`
Expand All @@ -30,7 +30,7 @@ This repo is just a bunch of NixOS modules, so you can pick or override anything
* [EdDSA for ssh and gpg keys](/doc/keys.md)
* gopass / [browserpass](https://github.com/browserpass/browserpass-extension#available-keyboard-shortcuts) integration
* [uBlock](https://github.com/gorhill/uBlock)
* [VPN](https://github.com/ksevelyar/idempotent-desktop/blob/main/services/vpn.nix)
* [nekoray](https://github.com/MatsuriDayo/nekoray)

[picard]: https://picard.musicbrainz.org/quick-start/
[imv]: /users/shared/imv/config
Expand Down
2 changes: 0 additions & 2 deletions sys/aliases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
pgrep = "pgrep --full";
pkill = "pkill --full";
i = "host-info";
ms = "mosh";
cat = "bat --paging=never --plain";
bat = "bat --paging=never -n";

Expand Down Expand Up @@ -47,7 +46,6 @@

# vim
v = "nvim";
vv = "nvim -U none"; # vanilla v, don't load plugins & init.vim

# sec
p = "gopass";
Expand Down
5 changes: 2 additions & 3 deletions users/root.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
home-manager = {
useGlobalPkgs = true;
users.root = {
home.stateVersion = "23.11";
home.file.".config/nvim/init.vim".source = ../users/shared/nvim/init.vim;
home.file.".config/nvim/lua/config.lua".source = ../users/shared/nvim/lua/config.lua;
home.stateVersion = "24.05";
home.file.".config/nvim/init.lua".source = ../users/shared/nvim/init.lua;

home.file.".config/fish/config.fish".source = ../users/shared/fish/config.fish;
home.file.".config/fish/functions/fish_prompt.fish".source = ../users/shared/fish/functions/fish_prompt.fish;
Expand Down
5 changes: 2 additions & 3 deletions users/shared.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
home-manager = {
useGlobalPkgs = true;
users.${user} = {
home.stateVersion = "23.11";
home.stateVersion = "24.05";

home.pointerCursor = lib.mkDefault {
x11.enable = true;
Expand Down Expand Up @@ -97,8 +97,7 @@

home.file.".npmrc".source = ../users/shared/.npmrc;

home.file.".config/nvim/init.vim".source = ../users/shared/nvim/init.vim;
home.file.".config/nvim/lua/config.lua".source = ../users/shared/nvim/lua/config.lua;
home.file.".config/nvim/init.lua".source = ../users/shared/nvim/init.lua;

home.file.".config/fish/config.fish".source = ../users/shared/fish/config.fish;
home.file.".config/fish/functions/fish_prompt.fish".source = ../users/shared/fish/functions/fish_prompt.fish;
Expand Down
201 changes: 179 additions & 22 deletions users/shared/nvim/lua/config.lua → users/shared/nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,151 @@
-- https://neovim.io/doc/user/lua-guide.html#lua-guide

-- deps
-- :checkhealth lazy
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)

-- disable netrw at the very start of your init.lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

-- history
vim.opt.undofile = true

vim.opt.laststatus = 2
vim.opt.signcolumn = "yes"
vim.opt.number = true
vim.opt.title = true

-- tabs
vim.opt.shiftwidth = 2
vim.opt.softtabstop = 2
vim.opt.tabstop = 2
vim.opt.expandtab = true

-- delays
vim.opt.updatetime = 250
vim.opt.timeoutlen = 300

-- search
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.gdefault = true

vim.opt.shortmess = "AIT"

-- windows
vim.opt.splitright = true
vim.opt.splitbelow = true

vim.opt.list = true
vim.opt.listchars = { nbsp = "¬", tab = ">•", extends = "»", precedes = "«", trail = "" }
vim.opt.clipboard = "unnamedplus"

vim.g.mapleader = " "

vim.keymap.set('n', '<esc>', '<cmd>nohlsearch<cr>')
vim.keymap.set('n', '<leader>w', ":write<cr>")

vim.keymap.set('n', '<leader>t', ":NvimTreeToggle<cr>")
vim.keymap.set('n', ";", ":")
vim.keymap.set('n', '<leader>f', ":NvimTreeFindFile<cr>")

vim.keymap.set('n', '<leader>c', ':normal gcc<CR>', { desc = '[/] Toggle comment line' })
-- <Esc> - exists visual mode.
-- :normal executes keystrokes in normal mode.
-- gv - restores selection.
-- gc - toggles comment
-- <CR> sends the command
vim.keymap.set('v', '<leader>c', '<Esc>:normal gvgc<CR>', { desc = '[/] Toggle comment block' })

require("lazy").setup({
"airblade/vim-rooter",
"tpope/vim-fugitive",
{
"lewis6991/gitsigns.nvim",
config = function()
require("gitsigns").setup()
end
},
{
'ethanholz/nvim-lastplace',
config = function()
require('nvim-lastplace').setup {}
end,
},
"sirtaj/vim-openscad",
"nvim-tree/nvim-tree.lua",
{
"nvim-telescope/telescope.nvim",
dependencies = { 'nvim-lua/plenary.nvim' }
},
"lukas-reineke/indent-blankline.nvim",
"nvim-lualine/lualine.nvim",
-- lsp
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-vsnip",
"hrsh7th/vim-vsnip",
"neovim/nvim-lspconfig",
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
opts = {
ensure_installed = {
"lua",
"html",
"markdown",
"elixir",
"eex",
"heex",
"rust",
"javascript",
"css",
"dockerfile",
"sql",
"css",
"json",
"nix"
},
auto_install = true,
highlight = {
enable = true
},
indent = { enable = true }
},
config = function(_, opts)
require('nvim-treesitter.install').prefer_git = true
require('nvim-treesitter.configs').setup(opts)
end
},
-- themes
{
"ksevelyar/joker.vim",
lazy = false, -- to make sure it's loaded on startup
priority = 1000, -- to load before other plugins
config = function()
vim.cmd.colorscheme("joker")
end
},
{
"shmerl/neogotham",
},
})

-- # LSP
local lspconfig = require('lspconfig')

Expand All @@ -23,38 +171,41 @@ cmp.setup({
['<CR>'] = cmp.mapping.confirm({ select = true })
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = 'vsnip' }
}, { { name = 'buffer' } })
{ name = 'nvim_lsp' },
{ name = 'vsnip' }
}, {
{ name = 'buffer' } })
})
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
local capabilities = require('cmp_nvim_lsp').default_capabilities()

-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
local silent = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, silent)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, silent)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, silent)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, silent)

-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(_, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
local bufsilent = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufsilent)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufsilent)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufsilent)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufsilent)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufsilent)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufsilent)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufsilent)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufsilent)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufsilent)
vim.keymap.set('n', '<space>=', function()
vim.lsp.buf.format { async = true }
end, opts)
end, silent)

vim.keymap.set('n', '<leader>h', function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end)
end

lspconfig.rust_analyzer.setup {
Expand Down Expand Up @@ -285,5 +436,11 @@ require 'telescope'.setup {
}
}

local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader><leader>', builtin.find_files, {})
vim.keymap.set('n', '<leader>r', builtin.live_grep, {})
vim.keymap.set('n', '<leader>b', builtin.git_branches, {})
vim.keymap.set('n', '<leader>m', builtin.oldfiles, {})

-- # indent_blankline
require("ibl").setup { indent = { char = "|" } }
Loading

0 comments on commit c9bd045

Please sign in to comment.