8000 nvim/init.lua at main · ntrkd/nvim · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
131 lines (109 loc) · 3.45 KB

init.lua

File metadata and controls

131 lines (109 loc) · 3.45 KB
-- Relative line number
vim.wo.relativenumber = true
vim.opt.number = true
vim.o.cmdheight = 1
vim.o.cursorline = true
vim.api.nvim_set_hl(0, "CursorLineNr", { fg = "#ffffff", bold = true })
-- Remove default context menu
vim.cmd('aunmenu PopUp')
-- Save with Control + S
vim.api.nvim_set_keymap('n', '<C-s>', ':w<CR>', { noremap = true, silent = true })
-- Tab size
-- vim.o.expandtab = true
-- vim.o.tabstop = 4 -- A TAB character looks like 4 spaces
-- vim.o.shiftwidth = 4 -- Number of spaces inserted when indenting
-- copy to OSC 52 but paste via internal clipboard. OSC 52 sucks for pasting
function my_paste(reg)
return function(lines)
local content = vim.fn.getreg('"')
return vim.split(content, '\n')
end
end
vim.opt.clipboard:append("unnamedplus")
vim.g.clipboard = {
name = 'OSC 52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
["+"] = my_paste("+"),
["*"] = my_paste("*"),
},
}
-- Get lazy plugin manager running
require("config.lazy")
-- Nice cursor smear
require("smear_cursor").setup()
-- Automatically disable italics on theme change
vim.api.nvim_create_autocmd("ColorScheme", {
callback = function()
local hl_groups = vim.api.nvim_get_hl(0, {})
for key, hl_group in pairs(hl_groups) do
if hl_group.italic then
vim.api.nvim_set_hl(0, key, vim.tbl_extend("force", hl_group, { italic = false }))
end
end
end,
})
-- theme
vim.cmd 'colorscheme kanso-zen'
-- lsp magic
vim.lsp.config('luals', {})
vim.lsp.config('gopls', {})
require("mason").setup()
require("mason-lspconfig").setup {
ensure_installed = { "lua_ls", "gopls", "ansiblels" },
}
vim.lsp.enable('ansiblels')
-- autoformat on save
local buffer_autoformat = function(bufnr)
local group = 'lsp_autoformat'
vim.api.nvim_create_augroup(group, { clear = false })
vim.api.nvim_clear_autocmds({ group = group, buffer = bufnr })
vim.api.nvim_create_autocmd('BufWritePre', {
buffer = bufnr,
group = group,
desc = 'LSP format on save',
callback = function()
-- note: do not enable async formatting
vim.lsp.buf.format({ async = false, timeout_ms = 10000 })
end,
})
end
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(event)
local bufnr = event.buf
local filetype = vim.bo[bufnr].filetype
if filetype == "go" then
return -- skip .go files
end
local id = vim.tbl_get(event, 'data', 'client_id')
local client = id and vim.lsp.get_client_by_id(id)
if client == nil then
return
end
-- make sure there is at least one client with formatting capabilities
if client.supports_method('textDocument/formatting') then
buffer_autoformat(bufnr)
end
end
})
-- go files
local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {})
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function()
require('go.format').goimports()
end,
group = format_sync_grp,
})
require('go').setup()
-- autoformat on save end
vim.o.updatetime = 300
-- Show errors and warnings in a floating window
vim.api.nvim_create_autocmd("CursorHold", {
callback = function()
vim.diagnostic.open_float(nil, { focusable = false, source = "if_many" })
end,
})
0