init.lua (#1)

* Switch neovim to init.lua from init.vim

switch from coc to inbuilt nvim-lsp

* Added completion with completion-nvim
added most of the plugins from init.vim
This commit is contained in:
Uttarayan Mondal
2021-05-06 02:23:09 +05:30
committed by GitHub
parent 2e750ef16d
commit 75b6b9a13e
12 changed files with 432 additions and 3153 deletions

View File

@@ -0,0 +1,36 @@
vim.o.termguicolors = true
vim.cmd[[colorscheme sonokai]]
local colors = {
black = '#181819',
bg0 = '#2c2e34',
bg1 = '#30323a',
bg2 = '#363944',
bg3 = '#3b3e48',
bg4 = '#414550',
bg_red = '#ff6077',
diff_red = '#55393d',
bg_green = '#a7df78',
diff_green = '#394634',
bg_blue = '#85d3f2',
diff_blue = '#354157',
diff_yellow = '#4e432f',
fg = '#e2e2e3',
red = '#fc5d7c',
orange = '#f39660',
yellow = '#e7c664',
green = '#9ed072',
blue = '#76cce0',
purple = '#b39df3',
grey = '#7f8490',
none = 'NONE',
}
-- Override some colors
vim.cmd('hi Normal guibg='..colors.black)
vim.cmd('hi EndOfBuffer guibg='..colors.black)
-- vim.cmd('hi NonText guibg='..colors.black)

View File

View File

@@ -0,0 +1,70 @@
vim.api.nvim_set_keymap('', '<Space>', '<Nop>', { noremap = true, silent=true})
vim.g.mapleader = " "
vim.g.maplocalleader = " "
local options = { noremap = true, silent = true }
local normal_mode_maps = {
-- toggles
{ key = '<F2>', map = [[<cmd>set number! relativenumber!<cr>]] },
-- navigation
{ key = '<leader><leader>', map = [[<c-^>]] },
{ key = '<leader>n', map = [[<cmd>bnext<cr>]] },
{ key = '<leader>p', map = [[<cmd>bprev<cr>]] },
{ key = '<leader>q', map = [[<cmd>bw<cr>]] },
-- fzf
{ key = '<leader>;', map = [[<cmd>Buffers<cr>]] },
{ key = '<leader>f', map = [[<cmd>Files<cr>]] },
{ key = '<leader>g', map = [[<cmd>Rg<cr>]] },
-- lsp
{ key = 'K', map = [[<cmd>lua vim.lsp.buf.hover()<cr>]] },
{ key = 'gd', map = [[<cmd>lua vim.lsp.buf.definition()<cr>]] },
{ key = 'gi', map = [[<cmd>lua vim.lsp.buf.implementation()<cr>]] },
{ key = '<leader>o', map = [[<cmd>LspTroubleToggle<cr>]] },
{ key = '<leader>a', map = [[<cmd>lua vim.lsp.buf.document_highlight()<cr>]] },
{ key = '<leader>c', map = [[<cmd>lua vim.lsp.buf.clear_references()<cr>]] },
{ key = 'F', map = [[<cmd>lua vim.lsp.buf.formatting()<cr>]] },
-- Other
{ key = '<leader>m', map = [[<cmd>silent !mpcfzf<cr>]] },
}
local insert_mode_maps = {
{
key = '<Tab>',
map = [[pumvisible() ? "\<C-n>" : "\<Tab>"]],
options = { noremap = true, silent = true, expr = true }
},
{
key = '<S-Tab>',
map = [[pumvisible() ? "\<C-p>" : "\<S-Tab>"]],
options = { noremap = true, silent = true, expr = true }
},
-- { key = '<tab>', map = '(completion_smart_tab)', options = { plug = true } },
-- { key = '<s-tab>', map = '(completion_smart_s_tab)', options = { plug = true } },
{ key = '<C-j>', map = '<ESC>' },
}
for idx = 1, #normal_mode_maps do
if normal_mode_maps[idx].options then
local options = normal_mode_maps[idx].options
vim.api.nvim_set_keymap('n', normal_mode_maps[idx].key, normal_mode_maps[idx].map ,options)
else
vim.api.nvim_set_keymap('n', normal_mode_maps[idx].key, normal_mode_maps[idx].map ,options)
end
end
for idx = 1, #insert_mode_maps do
if insert_mode_maps[idx].options then
local options = insert_mode_maps[idx].options
vim.api.nvim_set_keymap('i', insert_mode_maps[idx].key, insert_mode_maps[idx].map ,options)
else
vim.api.nvim_set_keymap('i', insert_mode_maps[idx].key, insert_mode_maps[idx].map ,options)
end
end

View File

@@ -0,0 +1,14 @@
-- local lspstatus = require('lsp-status')
-- lspstatus.register_progress()
require("lsp.rust-analyzer")
require("lsp.lua-language-server")
-- Set completeopt to have a better completion experience
vim.o.completeopt= "menuone,noinsert,noselect"
-- vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]]
-- vim.api.nvim_command [[autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()]]
-- vim.api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]]
--
vim.api.nvim_buf_set_option(0, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

View File

@@ -0,0 +1,18 @@
local lspconfig = require'lspconfig'
-- local lspstatus = require('lsp-status')
require'lspconfig'.sumneko_lua.setup{
cmd = { "lua-language-server" },
on_attach=function(client) require'completion'.on_attach(client) require'lsp-status'.on_attach(client) return end,
-- on_attach=require'completion'.on_attach,
filetypes = { "lua" },
log_level = 2,
root_dir = lspconfig.util.root_pattern(".git"),
settings = {
Lua = {
telemetry = {
enable = false
}
}
}
}

View File

@@ -0,0 +1,22 @@
-- Built in lsp
local lspconfig = require'lspconfig'
-- local lspstatus = require('lsp-status')
-- lspstatus.register_progress()
lspconfig.rust_analyzer.setup{
on_attach=function(client) require'completion'.on_attach(client) require'lsp-status'.on_attach(client) return end,
cmd = { "rust-analyzer" },
filetypes = { "rust" },
root_dir = lspconfig.util.root_pattern("Cargo.toml"),
settings = {
["rust-analyzer"] = {
checkOnSave = {
command = "clippy";
},
cargo = {
allFeatures = true;
}
}
}
}

View File

@@ -0,0 +1,73 @@
local execute = vim.api.nvim_command
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', 'https://github.com/wbthomason/packer.nvim', install_path})
execute 'packadd packer.nvim'
end
return require('packer').startup(function()
-- Packer can manage itself
use 'wbthomason/packer.nvim'
use {
'glepnir/galaxyline.nvim', branch = 'main',
config = function() require('statusline') end,
requires = { 'kyazdani42/nvim-web-devicons' }
}
use {
'sainnhe/sonokai',
config = function() require('colorscheme') end,
}
use {
'folke/which-key.nvim',
config = function() require("which-key").setup() end,
}
use { 'yuttie/comfortable-motion.vim' }
use {
'junegunn/fzf',
requires = { 'junegunn/fzf.vim' }
}
use {
'tpope/vim-surround',
'tpope/vim-vinegar',
'tpope/vim-repeat',
'tpope/vim-speeddating',
'tpope/vim-commentary',
'tpope/vim-fugitive',
}
use { 'norcalli/nvim-colorizer.lua', config = function() require'colorizer'.setup() end, }
-- lsp
use { 'onsails/lspkind-nvim', config = function() require'lspkind'.init() end, }
use { 'folke/lsp-trouble.nvim', config = function() require("trouble").setup {} end, }
use { 'neovim/nvim-lspconfig', config = function() require("lsp") end, }
use { 'nvim-lua/completion-nvim' }
use { 'nvim-lua/lsp-status.nvim' }
use {
'nvim-lua/lsp_extensions.nvim',
config =
function()
vim.api.nvim_command([[autocmd BufEnter,BufWinEnter,TabEnter *.rs :lua require'lsp_extensions'.inlay_hints{}]])
end
}
use { 'airblade/vim-rooter' }
-- rust {{{
use {
'rust-lang/rust.vim',
'mhinz/vim-crates',
'cespare/vim-toml',
}
-- }}}
end)

View File

@@ -0,0 +1,169 @@
local vim = vim
local gl = require('galaxyline')
local condition = require('galaxyline.condition')
-- local diagnostic = require('galaxyline.provider_diagnostic')
local diagnostics = require('lsp-status.diagnostics')
local vcs = require('galaxyline.provider_vcs')
local fileinfo = require('galaxyline.provider_fileinfo')
-- local extension = require('galaxyline.provider_extensions')
-- local colors = require('galaxyline.colors')
-- local buffer = require('galaxyline.provider_buffer')
-- local whitespace = require('galaxyline.provider_whitespace')
-- local lspclient = require('galaxyline.provider_lsp')
local lspstatus = require('lsp-status')
-- local gls = gl.section
gl.short_line_list = { 'defx' }
-- from sonokai theme (https://github.com/sainnhe/sonokai/blob/master/autoload/sonokai.vim)
local colors = {
dark_black = '#151515',
black = '#181819',
bg0 = '#2c2e34',
bg1 = '#30323a',
bg2 = '#363944',
bg3 = '#3b3e48',
bg4 = '#414550',
bg_red = '#ff6077',
diff_red = '#55393d',
bg_green = '#a7df78',
diff_green = '#394634',
bg_blue = '#85d3f2',
diff_blue = '#354157',
diff_yellow = '#4e432f',
fg = '#e2e2e3',
red = '#fc5d7c',
orange = '#f39660',
yellow = '#e7c664',
green = '#9ed072',
blue = '#76cce0',
purple = '#b39df3',
grey = '#7f8490',
none = 'NONE',
}
local mode_color = function()
local mode_colors = {
n = colors.blue,
i = colors.green,
c = colors.yellow,
V = colors.purple,
[''] = colors.purple,
v = colors.purple,
R = colors.red,
}
local color = mode_colors[vim.fn.mode()]
if color == nil then
color = colors.red
end
return color
end
local gls = gl.section
gls.left[1] = {
ViMode = {
provider = function()
local alias = {
n = 'NORMAL',
i = 'INSERT',
c = 'COMMAND',
V = 'VISUAL',
[''] = 'VISUAL',
v = 'VISUAL',
R = 'REPLACE',
}
vim.api.nvim_command('hi GalaxyViMode guifg='..mode_color())
local alias_mode = alias[vim.fn.mode()]
if alias_mode == nil then
alias_mode = vim.fn.mode()
end
return ''..alias_mode..' '
end,
highlight = { colors.fg , colors.bg2 },
separator = '',
separator_highlight = { colors.bg2 ,
function()
if condition.check_git_workspace() then
return colors.bg1
else
return colors.dark_black
end
end
},
}
}
-- gls.left[2] = {
-- GitIcon = {
-- provider = function() return '  ' end,
-- condition = condition.check_git_workspace,
-- highlight = { colors.purple , colors.bg1 },
-- }
-- }
gls.left[2] = {
GitBranch = {
provider = function() return vcs.get_git_branch()..' ' end,
condition = condition.check_git_workspace,
highlight = { colors.purple , colors.bg1 },
icon = '',
separator = '',
separator_highlight = { colors.bg1 , colors.dark_black },
}
}
gls.left[3] = {
ShowLspStatus = {
provider = lspstatus.status,
-- condition = function ()
-- local tbl = {['dashboard'] = true,['']=true}
-- if tbl[vim.bo.filetype] then
-- return false
-- end
-- return true
-- end,
-- icon = '  LSP:',
highlight = { colors.diff_yellow , colors.dark_black, 'bold' }
}
}
-- Right Side
gls.right[1]= {
FileFormat = {
provider = function() return ' '..fileinfo.get_file_format()..' ' end,
highlight = { colors.purple, colors.bg3 },
separator = '',
separator_highlight = { colors.bg3, colors.dark_black },
}
}
gls.right[2] = {
LineInfo = {
provider = 'LineColumn',
highlight = { colors.grey, colors.bg2 },
separator = '',
separator_highlight = { colors.bg2, colors.bg3 },
},
}
gls.right[3] = {
PerCent = {
provider = 'LinePercent',
highlight = { colors.blue, colors.bg1 },
separator = '',
separator_highlight = { colors.bg1 , colors.bg2 },
}
}