Skip to content
Snippets Groups Projects
Commit 96f30204 authored by codecraft's avatar codecraft :crocodile:
Browse files

Set null-ls to format with <C-y>

Add 80 characters line
add path completion source
parent acc70cc0
No related branches found
No related tags found
No related merge requests found
......@@ -3,18 +3,20 @@ local opt = vim.opt
local o = vim.o
local wo = vim.wo
-- Colorcolumn
o.colorcolumn = "79"
-- Set highlight on search
o.hlsearch = false
-- Make line numbers default
wo.number = true -- activate numbers
opt.nu = true -- right line number
opt.relativenumber = true -- relative
opt.relativenumber = true -- relative
-- keep cursor in the middle of the screen
opt.scrolloff = 25
-- TABS
o.expandtab = true
o.tabstop = 4
......@@ -27,12 +29,12 @@ opt.ignorecase = true
opt.smartcase = true
opt.incsearch = true
-- appearance
o.termguicolors = true
o.termguicolors = true
opt.background = "dark"
-- Enable mouse mode
-- Enable mouse mode
o.mouse = "a"
-- Enable break indent
o.breakindent = true
......@@ -50,18 +52,18 @@ opt.undofile = true
-- Decrease update time
o.updatetime = 250
wo.signcolumn = 'yes'
wo.signcolumn = "yes"
-- Set completeopt to have a better completion experience
o.completeopt = 'menuone,noselect'
o.completeopt = "menuone,noselect"
-- [[ Highlight on yank ]]
-- See `:help vim.highlight.on_yank()`
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
pattern = '*',
local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true })
vim.api.nvim_create_autocmd("TextYankPost", {
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
pattern = "*",
})
......@@ -8,6 +8,8 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
end
require("packer").startup(function(use)
-- dressing
use({ "stevearc/dressing.nvim" })
-- VimBeGood
use("ThePrimeagen/vim-be-good")
-- telescope filebrowser
......@@ -87,7 +89,14 @@ require("packer").startup(function(use)
use({ -- Autocompletion
"hrsh7th/nvim-cmp",
requires = { "hrsh7th/cmp-nvim-lsp", "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip" },
requires = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
},
})
use({ -- Highlight, edit, and navigate code
......
......@@ -24,5 +24,6 @@ cmp.setup({
{ name = "luasnip" },
{ name = "buffer" },
{ name = "crates" },
{ name = "path" },
},
})
local null_ls = require("null-ls")
local mason_null_ls = require("mason-null-ls")
local null_ls = require('null-ls')
local mason_null_ls = require('mason-null-ls')
local formatting = null_ls.builtins.formatting
local diagnostics = null_ls.builtins.diagnostics
......@@ -7,38 +7,23 @@ local diagnostics = null_ls.builtins.diagnostics
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local formatters_linters = {
prettier = {},
rustfmt = {},
black = {},
stylua = {},
prettier = {},
rustfmt = {},
black = {},
}
mason_null_ls.setup({
ensure_installed = vim.tbl_keys(formatters_linters),
ensure_installed = vim.tbl_keys(formatters_linters)
})
null_ls.setup({
sources = {
formatting.prettier,
formatting.rustfmt,
formatting.black,
formatting.stylua,
},
on_attach = function(current_client, bufnr)
if current_client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({
filter = function(client)
-- only use null-ls for formatting instead of lsp server
return client.name == "null-ls"
end,
bufnr = bufnr,
})
end,
})
end
end,
null_ls.setup ({
sources = {
formatting.prettier,
formatting.rustfmt,
formatting.black,
},
on_attach = function(current_client, bufnr)
if current_client.supports_method("textDocument/formatting") then
vim.api.nvim_buf_set_keymap(bufnr,"n", "<C-y>", '<CMD>lua vim.lsp.buf.format({ async = true })<CR>', { })
end
end,
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment