From 038a0d69401f0b9c48316d4c6311ef99111a0838 Mon Sep 17 00:00:00 2001 From: loignon Date: Thu, 13 Oct 2022 08:37:28 +0200 Subject: [PATCH] initial commit --- .config/nvim/init.lua | 226 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 .config/nvim/init.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..8276757 --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,226 @@ +--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 = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, + [''] = 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 + \ isAtStartOfLine('\|\|') ? + \ ':TableModeEnable' : '' +inoreabbrev __ + \ isAtStartOfLine('__') ? + \ ':silent! TableModeDisable' : '__' + ]] + +--- +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.number = true +set.relativenumber = true +set.encoding = "utf-8" + +--set.filetype = true +--set.filetype.plugin = true +--set.filetype.indent = true + +-- search +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 + +local group = vim.api.nvim_create_augroup("WrapMarkdown", { clear = true }) +vim.api.nvim_create_autocmd("FileType", { + pattern = "markdown,txt", + callback = function() + vim.opt_local.colorcolumn = "100" + vim.opt_local.textwidth = 100 + end, + group = WrapMarkdown, +}) + +vim.cmd [[ + let g:vim_markdown_folding_disabled=1 +]] + +-- mapping +local map = vim.api.nvim_set_keymap + +map('n', '', '', {}) +map('n', 'n', ':bNext', {}) +vim.g.mapleader = ' ' +---