knoebber / nvim

~/.config/nvim/init.lua Commits Diff Raw
-- basic settings

vim.g.mapleader = ' '
local set = vim.opt
set.tabstop = 2
set.shiftwidth = 2
set.softtabstop = 2
set.expandtab = true
set.mouse = 'a'
set.clipboard='unnamed'

local execute = vim.api.nvim_command
local fn = vim.fn
local fmt = string.format

local pack_path = fn.stdpath('data') .. '/site/pack'

-- ensure a given plugin from github.com/<user>/<repo> is cloned in the pack/packer/start directory
local function ensure (user, repo)
  local install_path = fmt('%s/packer/start/%s', pack_path, repo)
  if fn.empty(fn.glob(install_path)) > 0 then
    execute(fmt('!git clone https://github.com/%s/%s %s', user, repo, install_path))
    execute(fmt('packadd %s', repo))
  end
end

-- ensure the plugin manager is installed
ensure('wbthomason', 'packer.nvim')


require('packer').startup(function(use)
  -- install all the plugins you need here

  -- the plugin manager can manage itself
  use {'wbthomason/packer.nvim'}

  -- neogit
  use { 
    'TimUntersberger/neogit', 
    requires = 'nvim-lua/plenary.nvim',
    config = function() 
    end
  }

  -- telescope and fzf
  use { 'nvim-telescope/telescope.nvim', tag = '0.1.0', requires = { {'nvim-lua/plenary.nvim'} } }

  -- lsp config for elixir-ls support
  use {'neovim/nvim-lspconfig'}
  -- mix format
  use {'mhinz/vim-mix-format'}

  -- cmp framework for auto-completion support
  use {'hrsh7th/nvim-cmp'}

  -- install different completion source
  use {'hrsh7th/cmp-nvim-lsp'}
  use {'hrsh7th/cmp-buffer'}
  use {'hrsh7th/cmp-path'}
  use {'hrsh7th/cmp-cmdline'}

  -- you need a snippet engine for snippet support
  -- here I'm using vsnip which can load snippets in vscode format
  use {'hrsh7th/vim-vsnip'}
  use {'hrsh7th/cmp-vsnip'}

  -- colorscheme
  use 'marko-cerovac/material.nvim'

  -- treesitter for syntax highlighting and more
  use {'nvim-treesitter/nvim-treesitter'}

  use { 'ahmedkhalf/project.nvim', config = function()
    require('project_nvim').setup {
      -- https://github.com/ahmedkhalf/project.nvim#%EF%B8%8F-configuration
    }
  end
}

  -- status line
  -- https://github.com/nvim-lualine/lualine.nvim
  use { 'nvim-lualine/lualine.nvim', requires = { 'kyazdani42/nvim-web-devicons', opt = true } }
end)

-- `on_attach` callback will be called after a language server
-- instance has been attached to an open buffer with matching filetype
-- here we're setting key mappings for hover documentation, goto definitions, goto references, etc
-- you may set those key mappings based on your own preference
local on_attach = function(client, bufnr)
  local opts = { noremap=true, silent=true }

  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>cd', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
end


local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())

require('lspconfig').elixirls.setup {
  cmd = { '/Users/nicolasknoebber/package/elixir-ls/language_server.sh' },
  on_attach = on_attach,
  capabilities = capabilities
}

local cmp = require'cmp'

cmp.setup({
  snippet = {
    expand = function(args)
      -- setting up snippet engine
      -- this is for vsnip, if you're using other
      -- snippet engine, please refer to the `nvim-cmp` guide
      vim.fn['vsnip#anonymous'](args.body)
    end,
  },
  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
  },
  sources = cmp.config.sources({
    { name = 'nvim_lsp' },
    { name = 'vsnip' }, -- For vsnip users.
    { name = 'buffer' }
  })
})


vim.g.mix_format_on_save = 1

-- tree sitter
require'nvim-treesitter.configs'.setup {
  ensure_installed = {'elixir', 'heex'},
  sync_install = true,
  auto_install = true,
  ignore_install = { },
  highlight = {
    enable = true,
    disable = { },
    additional_vim_regex_highlighting = false,
  },
}

-- status line
require('lualine').setup {
  options = {
    theme = 'material',
  }
}

-- color scheme
require('material').setup({
    lualine_style = 'default',
})

require('neogit').setup {
  disable_commit_confirmation = true
}

vim.g.material_style = 'palenight'
vim.cmd 'colorscheme material'

-- global keybinds
vim.keymap.set('n', 'Y', 'yy')
vim.keymap.set('n', '<Leader>f', ':Telescope find_files<CR>')
vim.keymap.set('n', '<Leader>s', ':Telescope live_grep<CR>')
vim.keymap.set('n', '<Leader>b', ':Telescope buffers<CR>')
vim.keymap.set('n', '<Leader>k', ':q<CR>')
vim.keymap.set('n', '<Leader>o', '<C-w><C-o>')
vim.keymap.set('n', '<Leader>j', '<C-w><C-p>') 
vim.keymap.set('n', '<Leader>g', ':Neogit kind=vsplit<CR>')