diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 8276757..428df79 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -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 = { - [''] = 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' : '__' - ]] - ---- +---------------------- +-- 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', '', '', {}) -map('n', 'n', ':bNext', {}) -vim.g.mapleader = ' ' ---- diff --git a/.config/nvim/lua/core/mappings.lua b/.config/nvim/lua/core/mappings.lua new file mode 100644 index 0000000..e85f487 --- /dev/null +++ b/.config/nvim/lua/core/mappings.lua @@ -0,0 +1,10 @@ +-------------- +-- mappings -- +-------------- +local map = vim.api.nvim_set_keymap + +vim.g.mapleader = ' ' +map('n', '', '', {}) +map('n', 'n', ':bNext', {}) +map('n', 'p', ':bprevious', {}) +map('n', 'h', ':nohlsearch', {}) diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua new file mode 100644 index 0000000..4e1f109 --- /dev/null +++ b/.config/nvim/lua/plugins/init.lua @@ -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 + \ isAtStartOfLine('\|\|') ? + \ ':TableModeEnable' : '' +inoreabbrev __ + \ isAtStartOfLine('__') ? + \ ':silent! TableModeDisable' : '__' +]] + +require'plugins.lualine' +require'plugins.nvim-treesitter' +require'plugins.nvim-cmp' +require'indent_blankline'.setup{ + show_current_context = true, +} diff --git a/.config/nvim/lua/plugins/lualine.lua b/.config/nvim/lua/plugins/lualine.lua new file mode 100644 index 0000000..9c697f1 --- /dev/null +++ b/.config/nvim/lua/plugins/lualine.lua @@ -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 = {} +} diff --git a/.config/nvim/lua/plugins/nvim-cmp.lua b/.config/nvim/lua/plugins/nvim-cmp.lua new file mode 100644 index 0000000..93a5dc3 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-cmp.lua @@ -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 = { + [''] = 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{} +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 diff --git a/.config/nvim/lua/plugins/nvim-treesitter.lua b/.config/nvim/lua/plugins/nvim-treesitter.lua new file mode 100644 index 0000000..db95e1d --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-treesitter.lua @@ -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, + }, +}