summaryrefslogblamecommitdiff
path: root/.config/nvim/init.lua
blob: 2539956c583570d657e8cc4d5a4320b7fd0c11c0 (plain) (tree)
1
2
3
4
5
6
7

                     


                         

                       





                               
                     
                     

                            


                         










                                     
                                          
                                             


                                               
                                      
                                             



                                                   

                             


                                        
                             












                                                  
                                                  
                                              
                            
                        
       
                                                    
                                                
                              
                          


                      


















                                                                 
                      









                                  
                                                   





                                                             


                                                        

















                                             
                                   
                                          
        
                 
                                  































                                                                         




                                

                                  
                             


                                 

      







                                          
             
















                                     

                  
                                         
                                
                                        

    


                    

                 

  






                                                    

                                    
                                   



                                                   
                                        



       

           

                  



























                         
                                                                         
                      









                              



                          







                                                                                     
  
-- [[ baic opts ]]
vim.g.mapleader = " "
vim.g.netrw_banner = 0
vim.g.netrw_liststyle = 3
vim.g.netrw_winsize = 25
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.clipboard = "unnamedplus"
vim.o.breakindent = true
vim.o.undofile = true
vim.o.mouse = false
vim.o.guicursor = false
vim.o.termguicolors = true
vim.o.shortmess = "I"
vim.o.showtabline = 0
vim.wo.number = true
vim.wo.relativenumber = true
vim.wo.signcolumn = "yes"

-- [[ lib ]]
local table_merge = function (t1, t2)
  t1 = t1 or {}
  t2 = t2 or {}

  for k, v in pairs(t2) do
    t1[k] = v
  end

  return t1
end

local map = function(mode, lhs, rhs, opts)
  opts = table_merge(opts, { silent = true })
  vim.api.nvim_set_keymap(mode, lhs, rhs, opts)
end

local mapnl = function(lhs, rhs, opts)
  opts = table_merge(opts, { silent = true })
  vim.keymap.set("n", "<leader>" .. lhs, rhs, opts)
end

-- [[ keybindings ]]
-- generic
map("n", "<C-x>", ":bd!<CR>")
map("t", "<C-x>", "<C-\\><C-n>:bd!<CR>")
map("n", "<C-s>", ":close<CR>")
map("t", "<C-s>", "<C-\\><C-n>")
mapnl("n", ":nohlsearch<CR>")
-- splits
map("n", "<C-h>", "<C-w>h")
map("n", "<C-j>", "<C-w>j")
map("n", "<C-k>", "<C-w>k")
map("n", "<C-l>", "<C-w>l")
map("t", "<C-h>", "<C-\\><C-n><C-w>h")
map("t", "<C-j>", "<C-\\><C-n><C-w>j")
map("t", "<C-k>", "<C-\\><C-n><C-w>k")
map("t", "<C-l>", "<C-\\><C-n><C-w>l")
-- terminal
map("n", "<leader>t", ":vsplit<CR>:terminal<CR>i")
map("t", "<leader>t", "<C-\\><C-n>:q<CR>")
-- buffer
map("t", "<leader>j", "<C-\\><C-n>:bprevious<CR>")
map("t", "<leader>k", "<C-\\><C-n>:bnext<CR>")
mapnl("j", ":bprevious<CR>")
mapnl("k", ":bnext<CR>")
-- tabs
map("t", "<leader>h", "<C-\\><C-n>:tabprevious<CR>")
map("t", "<leader>l", "<C-\\><C-n>:tabnext<CR>")
mapnl("h", ":tabprevious<CR>")
mapnl("l", ":tabnext<CR>")
-- files
mapnl("e", ":Lex<CR>")
-- column hint
mapnl("cc", function()
  if vim.api.nvim_get_option_value("colorcolumn", {}) == "" then
    vim.api.nvim_set_option_value("colorcolumn", "79", {})
  else
    vim.api.nvim_set_option_value("colorcolumn", "", {})
  end
end)

-- [[ package manager ]]
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
local lazylock = vim.fn.stdpath("data") .. "/lazy/lazy-lock.json"
if not vim.loop.fs_stat(lazypath) then
  local lazyrepo = "https://github.com/folke/lazy.nvim.git"
  vim.print("downloading " .. lazyrepo)
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    lazyrepo,
    "--branch=stable",
    lazypath,
  })
  vim.api.nvim_echo({}, false, {})
end
vim.opt.rtp:prepend(lazypath)

