reworked nvim config files

This commit is contained in:
stev 2022-10-15 15:26:14 +02:00
parent 038a0d6940
commit b76ed824de
6 changed files with 202 additions and 203 deletions

View file

@ -1,207 +1,31 @@
--vim.opt.termguicolors = true
-- plugins
require "paq" {
"savq/paq-nvim"; -- Let Paq manage itself
"nvim-lualine/lualine.nvim";
{ 'kyazdani42/nvim-web-devicons', opt=true };
'neovim/nvim-lspconfig'; -- Collection of configurations for built-in LSP client
'hrsh7th/nvim-cmp'; -- Autocompletion plugin
'hrsh7th/cmp-nvim-lsp'; -- LSP source for nvim-cmp
'saadparwaiz1/cmp_luasnip'; -- Snippets source for nvim-cmp
'L3MON4D3/LuaSnip'; -- Snippets plugin
'nvim-treesitter/nvim-treesitter';
'windwp/nvim-autopairs';
'tpope/vim-surround';
'dhruvasagar/vim-table-mode';
'ap/vim-css-color';
'elkowar/yuck.vim';
}
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all"
ensure_installed = { "lua", "python" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- List of parsers to ignore installing (for "all")
--ignore_install = { "javascript" },
highlight = {
-- `false` will disable the whole extension
enable = true,
-- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
-- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
-- the name of the parser)
-- list of language that will be disabled
--disable = { "c", "rust" },
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
require'lualine'.setup {
options = {
icons_enabled = true,
theme = 'auto',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {},
always_divide_middle = true,
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
tabline = {},
extensions = {}
}
-- require'lspconfig'.pylsp.setup{}
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
local lspconfig = require('lspconfig')
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
local servers = { 'clangd', 'rust_analyzer', 'pylsp', 'tsserver' }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
-- on_attach = my_custom_on_attach,
capabilities = capabilities,
}
end
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<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 = true,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
require('nvim-autopairs').setup{}
-- If you want insert `(` after select function or method item
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local cmp = require('cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })
)
-- add a lisp filetype (wrap my-function), FYI: Hardcoded = { "clojure", "clojurescript", "fennel", "janet" }
--cmp_autopairs.lisp[#cmp_autopairs.lisp+1] = "racket"
vim.cmd [[
function! s:isAtStartOfLine(mapping)
let text_before_cursor = getline('.')[0 : col('.')-1]
let mapping_pattern = '\V' . escape(a:mapping, '\')
let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\')
return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$')
endfunction
inoreabbrev <expr> <bar><bar>
\ <SID>isAtStartOfLine('\|\|') ?
\ '<c-o>:TableModeEnable<cr><bar><space><bar><left><left>' : '<bar><bar>'
inoreabbrev <expr> __
\ <SID>isAtStartOfLine('__') ?
\ '<c-o>:silent! TableModeDisable<cr>' : '__'
]]
---
----------------------
-- general settings --
----------------------
local set = vim.opt
--vim.g.markdown_fenced_languages = ['css', 'html', 'python', 'bash=sh']
set.wrap = true
set.linebreak = true
set.breakindent = true
set.breakindentopt = {'shift:2', 'sbr'}
set.showbreak = ' >'
set.wrap = true
set.linebreak = true
set.breakindent = true
set.breakindentopt = {'shift:2', 'sbr'}
set.showbreak = ' >'
set.number = true
set.relativenumber = true
set.encoding = "utf-8"
--set.filetype = true
--set.filetype.plugin = true
--set.filetype.indent = true
set.number = true
set.relativenumber = true
set.encoding = "utf-8"
-- search
set.hlsearch = true
set.ignorecase = true
set.smartcase = true
set.hlsearch = true
set.ignorecase = true
set.smartcase = true
-- indentation
set.smarttab = true
set.expandtab = false
set.copyindent = true
set.preserveindent = true
set.tabstop = 4
set.shiftwidth = 4
set.softtabstop = 0
set.smarttab = true
set.expandtab = false
set.copyindent = true
set.preserveindent = true
set.tabstop = 4
set.shiftwidth = 4
set.softtabstop = 0
local group = vim.api.nvim_create_augroup("WrapMarkdown", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
@ -217,10 +41,14 @@ vim.cmd [[
let g:vim_markdown_folding_disabled=1
]]
-- mapping
local map = vim.api.nvim_set_keymap
-- removes the background color to have it transparent
vim.api.nvim_create_autocmd({"ColorScheme"}, {
pattern = {"*"},
command = "hi Normal ctermbg=none guibg=none",
})
vim.cmd("colorscheme kanagawa")
require('plugins')
--require('core.colors')
require('core.mappings')
map('n', '<Space>', '', {})
map('n', '<Leader>n', ':bNext<CR>', {})
vim.g.mapleader = ' '
---

View file

@ -0,0 +1,10 @@
--------------
-- mappings --
--------------
local map = vim.api.nvim_set_keymap
vim.g.mapleader = ' '
map('n', '<Space>', '', {})
map('n', '<Leader>n', '<cmd>:bNext<CR>', {})
map('n', '<Leader>p', '<cmd>:bprevious<CR>', {})
map('n', '<Leader>h', '<cmd>:nohlsearch<CR>', {})

View file

@ -0,0 +1,51 @@
-------------
-- plugins --
-------------
require "paq" {
"savq/paq-nvim"; -- Let Paq manage itself
"nvim-lualine/lualine.nvim";
{ 'kyazdani42/nvim-web-devicons', opt=true };
'neovim/nvim-lspconfig'; -- Configs for Nvim LSP
'hrsh7th/nvim-cmp'; -- Autocompletion plugin
'hrsh7th/cmp-nvim-lsp'; -- LSP source for nvim-cmp
'L3MON4D3/LuaSnip'; -- Snippets plugin
'saadparwaiz1/cmp_luasnip'; -- Snippets source for nvim-cmp
'nvim-treesitter/nvim-treesitter'; -- Better syntax highlighting
'windwp/nvim-autopairs';
'tpope/vim-surround';
'dhruvasagar/vim-table-mode';
'lukas-reineke/indent-blankline.nvim';
'ap/vim-css-color';
'rebelot/kanagawa.nvim';
'folke/tokyonight.nvim';
--'elkowar/yuck.vim';
}
-- looks like tablemode for vim-table-mode in markdown
vim.cmd [[
function! s:isAtStartOfLine(mapping)
let text_before_cursor = getline('.')[0 : col('.')-1]
let mapping_pattern = '\V' . escape(a:mapping, '\')
let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\')
return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$')
endfunction
inoreabbrev <expr> <bar><bar>
\ <SID>isAtStartOfLine('\|\|') ?
\ '<c-o>:TableModeEnable<cr><bar><space><bar><left><left>' : '<bar><bar>'
inoreabbrev <expr> __
\ <SID>isAtStartOfLine('__') ?
\ '<c-o>:silent! TableModeDisable<cr>' : '__'
]]
require'plugins.lualine'
require'plugins.nvim-treesitter'
require'plugins.nvim-cmp'
require'indent_blankline'.setup{
show_current_context = true,
}

View file

@ -0,0 +1,28 @@
require'lualine'.setup {
options = {
icons_enabled = true,
theme = 'auto',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {},
always_divide_middle = true,
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
tabline = {},
extensions = {}
}

View file

@ -0,0 +1,67 @@
local luasnip = require 'luasnip'
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<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 = true,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
require('nvim-autopairs').setup{}
cmp.event:on(
'confirm_done',
require('nvim-autopairs.completion.cmp').on_confirm_done({
map_char = { tex = '' }
})
)
-- require'lspconfig'.pylsp.setup{}
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
local lspconfig = require('lspconfig')
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
local servers = { 'clangd', 'rust_analyzer', 'pylsp', 'tsserver' }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
capabilities = capabilities,
}
end

View file

@ -0,0 +1,15 @@
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all"
ensure_installed = { "lua", "python" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
highlight = {
-- `false` will disable the whole extension
enable = true,
-- Using this option may slow down your editor, and you may see some duplicate highlights.
additional_vim_regex_highlighting = false,
},
}