nix-config/home/neovim/init.lua

473 lines
16 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- luacheck: globals vim
require("packer").startup(function(use)
use('nvim-tree/nvim-web-devicons')
use("freitass/todo.txt-vim")
use("psliwka/vim-smoothie")
-- navigation
use("easymotion/vim-easymotion")
use("tpope/vim-unimpaired")
use("tpope/vim-surround")
use("christoomey/vim-tmux-navigator")
-- fern
use("lambdalisue/fern.vim")
use("lambdalisue/glyph-palette.vim")
use("lambdalisue/fern-git-status.vim")
use("lambdalisue/fern-mapping-git.vim") -- to check
use("lambdalisue/fern-hijack.vim")
use("TheLeoP/fern-renderer-web-devicons.nvim")
-- airline
use("vim-airline/vim-airline")
use("vim-airline/vim-airline-themes")
use("tpope/vim-fugitive")
use("airblade/vim-gitgutter")
use("honza/vim-snippets")
use("SirVer/ultisnips")
use("junegunn/fzf.vim")
use("junegunn/goyo.vim")
use("junegunn/limelight.vim")
use("preservim/nerdcommenter")
use("luochen1990/rainbow")
use("ap/vim-css-color")
use("Yggdroot/indentLine")
use("gruvbox-community/gruvbox")
-- language support
use("Glench/Vim-Jinja2-Syntax")
use("preservim/vim-markdown")
use("mzlogin/vim-markdown-toc")
use("LnL7/vim-nix")
use("hashivim/vim-terraform")
use("LaTeX-Box-Team/LaTeX-Box")
use("vito-c/jq.vim")
use("tpope/vim-haml")
use("elzr/vim-json")
use("jpalardy/vim-slime")
use("neovim/nvim-lspconfig")
use("hrsh7th/nvim-cmp") -- Autocompletion plugin
use("hrsh7th/cmp-nvim-lsp") -- LSP source for nvim-cmp
use("hrsh7th/cmp-buffer")
use("hrsh7th/cmp-path")
use("saadparwaiz1/cmp_luasnip") -- Snippets source for nvim-cmp
use("L3MON4D3/LuaSnip") -- Snippets plugin
use("lukas-reineke/lsp-format.nvim")
use {
'nvim-telescope/telescope.nvim',
requires = { { 'nvim-lua/plenary.nvim' } }
}
use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }
use { 'nvim-lua/popup.nvim' }
use { 'nvim-telescope/telescope-media-files.nvim' }
use {
'renerocksai/telekasten.nvim',
requires = { 'nvim-telescope/telescope.nvim' }
}
use { 'nvim-telescope/telescope-symbols.nvim' }
use { 'renerocksai/calendar-vim' }
use { "nvim-telescope/telescope-bibtex.nvim" }
use("sheerun/vim-polyglot")
use("nvim-treesitter/nvim-treesitter")
end)
vim.g.mapleader = ","
vim.g.maplocaleader = "\\"
local o = vim.opt
local function map(mode, shortcut, command)
vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true })
end
local function nmap(shortcut, command)
map("n", shortcut, command)
end
--local function imap(shortcut, command)
-- map("i", shortcut, command)
--end
o.wrap = false
o.number = true
o.compatible = false
o.mouse = "a" -- mouse support
o.showcmd = true -- show incomplete cmds down the bottom
o.showmode = true -- show current mode
o.showmatch = true -- set show matching parenthesis
o.visualbell = true -- no sounds
o.autoread = true -- reload files changed outside of vim
o.backspace = [[indent,eol,start]] -- allow backspacing over everything in insert mode
o.ignorecase = true -- ignore case when searching
o.shiftround = true -- use multiple of shiftwidth when indenting with '<' and '>'
o.smartcase = true -- ignore case if searching pattern is all lowecase, case-sensitive otherwise
o.smarttab = true -- insert tabs on the start of a line according to shiftwidth, not tabstop
o.hlsearch = true -- highlight search terms
o.incsearch = true -- show search matches as you type
o.hidden = true
o.ruler = true
o.clipboard = "unnamed" -- system clipboard
o.colorcolumn = "80"
vim.cmd("syntax on")
vim.cmd("filetype plugin on")
if vim.fn.has("multi_byte") == 1 and vim.o.encoding == "utf-8" then
o.listchars = [[tab:▸ ,extends:,precedes:,nbsp:±,trail:…]]
else
o.listchars = [[tab:> ,extends:>,precedes:<,nbsp:.,trail:_]]
end
o.splitbelow = true
o.splitright = true
nmap("<A-r>", "<C-w>r")
nmap("<A-1>", "1gt")
nmap("<A-2>", "2gt")
nmap("<A-3>", "3gt")
nmap("<A-4>", "4gt")
nmap("<A-5>", "5gt")
nmap("<A-6>", "6gt")
nmap("<A-7>", "7gt")
nmap("<A-8>", "8gt")
nmap("<A-9>", ":tablast<cr>")
nmap("<C-l>", ":nohl<CR><C-l>")
-- todo: try to do it with `vim.api.nvim_set_hl`
vim.cmd("hi CursorLine cterm=NONE,underline ctermbg=NONE") -- highlight line when in insert mode
vim.cmd("hi tklink ctermfg=72 guifg=#689d6a cterm=bold,underline gui=bold,underline")
vim.cmd("hi tkBrackets ctermfg=gray guifg=gray")
o.timeoutlen = 1000
o.ttimeoutlen = 0
vim.cmd("autocmd InsertEnter * :set cursorline")
vim.cmd("autocmd InsertLeave * :set nocursorline")
-- indentation
vim.cmd("filetype indent on")
o.softtabstop = 4
o.expandtab = true
o.shiftwidth = 4
o.tabstop = 4
o.autoindent = true
o.copyindent = true
-- folds
o.foldmethod = "indent"
o.foldnestmax = 3
o.foldenable = false
o.termguicolors = true
vim.g.gruvbox_contrast_dark = "hard"
vim.g.gruvbox_contrast_light = "hard"
vim.g.gruvbox_italic = 1
vim.g.gruvbox_invert_indent_guides = 1
vim.g.gruvbox_vert_split = "bg1"
vim.cmd("colorscheme gruvbox")
o.background = "dark"
vim.g.markdown_syntax_conceal = 0
o.updatetime = 100 -- to make gigutter more responsive
vim.g["fern#renderer"] = "nvim-web-devicons"
vim.cmd([[
function! s:init_fern() abort
nmap <buffer> T <Plug>(fern-action-open:tab)
nmap <buffer> S <Plug>(fern-action-open:split)
nmap <buffer> V <Plug>(fern-action-open:vsplit)
nmap <buffer> <Space> <Plug>(fern-action-mark:toggle)
endfunction
augroup fern-custom
autocmd! *
autocmd FileType fern call s:init_fern()
augroup END
augroup my-glyph-palette
autocmd! *
autocmd FileType fern call glyph_palette#apply()
autocmd FileType nerdtree,startify call glyph_palette#apply()
augroup END
]])
nmap("<leader>t", ":Fern . -drawer -toggle<cr>")
nmap("<leader><Bs>", ": cd ..<cr>")
vim.g["indentLine_char"] = ""
vim.g["indentLine_setConceal"] = 0
vim.g["slime_target"] = "tmux"
vim.g["slime_python_ipython"] = 1
vim.g["tmux_navigator_no_mappings"] = 1
nmap("<A-h>", ":TmuxNavigateLeft<cr>")
nmap("<A-j>", ":TmuxNavigateDown<cr>")
nmap("<A-k>", ":TmuxNavigateUp<cr>")
nmap("<A-l>", ":TmuxNavigateRight<cr>")
vim.g["airline_theme"] = "base16_gruvbox_dark_hard"
vim.g["airline#extensions#tabline#enabled"] = 1
vim.g["airline#extensions#ale#enabled"] = 1
vim.g["deoplete#enable_at_startup"] = 1
vim.g["NERDDefaultAlign"] = "left"
vim.g["UltiSnipsExpandTrigger"] = "<tab>"
vim.g["UltiSnipsJumpForwardTrigger"] = "<c-b>"
vim.g["UltiSnipsJumpBackwardTrigger"] = "<c-z>"
local lspconfig = require("lspconfig")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
lspconfig.pyright.setup { capabilities = capabilities }
lspconfig.ruff_lsp.setup { capabilities = capabilities }
lspconfig.nixd.setup { capabilities = capabilities }
lspconfig.jsonls.setup { capabilities = capabilities }
lspconfig.beancount.setup { capabilities = capabilities }
lspconfig.ltex.setup { capabilities = capabilities }
lspconfig.terraformls.setup { capabilities = capabilities }
lspconfig.tflint.setup { capabilities = capabilities }
lspconfig.docker_compose_language_service.setup {
root_dir = lspconfig.util.root_pattern("docker-compose.yaml", "docker-compose.yml"),
filetypes = { "yaml", "yaml.docker-compose" },
capabilities = capabilities,
}
lspconfig.dockerls.setup { capabilities = capabilities }
-- lspconfig.sqlls.setup {capabilities = capabilities}
lspconfig.lua_ls.setup {
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
capabilities = capabilities
}
lspconfig.efm.setup {
init_options = { documentFormatting = true },
filetypes = { "python", "sh" },
settings = {
rootMarkers = { ".git/", "pyproject.toml" },
languages = {
python = { { formatCommand = "black -", formatStdin = true } },
sql = { {
formatCommand = "sqlfluff fix --dialect bigquery -",
formatStdin = true
} },
sh = { {
formatCommand = "shfmt -i 4 -bn -sr -p -ci",
formatStdin = true,
lintCommand = "shellcheck -f gcc -x",
lintSource = "shellcheck",
lintFormats = {
"%f:%l:%c: %trror: %m",
"%f:%l:%c: %tarning: %m",
"%f:%l:%c: %tote: %m",
}
} },
},
},
capabilities = capabilities
}
local luasnip = require 'luasnip'
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
-- C-b (back) C-f (forward) for snippet placeholder navigation.
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' },
},
}
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})
local telescope_builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', telescope_builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', telescope_builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', telescope_builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', telescope_builtin.help_tags, {})
vim.keymap.set('n', '<leader>fs', function()
telescope_builtin.symbols({ sources = 'emoji', 'gitmoji', 'nerd' })
end)
vim.keymap.set('n', '<leader>fb', ":Telescope bibtex<CR>")
local telescope = require("telescope")
telescope.setup {
extensions = {
fzf = {
fuzzy = true, -- false will only do exact matching
override_generic_sorter = true, -- override the generic sorter
override_file_sorter = true, -- override the file sorter
case_mode = "smart_case", -- or "ignore_case" or "respect_case"
-- the default case_mode is "smart_case"
},
-- media_files = {
-- -- filetypes whitelist
-- -- defaults to {"png", "jpg", "mp4", "webm", "pdf"}
-- filetypes = { "png", "webp", "jpg", "jpeg" },
-- -- find command (defaults to `fd`)
-- find_cmd = "rg"
-- },
bibtex = {
global_files = { vim.fn.expand("~/notes/refs") },
}
}
}
telescope.load_extension("fzf")
telescope.load_extension("media_files")
telescope.load_extension("bibtex")
require 'nvim-web-devicons'.setup()
local telekasten = require('telekasten')
telekasten.setup({
home = vim.fn.expand("~/notes"),
daily = vim.fn.expand("~/notes/daily"),
weeklies = vim.fn.expand("~/notes/weeklies"),
templates = vim.fn.expand("~/notes/templates"),
-- -- Specific note templates
-- -- set to `nil` or do not specify if you do not want a template
-- template_new_note = '/path/to/file', -- template for new notes
-- template_new_daily = '/path/to/file', -- template for new daily notes
-- template_new_weekly = '/path/to/file', -- template for new weekly notes
--
image_subdir = "img",
extension = ".md",
install_syntax = true,
media_previewer = "telescope-media-files",
})
vim.keymap.set("n", "<leader>z", telekasten.panel)
vim.keymap.set("n", "<leader>zf", telekasten.find_notes)
vim.keymap.set("n", "<leader>zd", telekasten.find_daily_notes)
vim.keymap.set("n", "<leader>zg", telekasten.search_notes)
vim.keymap.set("n", "<leader>zz", telekasten.follow_link)
vim.keymap.set("n", "<leader>zT", telekasten.goto_today)
vim.keymap.set("n", "<leader>zW", telekasten.goto_thisweek)
vim.keymap.set("n", "<leader>zw", telekasten.find_weekly_notes)
vim.keymap.set("n", "<leader>zn", telekasten.new_note)
vim.keymap.set("n", "<leader>zN", telekasten.new_templated_note)
vim.keymap.set("n", "<leader>zy", telekasten.yank_notelink)
vim.keymap.set("n", "<leader>zc", telekasten.show_calendar)
vim.keymap.set("n", "<leader>zC", ":CalendarT<CR>")
vim.keymap.set("n", "<leader>zi", telekasten.paste_img_and_link)
vim.keymap.set("n", "<leader>zt", telekasten.toggle_todo)
vim.keymap.set("v", "<leader>zt", function() telekasten.toggle_todo({ v = true }) end)
vim.keymap.set("n", "<leader>zb", telekasten.show_backlinks)
vim.keymap.set("n", "<leader>zF", telekasten.find_friends)
vim.keymap.set("n", "<leader>zI", function() telekasten.insert_img_link({ i = true }) end)
vim.keymap.set("n", "<leader>zp", telekasten.preview_img)
vim.keymap.set("n", "<leader>zm", telekasten.browse_media)
vim.keymap.set("n", "<leader>#", telekasten.show_tags)
vim.keymap.set("i", "[[", function() telekasten.insert_link({ i = true }) end)
vim.keymap.set("i", "<leader>zt", function() telekasten.toggle_todo({ i = true }) end)
vim.keymap.set("i", "<leader>#", function() telekasten.show_tags({ i = true }) end)
if vim.g.neovide then
vim.o.guifont = "Hack Nerd Font:h10"
end