summaryrefslogtreecommitdiff
path: root/.config/nvim/init.lua
blob: 4285f2340e967c43b4d191a96a956d4a90ccbfc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
-- [[ baic opts ]]
vim.g.mapleader = " "
vim.o.ignorecase = true
vim.o.smartcase = true
vim.wo.number = true
vim.wo.relativenumber = 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.wo.signcolumn = "yes"

-- [[ lib ]]
mapnl = function(lhs, rhs, opts)
  vim.keymap.set("n", "<leader>" .. lhs, rhs, opts)
end

-- [[ keybindings ]]
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", -- latest stable release
    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 = {
      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"},
      {"hrsh7th/cmp-nvim-lsp"},
      {"L3MON4D3/LuaSnip"},
    },
  },
}, { lockfile = lazylock })

-- [[ treesitter setup  ]]
require("nvim-treesitter.configs").setup {
  ensure_installed = {
    "c",
    "bash",
    "nix",
    "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)

require("lspconfig").ccls.setup{}
require("lspconfig").bashls.setup{}
require("lspconfig").nil_ls.setup{}
require("lspconfig").lua_ls.setup(lsp.nvim_lua_ls())

lsp.setup()