mirror of
https://github.com/halfdan/dotfiles.git
synced 2025-09-10 19:56:24 +00:00
Various refactors on nvim config
This commit is contained in:
121
.config/nvim/lua/halfdan/cmp.lua
Normal file
121
.config/nvim/lua/halfdan/cmp.lua
Normal file
@@ -0,0 +1,121 @@
|
||||
local cmp = require'cmp'
|
||||
local lspkind = require('lspkind')
|
||||
|
||||
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)
|
||||
require'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 require'luasnip'.expand_or_jumpable() then
|
||||
require'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 require'luasnip'.jumpable(-1) then
|
||||
require'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
|
||||
};
|
||||
})
|
||||
|
@@ -1,5 +1,8 @@
|
||||
require("halfdan.settings")
|
||||
require("halfdan.packer")
|
||||
|
||||
require("impatient")
|
||||
|
||||
require("halfdan.neogit")
|
||||
|
||||
require('halfdan.globals')
|
||||
|
7
.config/nvim/lua/halfdan/luasnip.lua
Normal file
7
.config/nvim/lua/halfdan/luasnip.lua
Normal file
@@ -0,0 +1,7 @@
|
||||
local luasnip = require('luasnip')
|
||||
luasnip.config.set_config {
|
||||
history = true,
|
||||
updateevents = "TextChanged,TextChangedI"
|
||||
}
|
||||
|
||||
require("luasnip/loaders/from_vscode").lazy_load()
|
32
.config/nvim/lua/halfdan/neorg.lua
Normal file
32
.config/nvim/lua/halfdan/neorg.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
local neorg = require("neorg")
|
||||
|
||||
neorg.setup({
|
||||
load = {
|
||||
["core.defaults"] = {},
|
||||
["core.norg.dirman"] = {
|
||||
config = {
|
||||
workspaces = {
|
||||
work = "~/org/work",
|
||||
home = "~/org/home",
|
||||
}
|
||||
}
|
||||
},
|
||||
["core.gtd.base"] = {
|
||||
config = {
|
||||
workspace = "work",
|
||||
},
|
||||
},
|
||||
["core.norg.completion"] = {
|
||||
config = {
|
||||
engine = "nvim-cmp",
|
||||
},
|
||||
},
|
||||
["core.norg.concealer"] = {},
|
||||
["core.norg.journal"] = {
|
||||
config = {
|
||||
strategy = "flat",
|
||||
},
|
||||
},
|
||||
["core.integrations.telescope"] = {},
|
||||
}
|
||||
})
|
@@ -35,6 +35,8 @@ return require("packer").startup({
|
||||
-- Packer can manage itself as an optional plugin
|
||||
use "wbthomason/packer.nvim"
|
||||
|
||||
use 'lewis6991/impatient.nvim'
|
||||
|
||||
use {'TimUntersberger/neogit' }
|
||||
use {'airblade/vim-gitgutter'}
|
||||
-- use {'andymass/vim-matchup'}
|
||||
@@ -49,6 +51,15 @@ return require("packer").startup({
|
||||
use {'tpope/vim-surround'} -- ✅
|
||||
use {'tpope/vim-dispatch'}
|
||||
|
||||
-- Treesitter
|
||||
|
||||
use {
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
run = ':TSUpdate',
|
||||
}
|
||||
use { 'nvim-treesitter/playground', after = 'nvim-treesitter' }
|
||||
use { 'nvim-treesitter/nvim-treesitter-textobjects', after = 'nvim-treesitter' }
|
||||
|
||||
-- Testing
|
||||
use {'vim-test/vim-test'}
|
||||
use {
|
||||
@@ -63,9 +74,6 @@ return require("packer").startup({
|
||||
}
|
||||
use {"nvim-neotest/neotest-vim-test" }
|
||||
|
||||
-- Treesitter
|
||||
use {"nvim-treesitter/nvim-treesitter", run = ":TSUpdate"}
|
||||
use {"nvim-treesitter/nvim-treesitter-textobjects"}
|
||||
|
||||
use {'preservim/tagbar'}
|
||||
vim.g.tagbar_ctags_bin = '/usr/local/bin/ctags'
|
||||
@@ -78,7 +86,15 @@ return require("packer").startup({
|
||||
|
||||
use {'rcarriga/nvim-notify'}
|
||||
|
||||
use {'nvim-orgmode/orgmode'}
|
||||
use {
|
||||
"nvim-neorg/neorg",
|
||||
event = "BufEnter",
|
||||
after = "nvim-treesitter",
|
||||
config = function()
|
||||
require 'halfdan.neorg'
|
||||
end
|
||||
}
|
||||
use {'nvim-neorg/neorg-telescope', after = "neorg"}
|
||||
|
||||
use {'justinmk/vim-sneak'}
|
||||
|
||||
@@ -91,18 +107,33 @@ return require("packer").startup({
|
||||
'williamboman/nvim-lsp-installer',
|
||||
}
|
||||
|
||||
use {'hrsh7th/cmp-nvim-lsp'}
|
||||
use {'hrsh7th/cmp-buffer'}
|
||||
use {'hrsh7th/cmp-path'}
|
||||
use {'hrsh7th/cmp-cmdline'}
|
||||
use {'hrsh7th/nvim-cmp'}
|
||||
use {'tzachar/cmp-tabnine', run = './install.sh'}
|
||||
use {'onsails/lspkind-nvim'} -- Display symbol with cmp suggestions
|
||||
use {
|
||||
'L3MON4D3/LuaSnip',
|
||||
requires = {"rafamadriz/friendly-snippets"},
|
||||
}
|
||||
use {'saadparwaiz1/cmp_luasnip'}
|
||||
'L3MON4D3/LuaSnip',
|
||||
event = "InsertEnter",
|
||||
config = function()
|
||||
require 'halfdan.luasnip'
|
||||
end,
|
||||
}
|
||||
use {"rafamadriz/friendly-snippets", after="LuaSnip"}
|
||||
|
||||
use {
|
||||
'hrsh7th/nvim-cmp',
|
||||
requires = {
|
||||
{ 'hrsh7th/cmp-buffer', after = 'nvim-cmp' },
|
||||
'hrsh7th/cmp-nvim-lsp',
|
||||
'onsails/lspkind.nvim',
|
||||
{ 'hrsh7th/cmp-path', after = 'nvim-cmp' },
|
||||
{ 'hrsh7th/cmp-nvim-lua', after = 'nvim-cmp' },
|
||||
{ 'saadparwaiz1/cmp_luasnip', after = 'nvim-cmp' },
|
||||
{ 'hrsh7th/cmp-cmdline', after = 'nvim-cmp', event = 'CmdlineEnter' },
|
||||
{'tzachar/cmp-tabnine', run = './install.sh', after = 'nvim-cmp' }
|
||||
},
|
||||
config = function()
|
||||
require 'halfdan.cmp'
|
||||
end,
|
||||
event = 'InsertEnter',
|
||||
after = 'LuaSnip',
|
||||
}
|
||||
|
||||
use {'glepnir/lspsaga.nvim'}
|
||||
|
||||
@@ -119,9 +150,9 @@ return require("packer").startup({
|
||||
-- Telescope fuzzy find files/grep
|
||||
use {'nvim-lua/popup.nvim'}
|
||||
use {'nvim-lua/plenary.nvim'}
|
||||
|
||||
use {'nvim-telescope/telescope.nvim'}
|
||||
use {'nvim-telescope/telescope-project.nvim'}
|
||||
use {'nvim-telescope/telescope-fzy-native.nvim'}
|
||||
|
||||
|
||||
use {'theprimeagen/git-worktree.nvim'}
|
||||
|
||||
@@ -134,6 +165,7 @@ return require("packer").startup({
|
||||
use {'rust-lang/rust.vim'}
|
||||
use {'simrat39/rust-tools.nvim'}
|
||||
use({ "mhanberg/elixir.nvim", requires = { "neovim/nvim-lspconfig", "nvim-lua/plenary.nvim" }})
|
||||
use {'tpope/vim-projectionist'}
|
||||
-- use {'JuliaEditorSupport/julia-vim', opt=true}
|
||||
-- vim.g.latex_to_unicode_auto = 1
|
||||
|
||||
|
@@ -37,10 +37,9 @@ vim.o.updatetime = 300 -- Faster completion
|
||||
vim.o.timeoutlen = 500 -- By default timeoutlen is 1000 ms
|
||||
vim.o.clipboard = "unnamedplus" -- Copy paste between vim and everything else
|
||||
vim.o.laststatus = 3 -- Set global status bar
|
||||
|
||||
vim.b.did_ftplugin = 1
|
||||
-- Enable telescope theme
|
||||
-- vim.g.gruvbox_baby_telescope_theme = 1
|
||||
-- vim.g.gruvbox_baby_background_color = "dark"
|
||||
vim.g.gruvbox_baby_telescope_theme = 1
|
||||
vim.g.gruvbox_baby_background_color = "dark"
|
||||
|
||||
vim.g.colorscheme = "gruvbox-baby" -- Set colorscheme
|
||||
vim.g.mapleader = ' '
|
||||
|
@@ -4,68 +4,68 @@ require("telescope").load_extension("git_worktree")
|
||||
|
||||
-- Global remapping
|
||||
require('telescope').setup {
|
||||
defaults = {
|
||||
find_command = {'rg', '--no-heading', '--with-filename', '--line-number', '--column', '--smart-case'},
|
||||
file_ignore_patterns = {"_build", "node_modules", "deps" },
|
||||
prompt_position = "bottom",
|
||||
--prompt_prefix = " ",
|
||||
prompt_prefix = " ",
|
||||
selection_caret = " ",
|
||||
entry_prefix = " ",
|
||||
initial_mode = "insert",
|
||||
selection_strategy = "reset",
|
||||
sorting_strategy = "descending",
|
||||
layout_strategy = "horizontal",
|
||||
layout_defaults = {horizontal = {mirror = false}, vertical = {mirror = false}},
|
||||
file_sorter = require'telescope.sorters'.get_fuzzy_file,
|
||||
generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter,
|
||||
shorten_path = true,
|
||||
winblend = 0,
|
||||
width = 0.75,
|
||||
preview_cutoff = 120,
|
||||
results_height = 1,
|
||||
results_width = 0.8,
|
||||
border = {},
|
||||
borderchars = {'─', '│', '─', '│', '╭', '╮', '╯', '╰'},
|
||||
color_devicons = true,
|
||||
use_less = true,
|
||||
set_env = {['COLORTERM'] = 'truecolor'}, -- default = nil,
|
||||
file_previewer = require'telescope.previewers'.vim_buffer_cat.new,
|
||||
grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new,
|
||||
qflist_previewer = require'telescope.previewers'.vim_buffer_qflist.new,
|
||||
-- Developer configurations: Not meant for general override
|
||||
buffer_previewer_maker = require'telescope.previewers'.buffer_previewer_maker,
|
||||
mappings = {
|
||||
i = {
|
||||
["<C-j>"] = actions.move_selection_next,
|
||||
["<C-k>"] = actions.move_selection_previous,
|
||||
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
||||
-- To disable a keymap, put [map] = false
|
||||
-- So, to not map "<C-n>", just put
|
||||
-- ["<c-x>"] = false,
|
||||
defaults = {
|
||||
find_command = {'rg', '--no-heading', '--with-filename', '--line-number', '--column', '--smart-case'},
|
||||
file_ignore_patterns = {"_build", "node_modules", "deps" },
|
||||
prompt_position = "bottom",
|
||||
--prompt_prefix = " ",
|
||||
prompt_prefix = " ",
|
||||
selection_caret = " ",
|
||||
entry_prefix = " ",
|
||||
initial_mode = "insert",
|
||||
selection_strategy = "reset",
|
||||
sorting_strategy = "descending",
|
||||
layout_strategy = "horizontal",
|
||||
layout_defaults = {horizontal = {mirror = false}, vertical = {mirror = false}},
|
||||
file_sorter = require'telescope.sorters'.get_fuzzy_file,
|
||||
generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter,
|
||||
shorten_path = true,
|
||||
winblend = 0,
|
||||
width = 0.75,
|
||||
preview_cutoff = 120,
|
||||
results_height = 1,
|
||||
results_width = 0.8,
|
||||
border = {},
|
||||
borderchars = {'─', '│', '─', '│', '╭', '╮', '╯', '╰'},
|
||||
color_devicons = true,
|
||||
use_less = true,
|
||||
set_env = {['COLORTERM'] = 'truecolor'}, -- default = nil,
|
||||
file_previewer = require'telescope.previewers'.vim_buffer_cat.new,
|
||||
grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new,
|
||||
qflist_previewer = require'telescope.previewers'.vim_buffer_qflist.new,
|
||||
-- Developer configurations: Not meant for general override
|
||||
buffer_previewer_maker = require'telescope.previewers'.buffer_previewer_maker,
|
||||
mappings = {
|
||||
i = {
|
||||
["<C-j>"] = actions.move_selection_next,
|
||||
["<C-k>"] = actions.move_selection_previous,
|
||||
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
||||
-- To disable a keymap, put [map] = false
|
||||
-- So, to not map "<C-n>", just put
|
||||
-- ["<c-x>"] = false,
|
||||
|
||||
-- Otherwise, just set the mapping to the function that you want it to be.
|
||||
-- ["<C-i>"] = actions.select_horizontal,
|
||||
-- Otherwise, just set the mapping to the function that you want it to be.
|
||||
-- ["<C-i>"] = actions.select_horizontal,
|
||||
|
||||
-- Add up multiple actions
|
||||
["<CR>"] = actions.select_default + actions.center
|
||||
-- Add up multiple actions
|
||||
["<CR>"] = actions.select_default + actions.center
|
||||
|
||||
-- You can perform as many actions in a row as you like
|
||||
-- ["<CR>"] = actions.select_default + actions.center + my_cool_custom_action,
|
||||
},
|
||||
n = {
|
||||
["<C-j>"] = actions.move_selection_next,
|
||||
["<C-k>"] = actions.move_selection_previous,
|
||||
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
||||
["<esc>"] = actions.close,
|
||||
-- ["<C-i>"] = my_cool_custom_action,
|
||||
}
|
||||
}
|
||||
},
|
||||
extensions = {
|
||||
fzy_native = {
|
||||
override_generic_sorter = false,
|
||||
override_file_sorter = true,
|
||||
}
|
||||
-- You can perform as many actions in a row as you like
|
||||
-- ["<CR>"] = actions.select_default + actions.center + my_cool_custom_action,
|
||||
},
|
||||
n = {
|
||||
["<C-j>"] = actions.move_selection_next,
|
||||
["<C-k>"] = actions.move_selection_previous,
|
||||
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
||||
["<esc>"] = actions.close,
|
||||
-- ["<C-i>"] = my_cool_custom_action,
|
||||
}
|
||||
}
|
||||
},
|
||||
extensions = {
|
||||
fzy_native = {
|
||||
override_generic_sorter = false,
|
||||
override_file_sorter = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ require('nvim-treesitter.configs').setup({
|
||||
disable = { 'org' },
|
||||
},
|
||||
incremental_selection = {
|
||||
enable = true,
|
||||
enable = false,
|
||||
keymaps = {
|
||||
init_selection = "gnn",
|
||||
node_incremental = "grn",
|
||||
|
Reference in New Issue
Block a user