Dotfiles/nvim/init.lua

288 lines
7.4 KiB
Lua

-- set shell to avoid problems with FiSH
vim.env.SHELL = "/bin/bash"
-- disable mouse
vim.opt.mouse = ""
vim.g.linenumbers = true
vim.opt.number = vim.g.linenumbers
vim.opt.relativenumber = vim.g.linenumbers
function toggle_line_numbering()
vim.g.linenumbers = not vim.g.linenumbers
vim.opt.number = vim.g.linenumbers
vim.opt.relativenumber = vim.g.linenumbers
end
vim.keymap.set("n", "ä", ":lua toggle_line_numbering()<CR>")
vim.opt.encoding = "utf-8"
vim.opt.fileencoding = "utf-8"
vim.g.mapleader = " "
-- vim.cmd([[
-- syntax on
-- filetype indent plugin on
-- ]])
vim.opt.wrap = false
vim.opt.linebreak = true
vim.keymap.set("n", "W", ":set wrap!<CR>")
vim.keymap.set("n", "-", "/")
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = false
vim.opt.list = false
vim.opt.hlsearch = true
-- vim.opt.listchars=tab:→\ ,space:·
vim.opt.undofile = true
vim.opt.undodir = vim.fn.expand("~/.local/share/nvim/undo")
vim.opt.foldlevel = 99
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.keymap.set("n", "<F1>", ":echo<CR>")
vim.keymap.set("i", "<F1>", "<C-o>:echo<CR>")
function save()
vim.cmd(":keeppatterns :%s/\\s\\+$//e")
vim.cmd(":up")
end
function toggle_buffer()
local buf = vim.api.nvim_win_get_buf(0)
if vim.bo[buf].readonly then
vim.cmd(":b#")
else
save()
vim.cmd(":b#")
end
end
vim.keymap.set("n", "<leader><leader>", ":lua toggle_buffer()<CR>")
vim.keymap.set("n", "ZZ", ":lua save()<CR>:xa<CR>")
vim.keymap.set("n", "<c-s>", ":lua save()<CR>")
vim.keymap.set("i", "<c-s>", "<Esc>:lua save()<CR>")
-- vim.keymap.set("n", "<leader>d", ":ALEGoToDefinition<cr>")
vim.keymap.set("v", "ss", ":!sort -u<CR>")
vim.keymap.set("v", "ee", ":!numlines<CR>")
vim.keymap.set("i", "<leader><Tab>", "<c-v><Tab>")
vim.keymap.set("i", "jj", "<Esc>")
vim.keymap.set("n", "j", "gj")
vim.keymap.set("n", "k", "gk")
vim.keymap.set("n", "X", ":! chmod u+x %")
vim.keymap.set("n", "§", "/")
vim.keymap.set("n", "<c-l>", "f|2l")
vim.keymap.set("n", "<c-h>", "2hF|2l")
vim.keymap.set("n", "<c-j>", "j")
vim.keymap.set("n", "<c-k>", "k")
vim.keymap.set("n", "ay", '"+y')
vim.keymap.set("v", "ay", '"+y')
vim.keymap.set("n", "aY", '"+Y')
vim.keymap.set("v", "aY", '"+Y')
vim.keymap.set("n", "ayy", '"+yy')
vim.keymap.set("v", "ayy", '"+yy')
vim.keymap.set("n", "ap", '"+p')
vim.keymap.set("n", "ad", '"+d')
vim.keymap.set("v", "ad", '"+d')
vim.keymap.set("n", "add", '"+dd')
vim.keymap.set("v", "add", '"+dd')
vim.keymap.set("n", "<leader>c", ":Commentary<CR>")
vim.keymap.set("v", "<leader>c", ":Commentary<CR>")
vim.opt.scrolloff = 5
vim.cmd([[
" let g:fzf_files_options = '--preview "(pygmentize {} || cat {}) 2> /dev/null | head -'.&lines.'"'
let $FZF_DEFAULT_COMMAND = 'fd --type f --exclude target --exclude Cargo.lock --exclude __pycache__'
]])
vim.keymap.set("n", "<leader>b", ":up<cr>:Buffers<cr>")
vim.keymap.set("n", "<leader>f", ":up<cr>:Files<cr>")
vim.keymap.set("n", "<leader>g", ":Rg<cr>")
vim.cmd([[
" ALE
let g:ale_fixers = {
\'lua': ['stylua'],
\'rust': ['rustfmt'],
\}
let g:ale_linters = {
\'lua': ['stylua'],
\'python': ['flake8'],
\'rust': ['rls'],
\}
]])
vim.g.ale_fix_on_save = 1
vim.g.ale_sign_error = ""
vim.g.ale_sign_warning = ""
vim.g.ale_rust_cargo_use_clippy = 1
vim.g.ale_set_highlights = 0
vim.g.ale_python_flake8_options = "--max-line-length=99"
-- ultisnips
vim.g.UltiSnipsExpandTrigger = "<enter>"
vim.g.UltiSnipsJumpForwardTrigger = "<c-b>"
vim.g.UltiSnipsJumpBackwardTrigger = "<c-z>"
vim.cmd([[
let g:UltiSnipsSnippetDirectory=['$HOME/.config/nvim/ultisnips']
]])
-- marks
require("marks").setup({
-- whether to map keybinds or not. default true
default_mappings = true,
-- which builtin marks to show. default {}
-- builtin_marks = { ".", "<", ">", "^" },
-- whether movements cycle back to the beginning/end of buffer. default true
cyclic = true,
-- whether the shada file is updated after modifying uppercase marks. default false
force_write_shada = false,
-- how often (in ms) to redraw signs/recompute mark positions.
-- higher values will have better performance but may cause visual lag,
-- while lower values may cause performance penalties. default 150.
refresh_interval = 250,
-- sign priorities for each type of mark - builtin marks, uppercase marks, lowercase
-- marks, and bookmarks.
-- can be either a table with all/none of the keys, or a single number, in which case
-- the priority applies to all marks.
-- default 10.
sign_priority = { lower = 10, upper = 15, builtin = 8, bookmark = 20 },
-- disables mark tracking for specific filetypes. default {}
excluded_filetypes = {},
-- marks.nvim allows you to configure up to 10 bookmark groups, each with its own
-- sign/virttext. Bookmarks can be used to group together positions and quickly move
-- across multiple buffers. default sign is '!@#$%^&*()' (from 0 to 9), and
-- default virt_text is "".
-- bookmark_0 = {
-- sign = "⚑",
-- virt_text = "hello world",
-- -- explicitly prompt for a virtual line annotation when setting a bookmark from this group.
-- -- defaults to false.
-- annotate = false,
-- },
mappings = {
toggle = "<leader>m",
next = "<leader>n",
prev = "<leader>N",
},
})
-- colours
vim.cmd([[
" Start flavours vim
" End flavours vim
" Start flavours lightline
" End flavours lightline
]])
-- base16colorspace = 256
-- vim.cmd([[
-- colorscheme $BASE16_THEME
-- let g:lightline = {'colorscheme': $BASE16_THEME_}
-- ]])
-- Disable LSP highlighting as it breaks normal syntax highlighting
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
vim.api.nvim_set_hl(0, group, {})
end
if vim.bo.filetype ~= "rst" then
vim.g.table_mode_corner = "|"
end
vim.keymap.set("n", "<leader>tr", ":TableModeRealign<CR>")
vim.keymap.set("n", "ci|", "T|ct|")
vim.keymap.set("n", "di|", "T|dt|")
vim.keymap.set("n", "yi|", "T|yt|")
-- Vimboy
vim.api.nvim_create_autocmd({ "bufnewfile", "bufread" }, {
pattern = os.getenv("HOME") .. "/wiki/*",
callback = function()
vim.bo.filetype = "vimboy"
end,
})
local lspconfig = require("lspconfig")
-- lspconfig.rust_analyzer.setup({})
lspconfig.lua_ls.setup({
settings = {
Lua = {
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
},
},
})
local cmp = require("cmp")
cmp.setup({
-- As currently, i am not using any snippet manager, thus disabled it.
-- snippet = {
-- expand = function(args)
-- require("luasnip").lsp_expand(args.body)
-- end,
-- },
mapping = {
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- elseif snippy.can_expand_or_advance() then
-- snippy.expand_or_advance()
-- elseif has_words_before() then
-- cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
-- elseif snippy.can_jump(-1) then
-- snippy.previous()
else
fallback()
end
end, { "i", "s" }),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-c>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
}),
},
sources = {
{ name = "nvim_lsp" },
{ name = "path" },
{ name = "buffer", keyword_length = 5 },
},
experimental = {
ghost_text = true,
},
})
local f = io.open(vim.fn.expand("~/.config/nvim/lua/local.lua"), "r")
if f ~= nil then
io.close(f)
require("local")
end