Skip to content

Commit

Permalink
Merge pull request #57 from guni1192/convert-neovim-config-to-lua
Browse files Browse the repository at this point in the history
Neovim Lua Configuration
  • Loading branch information
guni1192 authored Dec 12, 2023
2 parents f2e73aa + c88e760 commit 113f2f1
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 7 deletions.
5 changes: 5 additions & 0 deletions nvim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require('editor')
require('plugins')
require('color')
require('filetype')
require('lsp')
7 changes: 0 additions & 7 deletions nvim/init.vim

This file was deleted.

19 changes: 19 additions & 0 deletions nvim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bufferline.nvim": { "branch": "main", "commit": "6ecd37e0fa8b156099daedd2191130e083fb1490" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" },
"cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"copilot.vim": { "branch": "release", "commit": "2c31989063b145830d5f0bea8ab529d2aef2427b" },
"fzf-lua": { "branch": "main", "commit": "6589bdd872385d120a1eb3cb85e5d15d37621c1d" },
"lazy.nvim": { "branch": "main", "commit": "16603c6917435d8446f7357cb61095138a417085" },
"lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" },
"markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
"nvim-autopairs": { "branch": "master", "commit": "0f04d78619cce9a5af4f355968040f7d675854a1" },
"nvim-cmp": { "branch": "main", "commit": "51260c02a8ffded8e16162dcf41a23ec90cfba62" },
"nvim-lspconfig": { "branch": "master", "commit": "cb49a4cd622d7ed775c31561bb8aa6a50712d6b9" },
"nvim-tree.lua": { "branch": "master", "commit": "78a9ca5ed6557f29cd0ce203df44213e54bfabb9" },
"nvim-web-devicons": { "branch": "master", "commit": "5de460ca7595806044eced31e3c36c159a493857" },
"vim-kalisi": { "branch": "master", "commit": "8d076bd7989fcb14f995a0d4065a8f16cd00d4d6" },
"vim-vsnip": { "branch": "master", "commit": "be277461265f1e5c7db470aa479f30956597ea9e" }
}
77 changes: 77 additions & 0 deletions nvim/lua/color.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
vim.cmd("syntax on")
vim.api.nvim_create_augroup('BgColor', {})
vim.api.nvim_create_autocmd({'VimEnter', 'ColorScheme'}, {
pattern = {'*'},
group = 'BgColor',
command = 'highlight Normal ctermbg=none'
})
vim.api.nvim_create_autocmd({'VimEnter', 'ColorScheme'}, {
pattern = {'*'},
group = 'BgColor',
command = 'highlight LineNr ctermbg=none'
})
vim.api.nvim_create_autocmd({'VimEnter', 'ColorScheme'}, {
pattern = {'*'},
group = 'BgColor',
command = 'highlight SignColumn ctermbg=none'
})
vim.api.nvim_create_autocmd({'VimEnter', 'ColorScheme'}, {
pattern = {'*'},
group = 'BgColor',
command = 'highlight VertSplit ctermbg=none'
})
vim.api.nvim_create_autocmd({'VimEnter', 'ColorScheme'}, {
pattern = {'*'},
group = 'BgColor',
command = 'highlight NonText ctermbg=none'
})


vim.cmd("colorscheme kalisi")
vim.opt.background = "dark"

require('lualine').setup {
options = {
icons_enabled = true,
theme = 'auto',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
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 = {},
winbar = {},
inactive_winbar = {},
extensions = {}
}

local bufferline = require('bufferline')
bufferline.setup{}
vim.api.nvim_set_keymap('n', '<C-n>', ':BufferLineCycleNext<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<C-p>', ':BufferLineCyclePrev<CR>', { noremap = true, silent = true })
24 changes: 24 additions & 0 deletions nvim/lua/editor.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
vim.opt.number = true
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.expandtab = true
vim.opt.shiftwidth = 4
vim.opt.smartindent = true
vim.opt.autoindent = true
vim.opt.list = true
vim.opt.listchars= 'tab:>-,trail:-,eol:↲,extends:»,precedes:«,nbsp:%'
vim.opt.hidden = true
vim.opt.history = 50
vim.opt.virtualedit = "block"
vim.opt.whichwrap = "b,s,h,l,<,>,[,]"
vim.opt.backspace = "indent,eol,start"
vim.opt.wildmenu = true
vim.opt.clipboard = "unnamed"
vim.opt.pumheight = 10
vim.opt.showmode = true
vim.opt.wildmode = "list:full"
vim.opt.encoding = "utf-8"
vim.opt.helplang = "en"
vim.opt.cursorline = true
vim.opt.foldmethod = "syntax"
vim.opt.foldlevel = 100
23 changes: 23 additions & 0 deletions nvim/lua/filetype.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
vim.api.nvim_create_augroup('FileTypeIndent', {})
vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, {
pattern = {'*.rs', },
group = 'FileTypeIndent',
command = 'setlocal tabstop=4 softtabstop=4 shiftwidth=4'
})
vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, {
pattern = {'*.lua', '*.yaml', '*.yml', '*.html', '*.css', '*.js', '*.jsx', '*.ts', '*.tsx'},
group = 'FileTypeIndent',
command = 'setlocal tabstop=2 softtabstop=2 shiftwidth=2'
})
vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, {
pattern = {'*.go'},
group = 'FileTypeIndent',
command = 'setlocal tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab'
})

vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, {
pattern = {'*.md',},
group = 'FileTypeIndent',
command = 'setlocal tabstop=2 softtabstop=2 shiftwidth=2'
})

120 changes: 120 additions & 0 deletions nvim/lua/lsp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@

vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'

-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})


local cmp = require ("cmp")
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
window = {
-- completion = {
-- autocomplete = true,
-- },
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
}),
mapping = cmp.mapping.preset.insert({
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-c>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<Enter>"] = cmp.mapping.confirm({ select = true }),
}),
})


local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require('lspconfig')

lspconfig.rust_analyzer.setup {
capabilities = capabilities,
flags = {
exit_timeout = 0,
},
filetypes = {'rust'},
settings = {
['rust-analyzer'] = {
cargo = {
buildScripts = {
enable = true,
},
},
checkOnSave = {
allFeatures = true,
command = 'clippy',
},
procMacro = {
enable = true,
},
},
}
}

lspconfig.gopls.setup {
capabilities = capabilities,
cmd = {"gopls", "serve", "-rpc.trace"},
filetypes = {'go'},
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
gofumpt = true,
},
},
}


vim.cmd [[autocmd BufWritePre *.go lua vim.lsp.buf.format({ async = true })]]
vim.api.nvim_create_autocmd('BufWritePre', {
pattern = '*.go',
callback = function()
vim.lsp.buf.code_action({ context = { only = { 'source.organizeImports' } }, apply = true })
end
})

-- probobuf
lspconfig.clangd.setup{
capabilities = capabilities,
}

-- GitHub Copilot
-- vim.keymap.set('i', '<C-g>', 'copilot#Accept("<CR>")', {
-- expr = true,
-- replace_keycodes = false
-- })
-- vim.g.copilot_no_tab_map = true
94 changes: 94 additions & 0 deletions nvim/lua/plugins.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)

local lazy = require('lazy')

lazy.setup({
{
"nvim-tree/nvim-tree.lua",
version = "*",
lazy = false,
dependencies = {
"nvim-tree/nvim-web-devicons",
},
config = function()
local function my_on_attach(bufnr)
local api = require "nvim-tree.api"

local function opts(desc)
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end

-- default mappings
api.config.mappings.default_on_attach(bufnr)

-- custom mappings
vim.keymap.set('n', '<C-t>', api.tree.change_root_to_parent, opts('Up'))
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
vim.keymap.set('n', '<C-e>', api.tree.toggle, opts('Toggle'))
end
require("nvim-tree").setup {
on_attach = my_on_attach,
}
end,
},
{"freeo/vim-kalisi"},
{
"ibhagwan/fzf-lua",
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("fzf-lua").setup({})
end
},
-- completion and snippet
{"neovim/nvim-lspconfig"},
{"hrsh7th/nvim-cmp"},
{"hrsh7th/cmp-path"},
{"hrsh7th/cmp-buffer"},
{"hrsh7th/cmp-cmdline"},
{"hrsh7th/cmp-nvim-lsp"},
{"hrsh7th/vim-vsnip"},
-- lualine
{'nvim-lualine/lualine.nvim'},
{
'akinsho/bufferline.nvim',
version = "*",
dependencies = 'nvim-tree/nvim-web-devicons',
},
{
'windwp/nvim-autopairs',
event = "InsertEnter",
opts = {}
},
{
"iamcco/markdown-preview.nvim",
cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
ft = { "markdown" },
build = function() vim.fn["mkdp#util#install"]() end,
},
-- copilot
{ 'github/copilot.vim' }
})


-- nvim-tree global keymap
local api = require "nvim-tree.api"
vim.keymap.set('n', '<C-e>', api.tree.toggle)

-- fzf-lua
vim.keymap.set("n", "<c-f><c-f>",
"<cmd>lua require('fzf-lua').files()<CR>", { silent = true })
vim.keymap.set("n", "<c-f><c-g>",
"<cmd>lua require('fzf-lua').git_files()<CR>", { silent = true })
vim.keymap.set("n", "<c-f><c-s>",
"<cmd>lua require('fzf-lua').live_grep()<CR>", { silent = true })

0 comments on commit 113f2f1

Please sign in to comment.