-- [[ plugin setup ]]
require("lazy").setup({
  "tpope/vim-fugitive",
  "tpope/vim-sleuth",
  { "numToStr/Comment.nvim",           opts = {} },
  { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },

  {
    "nvim-lualine/lualine.nvim",
    dependencies = { "nvim-tree/nvim-web-devicons" },
    opts = {
      sections = {
        lualine_a = { "mode" },
        lualine_b = { "branch", "diff", "diagnostics" },
        lualine_c = {
          {
            "buffers",
            mode = 2,
            symbols = { directory = '󰉋' },
          }
        },
        lualine_x = {
          "encoding",
          {
            "fileformat",
            symbols = {
              unix = " ",
              dos = " ",
              mac = " ",
            }
          }
        },
        lualine_y = { "progress" },
        lualine_z = { "location", "tabs" }
      },
      options = {
        component_separators = "",
        section_separators = "",
      },
    },
  },

  {
    "navarasu/onedark.nvim",
    priority = 1000,
    opts = { transparent = true },
    config = function(_, opts)
      require("onedark").setup(opts)
      vim.cmd.colorscheme "onedark"
    end,
  },

  {
    "lewis6991/gitsigns.nvim",
    opts = {
      signs = {
        add = { text = "+" },
        change = { text = "~" },
        delete = { text = "_" },
        topdelete = { text = "‾" },
        changedelete = { text = "~" },
      },
      on_attach = function(bufnr)
        mapnl("gp", require("gitsigns").prev_hunk, { buffer = bufnr })
        mapnl("gn", require("gitsigns").next_hunk, { buffer = bufnr })
        mapnl("ph", require("gitsigns").preview_hunk, { buffer = bufnr })
      end,
    },
  },

  {
    "VonHeikemen/lsp-zero.nvim",
    branch = "v2.x",
    dependencies = {
      { "neovim/nvim-lspconfig" },
      { "hrsh7th/nvim-cmp" },
      { "L3MON4D3/LuaSnip" },
      { "hrsh7th/cmp-nvim-lsp" },
      { "hrsh7th/cmp-buffer" },
      { "hrsh7th/cmp-path" },
    },
  },
}, { lockfile = lazylock })

-- [[ treesitter setup  ]]
require("nvim-treesitter.configs").setup {
  ensure_installed = {
    "c",
    "bash",
    "nix",
    "python",
    "lua",
    "markdown",
    "regex",
  },
  sync_install = false,
  auto_install = false,
  highlight = { enable = true },
  indent = { enable = true },
  incremental_selection = {
    enable = true,
    keymaps = {
      init_selection = "<leader>i",
      node_incremental = "<leader>i",
      node_decremental = "<leader>d",
    },
  }
}

-- [[ lsp setup ]]
local lsp = require("lsp-zero").preset {}
lsp.on_attach(function(_, bufnr)
  lsp.default_keymaps { buffer = bufnr }
end)

lsp.set_sign_icons({
  error = "󰅚 ",
  warn = "󰀪 ",
  info = "󰋽 ",
  hint = "󰌶 "
})

require("lspconfig").ccls.setup {
  init_options = {
    cache = {
      directory = vim.fn.stdpath('cache') .. '/ccls'
    }
  }
}
require("lspconfig").bashls.setup {}
require("lspconfig").nil_ls.setup {}
require'lspconfig'.pyright.setup {}
require("lspconfig").lua_ls.setup(lsp.nvim_lua_ls({
  settings = {
    Lua = {
      diagnostics = {
        globals = { 'mp' } -- mpv global
      }
    }
  }
}))

lsp.setup()

-- [[ cmp setup ]]
local kind_icons = {
  Text = " ",
  Method = " ",
  Function = " ",
  Constructor = " ",
  Field = " ",
  Variable = " ",
  Class = " ",
  Interface = " ",
  Module = " ",
  Property = " ",
  Unit = " ",
  Value = " ",
  Enum = " ",
  Keyword = " ",
  Snippet = " ",
  Color = " ",
  File = " ",
  Reference = " ",
  Folder = " ",
  EnumMember = " ",
  Constant = " ",
  Struct = " ",
  Event = " ",
  Operator = " ",
  TypeParameter = " ",
}

local cmp_colr = "Normal:Normal,FloatBorder:BorderBG,CursorLine:PmenuSel"
require("cmp").setup({
  window = {
    completion = {
      border = "rounded",
      winhighlight = cmp_colr,
    },
    documentation = {
      border = "rounded",
      winhighlight = cmp_colr,
    }
  },
  sources = {
    { name = "nvim_lsp" },
    { name = "buffer" },
    { name = "path" },
  },
  formatting = {
    format = function(entry, vim_item)
      vim_item.kind = kind_icons[vim_item.kind] .. " " .. string.lower(vim_item.kind)
      vim_item.menu = "[" .. entry.source.name .. "]"
      return vim_item
    end
  },
})