aboutsummaryrefslogtreecommitdiffstats
path: root/.config/nvim/init.lua
blob: dc705610aecb33149cd16f37727c907f1c387319 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
-- Flash screen instead of beep sound
vim.opt.visualbell = true
vim.opt.encoding = 'utf-8'
vim.opt.fileencoding = 'utf-8'
vim.opt.number = true
vim.opt.linebreak = true
vim.opt.splitbelow = true
vim.opt.splitright = true
vim.opt.shiftwidth = 4
vim.opt.backspace = { 'indent', 'eol', 'start' }
vim.cmd('filetype plugin indent on')

-- Whitespace settings per filetype
vim.api.nvim_create_autocmd('FileType', {
  pattern = 'python',
  command = 'setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4'
})

vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, {
  pattern = '*.go',
  command = 'setlocal noet tabstop=4 shiftwidth=4 softtabstop=4'
})

vim.api.nvim_create_autocmd('FileType', {
  pattern = {'javascript', 'typescript', 'java', 'rust', 'c', 'cpp'},
  command = 'setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2'
})

-- Automatically install packer.nvim if not installed
local ensure_packer = function()
  local fn = vim.fn
  local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
  if fn.empty(fn.glob(install_path)) > 0 then
    fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
    vim.cmd [[packadd packer.nvim]]
    return true
  end
  return false
end

local packer_bootstrap = ensure_packer()

-- Autocommand to reload Neovim whenever you save the init.lua
vim.cmd([[
  augroup packer_user_config
    autocmd!
    autocmd BufWritePost init.lua source <afile> | PackerSync
  augroup end
]])

-- Plugin manager setup using packer.nvim
require('packer').startup(function(use)
  -- Packer can manage itself
  use 'wbthomason/packer.nvim'

  -- Auto complete
  use 'neovim/nvim-lspconfig'
  use 'hrsh7th/nvim-cmp'
  use 'hrsh7th/cmp-nvim-lsp'
  use 'hrsh7th/cmp-buffer'
  use 'hrsh7th/cmp-path'
  use 'hrsh7th/cmp-cmdline'

  -- Fuzzy finder
  use { 'junegunn/fzf', run = 'fzf#install()' }
  use 'junegunn/fzf.vim'

  -- Git gutter
  use 'airblade/vim-gitgutter'

  -- Status bar
  use 'nvim-lualine/lualine.nvim'

  -- Git wrapper with :G
  use 'tpope/vim-fugitive'

  -- Editorconfig file support
  use 'editorconfig/editorconfig-vim'

  -- Theme
  use 'sainnhe/everforest'

  -- Go support
  use { 'fatih/vim-go', run = ':GoUpdateBinaries' }

  -- Treesitter for better syntax highlighting
  use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }

  -- File explorer
  use 'kyazdani42/nvim-tree.lua'

  -- LSP Installer
  use 'williamboman/mason.nvim'
  use 'williamboman/mason-lspconfig.nvim'

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if packer_bootstrap then
    require('packer').sync()
  end
end)

-- Setup LSP for C/C++ with clangd
local status_ok_mason, mason = pcall(require, "mason")
if status_ok_mason then
  mason.setup()
end

local status_ok_mason_lspconfig, mason_lspconfig = pcall(require, "mason-lspconfig")
if status_ok_mason_lspconfig then
  mason_lspconfig.setup()
end

local status_ok_lspconfig, lspconfig = pcall(require, "lspconfig")
if status_ok_lspconfig then
  lspconfig.clangd.setup{}
end

-- Treesitter setup
require'nvim-treesitter.configs'.setup {
  ensure_installed = {
    "c", "cpp", "go", "python", "javascript", "typescript", "java", "rust"
  },
  highlight = {
    enable = true,
  },
}

-- Lualine setup
require('lualine').setup {
  options = {
    theme = 'everforest',
    section_separators = {'', ''},
    component_separators = {'', ''},
  }
}

-- Nvim-tree setup
require'nvim-tree'.setup {
  view = {
    side = 'left',
    width = 30,
  },
  actions = {
    open_file = {
      quit_on_open = false,
    },
  },
}

-- Theme setup
vim.opt.termguicolors = true
vim.g.everforest_background = 'soft'
vim.g.everforest_better_performance = 1
vim.g.everforest_disable_italic_comment = 1
vim.cmd('colorscheme everforest')

-- Syntax highlighting
vim.cmd('syntax on')

-- Key mappings
vim.api.nvim_set_keymap('n', '<leader>ff', ':Files<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>fg', ':GFiles<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>gs', ':G<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>gd', ':Gdiff<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>q', ':q<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>w', ':w<CR>', { noremap = true, silent = true })

-- Command to run C programs
vim.api.nvim_create_user_command('RunC', function(opts)
  vim.cmd('!./' .. vim.fn.expand('%<') .. ' ' .. opts.args)
end, { nargs = 1 })