helm/profiles/nvim/nvim.nix

708 lines
19 KiB
Nix
Raw Normal View History

2021-10-04 08:23:05 -07:00
{ pkgs, ... }:
2021-10-10 01:34:18 -07:00
let
customPlugins = {
vim-zettel = pkgs.vimUtils.buildVimPlugin {
name = "vim-zettel";
src = pkgs.fetchFromGitHub {
owner = "michal-h21";
repo = "vim-zettel";
rev = "929d90eec62e6f693c2702d2b6f76a93f2f1689d";
sha256 = "1fzKmknfVlEYwqeXgbKITbb2/PJ023iJyMz6vak3qh4=";
};
};
vimwiki-dev = pkgs.vimUtils.buildVimPlugin {
name = "vimwiki-dev";
src = pkgs.fetchFromGitHub {
owner = "vimwiki";
repo = "vimwiki";
rev = "d035a3428c6343b4f218e51340ddf690ad8c57ee";
sha256 = "000000000000000000000000PJ023iJyMz6vak3qh4=";
};
};
taskwiki-t = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "taskwiki";
version = "2021-09-22";
src = pkgs.fetchFromGitHub {
owner = "tools-life";
repo = "taskwiki";
rev = "c4392c36c01cfffcb06f460d722990b98bc53bdb";
sha256 = "QrxFqu/Y6FykXGqIlK52+nDwmnBhubURl6v2Zc/KwPw=";
};
meta.homepage = "https://github.com/tools-life/taskwiki/";
};
};
my-python-packages = python-packages: with python-packages; [
tasklib
pynvim
six
python-lsp-server
pylsp-mypy
python-lsp-black
pylint
# other python packages you want
];
python-with-my-packages = pkgs.python3.withPackages my-python-packages;
2021-10-10 01:34:18 -07:00
in
{
environment.variables.EDITOR = "nvim";
environment.shellAliases = {
k = "vim -c :VimwikiIndex";
kz = "vim -c :VimwikiIndex -c :ZettelNew";
};
environment.systemPackages = with pkgs // customPlugins; [
nodejs
python-with-my-packages
clojure-lsp
rnix-lsp
terraform-lsp
nodePackages.typescript-lsp-server
# Other LSPs
( neovim.override {
vimAlias = true;
withPython3 = true;
extraPython3Packages = pkgs: with pkgs; [ tasklib six ];
configure = {
2021-10-04 08:23:05 -07:00
packages.myPlugins = with pkgs.vimPlugins; {
start = [
vim-nix
fzf-vim
vim-elixir
emmet-vim
nerdtree
ayu-vim
2021-10-04 08:23:05 -07:00
goyo-vim
vim-sneak
csv-vim
rainbow_parentheses-vim
vim-surround
bufferline-nvim
feline-nvim
nvim-webdev-icons
2021-10-04 08:23:05 -07:00
vim-devicons
# kitaab stuff
vimwiki
2021-10-04 08:23:05 -07:00
taskwiki
2021-10-10 01:34:18 -07:00
vim-zettel
telescope-nvim
plenary-nvim
# lsp stuff
ale
black-vim
nvim-lspconfig
nvim-cmp
nvim-cmp-lsp
nvim-lsp-ts-utils
cmp-conjure
cmp-buffer
cmp-tabnine
lspkind-nvim
luasnip
cmp_luasnip
# git stuff
vim-fugitive
gitsigns-nvim
fzf-checkout-vim
# Clojure stuff
conjure
vim-sexp
vim-sexp-mappings-for-regular-people
# testing
#vim-processing
#vim-tidal
2021-10-04 08:23:05 -07:00
];
};
customRC = ''
set tabstop=2
set showmatch
set shiftwidth=2
set noexpandtab
set autoindent
set undofile
" set foldmethod=indent " fold based on indent
set number
set nocompatible
set relativenumber
set showtabline=2
set noexpandtab
set autowriteall
2021-10-04 08:23:05 -07:00
syntax on
set list lcs=tab:\|\
filetype plugin on
set termguicolors
let ayucolor="mirage"
colorscheme ayu
2021-10-04 08:23:05 -07:00
" set spell
set spelllang=en_gb
2021-10-04 08:23:05 -07:00
" window
2022-02-25 06:55:19 -08:00
nmap <leader>wh :topleft vnew<CR>
nmap <leader>wl :botright vnew<CR>
2022-02-25 06:55:19 -08:00
nmap <leader>wk :topleft new<CR>
nmap <leader>wj :botright new<CR>
2022-02-08 02:03:49 -08:00
" tabs
nmap <leader>rt :retab!<CR>
2021-10-04 08:23:05 -07:00
let mapleader = "\<Space>"
let maplocalleader = ","
2021-10-04 08:23:05 -07:00
" moving splits with vim movements.
:tnoremap <A-h> <C-\><C-N><C-w>h
:tnoremap <A-j> <C-\><C-N><C-w>j
:tnoremap <A-k> <C-\><C-N><C-w>k
:tnoremap <A-l> <C-\><C-N><C-w>l
:inoremap <A-h> <C-\><C-N><C-w>h
:inoremap <A-j> <C-\><C-N><C-w>j
:inoremap <A-k> <C-\><C-N><C-w>k
:inoremap <A-l> <C-\><C-N><C-w>l
:nnoremap <A-h> <leader>h
:nnoremap <A-j> <leader>j
:nnoremap <A-k> <leader>k
:nnoremap <A-l> <leader>l
:nnoremap <F5> "=strftime("%Y-%m-%d %H:%M:")
:inoremap <F5> <C-R>=strftime("%Y-%m-%d %H:%M:")
" telescope
" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
2022-02-08 02:03:49 -08:00
" exit normal mode in terminal
:tnoremap <C-n> <C-\><C-n>
2021-10-04 08:23:05 -07:00
" Sexp in Conjure (since it's fennel)
" let g:sexp_filetypes = [ "fennel" ]
2021-10-10 01:34:18 -07:00
let g:rainbow_active = 0
autocmd BufReadPost,BufNewFile c,py,nix RainbowParenthesesToggleAll
2021-10-04 08:23:05 -07:00
2022-02-25 06:55:19 -08:00
" general commands
2021-10-04 08:23:05 -07:00
map <leader>t :NERDTreeToggle<CR>
map <leader>s :w<CR>
map <leader>q :wq<CR>
map <leader>r :RainbowParenthesesToggleAll<CR>
2022-02-25 06:55:19 -08:00
map <leader><BS> :noh<CR>
nnoremap Y y$
" center moving
nnoremap n nzzzv
nnoremap N Nzzzv
nnoremap J mzJ'z
" undo points
inoremap , ,<c-g>u
inoremap . .<c-g>u
inoremap ! !<c-g>u
inoremap ? ?<c-g>u
inoremap ( (<c-g>u
inoremap ) )<c-g>u
inoremap [ [<c-g>u
inoremap ] ]<c-g>u
inoremap { {<c-g>u
inoremap } }<c-g>u
" moving text
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '>-2<CR>gv=gv
inoremap <c-j> <esc>:m .+1<CR>==
inoremap <c-k> <esc>:m .-2<CR>==
nnoremap <leader>j <esc>:m .+1<CR>==
nnoremap <leader>k <esc>:m .-2<CR>==
" Pasting
:map <leader>sy :!xclip -i<CR><CR>
:vmap <leader>sy "*y
:map <leader>sp :r!xclip -o<CR>
2022-02-25 06:55:19 -08:00
" git
nmap <leader>gd :SignifyDiff<CR>
map <leader>ghu :SignifyHunkUndo<CR>
nmap <leader>gl :SignifyList<CR>
nnoremap <leader>ga :G fetch --all
2022-02-25 06:55:19 -08:00
nmap <leader>gs :G<CR>
nmap <leader>gh :diffget //3
nmap <leader>gl :diffget //2
nmap <leader>gc :GCheckout<CR>
2022-02-25 06:55:19 -08:00
" kitaab
map <leader>zs :ZettelSearch<CR>
map <leader>zo :ZettelOpen<CR>
map <leader>zn :ZettelNew<CR>
2021-10-04 08:23:05 -07:00
" NERDTree
" open on directory
autocmd StdinReadPre * let s:std_in=1
2022-02-25 06:55:19 -08:00
" fzf
let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.8 } }
" ALE + clj-kondo
let g:ale_linters = {'clojure': ['clj-kondo'], 'python': ['black', 'pylint']}
2022-02-08 02:03:49 -08:00
2021-10-04 08:23:05 -07:00
" if hidden is not set, TextEdit might fail.
set hidden
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup
" Better display for messages
set cmdheight=2
" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
" lsp commands
nnoremap <leader>vd :lua vim.lsp.buf.definition()<CR>
nnoremap <leader>vi :lua vim.lsp.buf.implementation()<CR>
nnoremap <leader>vsh :lua vim.lsp.buf.signature_help()<CR>
nnoremap <leader>vrr :lua vim.lsp.buf.references()<CR>
nnoremap <leader>vrn :lua vim.lsp.buf.rename()<CR>
nnoremap <leader>vh :lua vim.lsp.buf.hover()<CR>
nnoremap <leader>vca :lua vim.lsp.buf.code_action()<CR>
nnoremap <leader>vsd :lua vim.lsp.diagnostic.show_line_diagnostics(); vim.lsp.util.show_line_diagnostics()<CR>
nnoremap <leader>vn :lua vim.lsp.diagnostic.goto_next()<CR>
nnoremap <leader>vll :call LspLocationList()<CR>
augroup THE_PRIMEAGEN_LSP
autocmd!
autocmd! BufWrite,BufEnter,InsertLeave * :call LspLocationList()
augroup END
"bufferline
" These commands will navigate through buffers in order regardless of which mode you are using
nnoremap <silent>[b :BufferLineCycleNext<CR>
nnoremap <silent>b] :BufferLineCyclePrev<CR>
" lua config
lua <<EOF
-- luasnip
M.luasnip = function(override_flag)
local present, luasnip = pcall(require, "luasnip")
if present then
local default = {
history = true,
updateevents = "TextChanged,TextChangedI",
}
if override_flag then
default = require("core.utils").tbl_override_req("luasnip", default)
end
luasnip.config.set_config(default)
require("luasnip/loaders/from_vscode").load { paths = chadrc_config.plugins.options.luasnip.snippet_path }
require("luasnip/loaders/from_vscode").load()
end
end
-- Setup nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
end,
},
formatting = {
format = function(entry, vim_item)
local icons = require "plugins.configs.lspkind_icons"
vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)
vim_item.menu = ({
nvim_lsp = "[LSP]",
clojure_lsp = "[CLJ]",
buffer = "[BUF]",
terraform_lsp = "[TER]",
pylsp = "[PY]",
rnix-lsp = "[NIX]",
})[entry.source.name]
return vim_item
end,
},
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- For luasnip users.
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
{ name = "nvim_lsp"},
{ name = "path" },
{ name = 'conjure'},
{ name = 'cmp_tabnine'},
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
-- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
require('lspconfig')['nvim_lsp', clojure_lsp', 'rnix-lsp', 'pylsp', 'terraform_lsp', 'tsserver'].setup {
capabilities = capabilities
}
-- Feline
local colors = require 'theme.colors'
local lsp = require 'feline.providers.lsp'
local vi_mode_utils = require 'feline.providers.vi_mode'
local vi_mode_colors = {
NORMAL = colors.green,
INSERT = colors.red,
VISUAL = colors.magenta,
OP = colors.green,
BLOCK = colors.blue,
REPLACE = colors.violet,
['V-REPLACE'] = colors.violet,
ENTER = colors.cyan,
MORE = colors.cyan,
SELECT = colors.orange,
COMMAND = colors.green,
SHELL = colors.green,
TERM = colors.green,
NONE = colors.yellow
}
local icons = {
linux = ' ',
macos = ' ',
windows = ' ',
errs = ' ',
warns = ' ',
infos = ' ',
hints = ' ',
lsp = ' ',
git = ''
}
local function file_osinfo()
local os = vim.bo.fileformat:upper()
local icon
if os == 'UNIX' then
icon = icons.linux
elseif os == 'MAC' then
icon = icons.macos
else
icon = icons.windows
end
return icon .. os
end
local function lsp_diagnostics_info()
return {
errs = lsp.get_diagnostics_count('Error'),
warns = lsp.get_diagnostics_count('Warning'),
infos = lsp.get_diagnostics_count('Information'),
hints = lsp.get_diagnostics_count('Hint')
}
end
local function diag_enable(f, s)
return function()
local diag = f()[s]
return diag and diag ~= 0
end
end
local function diag_of(f, s)
local icon = icons[s]
return function()
local diag = f()[s]
return icon .. diag
end
end
local function vimode_hl()
return {
name = vi_mode_utils.get_mode_highlight_name(),
fg = vi_mode_utils.get_mode_color()
}
end
-- LuaFormatter off
local comps = {
vi_mode = {
left = {
provider = '',
hl = vimode_hl,
right_sep = ' '
},
right = {
provider = '',
hl = vimode_hl,
left_sep = ' '
}
},
file = {
info = {
provider = 'file_info',
hl = {
fg = colors.blue,
style = 'bold'
}
},
encoding = {
provider = 'file_encoding',
left_sep = ' ',
hl = {
fg = colors.violet,
style = 'bold'
}
},
type = {
provider = 'file_type'
},
os = {
provider = file_osinfo,
left_sep = ' ',
hl = {
fg = colors.violet,
style = 'bold'
}
}
},
line_percentage = {
provider = 'line_percentage',
left_sep = ' ',
hl = {
style = 'bold'
}
},
scroll_bar = {
provider = 'scroll_bar',
left_sep = ' ',
hl = {
fg = colors.blue,
style = 'bold'
}
},
diagnos = {
err = {
provider = diag_of(lsp_diagnostics_info, 'errs'),
left_sep = ' ',
enabled = diag_enable(lsp_diagnostics_info, 'errs'),
hl = {
fg = colors.red
}
},
warn = {
provider = diag_of(lsp_diagnostics_info, 'warns'),
left_sep = ' ',
enabled = diag_enable(lsp_diagnostics_info, 'warns'),
hl = {
fg = colors.yellow
}
},
info = {
provider = diag_of(lsp_diagnostics_info, 'infos'),
left_sep = ' ',
enabled = diag_enable(lsp_diagnostics_info, 'infos'),
hl = {
fg = colors.blue
}
},
hint = {
provider = diag_of(lsp_diagnostics_info, 'hints'),
left_sep = ' ',
enabled = diag_enable(lsp_diagnostics_info, 'hints'),
hl = {
fg = colors.cyan
}
},
},
lsp = {
name = {
provider = 'lsp_client_names',
left_sep = ' ',
icon = icons.lsp,
hl = {
fg = colors.yellow
}
}
},
git = {
branch = {
provider = 'git_branch',
icon = icons.git,
left_sep = ' ',
hl = {
fg = colors.violet,
style = 'bold'
},
},
add = {
provider = 'git_diff_added',
hl = {
fg = colors.green
}
},
change = {
provider = 'git_diff_changed',
hl = {
fg = colors.orange
}
},
remove = {
provider = 'git_diff_removed',
hl = {
fg = colors.red
}
}
}
}
local properties = {
force_inactive = {
filetypes = {
'NvimTree',
'dbui',
'packer',
'startify',
'fugitive',
'fugitiveblame'
},
buftypes = {'terminal'},
bufnames = {}
}
}
local components = {
left = {
active = {
comps.vi_mode.left,
comps.file.info,
comps.lsp.name,
comps.diagnos.err,
comps.diagnos.warn,
comps.diagnos.hint,
comps.diagnos.info
},
inactive = {
comps.vi_mode.left,
comps.file.info
}
},
mid = {
active = {},
inactive = {}
},
right = {
active = {
comps.git.add,
comps.git.change,
comps.git.remove,
comps.file.os,
comps.git.branch,
comps.line_percentage,
comps.scroll_bar,
comps.vi_mode.right
},
inactive = {}
}
}
-- LuaFormatter on
require'feline'.setup {
default_bg = colors.bg,
default_fg = colors.fg,
components = components,
properties = properties,
vi_mode_colors = vi_mode_colors
}
-- Buffeline
require('bufferline').setup {
options = {
numbers = "ordinal",
--- @deprecated, please specify numbers as a function to customize the styling
number_style = "superscript",
close_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
right_mouse_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions"
middle_mouse_command = nil, -- can be a string | function, see "Mouse actions"
-- NOTE: this plugin is designed with this icon in mind,
-- and so changing this is NOT recommended, this is intended
-- as an escape hatch for people who cannot bear it for whatever reason
indicator_icon = '',
buffer_close_icon = '',
modified_icon = '',
close_icon = '',
left_trunc_marker = '',
right_trunc_marker = '',
--- name_formatter can be used to change the buffer's label in the bufferline.
--- Please note some names can/will break the
--- bufferline so use this at your discretion knowing that it has
--- some limitations that will *NOT* be fixed.
name_formatter = function(buf) -- buf contains a "name", "path" and "bufnr"
-- remove extension from markdown files for example
if buf.name:match('%.md') then
return vim.fn.fnamemodify(buf.name, ':t:r')
end
end,
max_name_length = 18,
max_prefix_length = 15, -- prefix used when a buffer is de-duplicated
tab_size = 18,
diagnostics = "nvim_lsp",
diagnostics_update_in_insert = false,
diagnostics_indicator = function(count, level, diagnostics_dict, context)
return "("..count..")"
end,
-- NOTE: this will be called a lot so don't do any heavy processing here
custom_filter = function(buf_number, buf_numbers)
-- filter out filetypes you don't want to see
if vim.bo[buf_number].filetype ~= "<i-dont-want-to-see-this>" then
return true
end
-- filter out by buffer name
if vim.fn.bufname(buf_number) ~= "<buffer-name-I-dont-want>" then
return true
end
-- filter out based on arbitrary rules
-- e.g. filter out vim wiki buffer from tabline in your work repo
if vim.fn.getcwd() == "<work-repo>" and vim.bo[buf_number].filetype ~= "wiki" then
return true
end
-- filter out by it's index number in list (don't show first buffer)
if buf_numbers[1] ~= buf_number then
return true
end
end,
-- offsets = {{filetype = "NvimTree", text = "File Explorer" | function , text_align = "left" | "center" | "right"}},
show_buffer_icons = true, -- disable filetype icons for buffers
show_buffer_close_icons = false,
show_close_icon = false,
show_tab_indicators = true,
persist_buffer_sort = true, -- whether or not custom sorted buffers should persist
-- can also be a table containing 2 custom separators
-- [focused and unfocused]. eg: { '|', '|' }
separator_style = "thick",
enforce_regular_tabs = true,
always_show_bufferline = true,
sort_by = 'relative_directory'
end
}
}
EOF
2021-10-04 08:23:05 -07:00
'';
};
}
)];
}