Various refactors on nvim config

This commit is contained in:
Fabian Becker
2022-09-27 10:33:01 +03:00
parent 04eac8f2b6
commit eb17f0ab25
13 changed files with 297 additions and 167 deletions

View File

@@ -1,122 +0,0 @@
local cmp = require'cmp'
local lspkind = require('lspkind')
local luasnip = require 'luasnip'
local source_mapping = {
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
nvim_lua = "[Lua]",
cmp_tabnine = "[TN]",
path = "[Path]",
orgmode = "[Org]",
luasnip = "[Snippet]",
}
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(
col, col):match("%s") == nil
end
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }),
['<C-n>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = false, -- only replace if explicitly selected
},
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
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 luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" })
},
sources = cmp.config.sources({
{ name = 'cmp_tabnine' },
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}),
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
local menu = source_mapping[entry.source.name]
if entry.source.name == 'cmp_tabnine' then
if entry.completion_item.data ~= nil and entry.completion_item.data.detail ~= nil then
menu = entry.completion_item.data.detail .. ' ' .. menu
end
vim_item.kind = '?'
end
vim_item.menu = menu
return vim_item
end
}
})
-- Set configuration for specific filetype.
cmp.setup.filetype('org', {
sources = cmp.config.sources({
{ name = 'orgmode' },
{ name = 'cmp_tabnine' },
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
-- 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' }
}),
mappings = cmp.mapping.preset.cmdline(),
})
-- Setup tabnine
local tabnine = require('cmp_tabnine.config')
tabnine:setup({
max_lines = 1000;
max_num_results = 20;
sort = true;
run_on_every_keystroke = true;
snippet_placeholder = '..';
ignored_file_types = { -- default is not to ignore
-- uncomment to ignore in lua:
lua = true
};
})

View File

@@ -195,12 +195,3 @@ require('rust-tools').setup({
}
})
-- vim.cmd([[
-- augroup
-- autocmd!
-- autocmd BufWritePre *.go lua vim.lsp.buf.formatting_sync(nil, 100)
-- autocmd BufWritePre *.rs lua vim.lsp.buf.formatting_sync(nil, 100)
-- autocmd BufWritePre *.ex,*.exs lua vim.lsp.buf.formatting_sync(nil, 100)
-- autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100)
-- augroup END
-- ]])

View File

@@ -45,14 +45,14 @@ local function config_winbar()
end
end
local events = { 'BufEnter', 'BufWinEnter', 'CursorMoved' }
vim.api.nvim_create_autocmd(events, {
pattern = '*',
callback = function() config_winbar() end,
})
vim.api.nvim_create_autocmd('User', {
pattern = 'LspsagaUpdateSymbol',
callback = function() config_winbar() end,
})
-- local events = { 'BufEnter', 'BufWinEnter', 'CursorMoved' }
--
-- vim.api.nvim_create_autocmd(events, {
-- pattern = '*',
-- callback = function() config_winbar() end,
-- })
--
-- vim.api.nvim_create_autocmd('User', {
-- pattern = 'LspsagaUpdateSymbol',
-- callback = function() config_winbar() end,
-- })

View File

@@ -1,7 +0,0 @@
local luasnip = require('luasnip')
luasnip.config.set_config {
history = true,
updateevents = "TextChanged,TextChangedI"
}
require("luasnip/loaders/from_vscode").lazy_load()

View File

@@ -1,23 +0,0 @@
local orgmode = require('orgmode')
orgmode.setup_ts_grammar()
orgmode.setup({
org_agenda_files = { '~/org/*' },
org_default_notes_file = '~/org/inbox.org',
org_todo_keywords = {'TODO(t)', 'WAITING(w)', '|', 'DONE(d)', 'CANCELLED(c)'},
org_capture_templates = {
t = {
description = 'Todo',
template = '* TODO %?\n %u',
target = '~/org/inbox.org'
},
j = {
description = 'Journal',
template = '\n*** %<%Y-%m-%d> %<%A>\n**** %U\n\n%?',
target = '~/org/journal.org'
},
},
})

View File

@@ -3,7 +3,7 @@ local nnoremap = Remap.nnoremap
local builtin = require("telescope.builtin")
nnoremap("<leader>pg", function()
builtin.grep_string({ search = vim.fn.input("Grep For > ")})
builtin.live_grep()
end)
nnoremap("<C-p>", function()
if not pcall(builtin.git_files) then
@@ -26,10 +26,13 @@ end)
nnoremap("<leader>vh", function()
builtin.help_tags()
end)
nnoremap("<leader>gw", function()
nnoremap("<leader>wc", function()
require('telescope').extensions.git_worktree.create_git_worktree()
end)
nnoremap("<leader>ws", function()
require('telescope').extensions.git_worktree.git_worktrees()
end)
nnoremap("<leader>gc", function()
builtin.git_branches()
end)