first commit
This commit is contained in:
commit
02f0def35e
16 changed files with 422 additions and 0 deletions
36
README.md
Normal file
36
README.md
Normal file
|
@ -0,0 +1,36 @@
|
|||
Neovim configuration
|
||||
--------------------
|
||||
|
||||
This is my Neovim configuratio all written in lua, Neovim 8 minimum is required.
|
||||
For `Tree sitter` working properly, you need `g++` in Debian :
|
||||
|
||||
```
|
||||
apt install g++ clang gcc
|
||||
```
|
||||
|
||||
Then clone this repository:
|
||||
|
||||
```
|
||||
git clone https://git.epha.se/ephase/nvim_config.git ~/.config/nvim
|
||||
```
|
||||
|
||||
To install plugins, start nvim in headless mode with `lua/plugins.lua` config
|
||||
file:
|
||||
|
||||
```
|
||||
nvim -u ~/.config/nvim/lua/plugins.lua --headless
|
||||
```
|
||||
|
||||
## Keybinding
|
||||
|
||||
Leader key is `space`
|
||||
|
||||
* <leader>fm : open file manager
|
||||
* <leader>l : show all caracters (`space`, `tab`, `eol`)
|
||||
* <leader>[ : previous tab
|
||||
* <leader>] : nest tab
|
||||
* <leader>gn : gitsign - goto next hunk
|
||||
* <leader>gN : gitsign - goto previous hunk
|
||||
* <leader>gs : gitsign - stage hunk
|
||||
* <leader>gr : gitsign - reset hunk
|
||||
* <leader>gd : gitsign - diff
|
4
init.lua
Normal file
4
init.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
require("plugins")
|
||||
require("settings")
|
||||
require("plugins-options")
|
||||
require("keybiding")
|
28
lua/keybiding.lua
Normal file
28
lua/keybiding.lua
Normal file
|
@ -0,0 +1,28 @@
|
|||
-- " Key biding
|
||||
-- " ----------
|
||||
local opts = { noremap = true, silent = true}
|
||||
|
||||
vim.api.nvim_set_keymap('n', '<leader>/', ':nohlsearch<CR>', opts)
|
||||
|
||||
vim.api.nvim_set_keymap('n', '<leader>fm',
|
||||
':NeoTreeFocusToggle<CR>',
|
||||
{ table.unpack(opts), desc = 'Toggle NeoTree' }
|
||||
)
|
||||
|
||||
-- Move tabs with \[ and \]
|
||||
vim.api.nvim_set_keymap('n', '<Leader>]', ':tabnext<CR>', opts)
|
||||
vim.api.nvim_set_keymap('n', '<Leader>[', ':tabprev<CR>', opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>l', ':set list!<CR>', {silent = true})
|
||||
|
||||
-- Manage Tab
|
||||
local t = function(str)
|
||||
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
||||
end
|
||||
|
||||
-- git sign
|
||||
-- vim.api.nvim_set_keymap('n', '<leader>gp', require("gitsigns").preview_hunk, opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>gn', [[<cmd>lua require('gitsigns').next_hunk()<CR>]], opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>gN', [[<cmd>lua require('gitsigns').prev_hunk()<CR>]], opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>gs', ':Gitsigns stage_hunk<CR>', opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>gr', ':Gitsigns reset_hunk<CR>', opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>gd', [[<cmd>lua require("gitsigns").diffthis('~')<CR>]], opts)
|
10
lua/plugins-options.lua
Normal file
10
lua/plugins-options.lua
Normal file
|
@ -0,0 +1,10 @@
|
|||
require('plugins.treesitter')
|
||||
require('plugins.lsp')
|
||||
require('plugins.mason')
|
||||
require('plugins.cmp')
|
||||
require('plugins.gitsigns')
|
||||
require('plugins.lualine')
|
||||
require('plugins.autopairs')
|
||||
require('plugins.whichkey')
|
||||
require('plugins.base16')
|
||||
require('plugins.neotree')
|
71
lua/plugins.lua
Normal file
71
lua/plugins.lua
Normal file
|
@ -0,0 +1,71 @@
|
|||
local function clone_paq()
|
||||
local path = vim.fn.stdpath("data") .. "/site/pack/paqs/start/paq-nvim"
|
||||
local is_installed = vim.fn.empty(vim.fn.glob(path)) == 0
|
||||
if not is_installed then
|
||||
vim.fn.system { "git", "clone", "--depth=1", "https://github.com/savq/paq-nvim.git", path }
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local pkgs = {
|
||||
"savq/paq-nvim";
|
||||
|
||||
-- need to install g++ package on Debian
|
||||
-- for tree sitter plugins
|
||||
'nvim-treesitter/nvim-treesitter';
|
||||
|
||||
-- LSP installer
|
||||
'neovim/nvim-lspconfig';
|
||||
|
||||
-- ui elements
|
||||
'MunifTanjim/nui.nvim';
|
||||
'nvim-lua/plenary.nvim';
|
||||
|
||||
-- status bar
|
||||
'nvim-lualine/lualine.nvim';
|
||||
|
||||
-- Base16 theme
|
||||
'RRethy/nvim-base16';
|
||||
|
||||
-- file manager
|
||||
'nvim-neo-tree/neo-tree.nvim';
|
||||
|
||||
-- git integration
|
||||
'lewis6991/gitsigns.nvim';
|
||||
|
||||
|
||||
-- Mason is a GUI to install language servers and lspconfig is a bridge
|
||||
-- between mason and nvim-lspconfig
|
||||
'williamboman/mason.nvim';
|
||||
'williamboman/mason-lspconfig.nvim';
|
||||
|
||||
-- autocompletion plugin
|
||||
'hrsh7th/nvim-cmp';
|
||||
'hrsh7th/cmp-nvim-lsp'; -- LSP source
|
||||
'hrsh7th/cmp-path'; -- path source
|
||||
'hrsh7th/cmp-buffer'; -- buffer
|
||||
'L3MON4D3/LuaSnip'; -- snippet engine
|
||||
'saadparwaiz1/cmp_luasnip';
|
||||
|
||||
-- autopair
|
||||
'windwp/nvim-autopairs';
|
||||
|
||||
-- indent guide
|
||||
'lukas-reineke/indent-blankline.nvim';
|
||||
|
||||
-- windows popup with keys
|
||||
'folke/which-key.nvim';
|
||||
}
|
||||
|
||||
if clone_paq() then
|
||||
vim.cmd('packadd paq-nvim')
|
||||
local paq = require('paq')
|
||||
-- Exit nvim after installing plugins
|
||||
vim.cmd('autocmd User PaqDoneInstall quit')
|
||||
-- Read and install packages
|
||||
paq(pkgs)
|
||||
paq.install()
|
||||
end
|
||||
|
||||
local paq = require("paq")
|
||||
paq(pkgs)
|
1
lua/plugins/autopairs.lua
Normal file
1
lua/plugins/autopairs.lua
Normal file
|
@ -0,0 +1 @@
|
|||
local autopair = require("nvim-autopairs").setup {}
|
1
lua/plugins/base16.lua
Normal file
1
lua/plugins/base16.lua
Normal file
|
@ -0,0 +1 @@
|
|||
vim.cmd.colorscheme 'base16-default-dark'
|
84
lua/plugins/cmp.lua
Normal file
84
lua/plugins/cmp.lua
Normal file
|
@ -0,0 +1,84 @@
|
|||
local has_words_before = function()
|
||||
unpack = unpack or table.unpack
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(
|
||||
0,
|
||||
line - 1,
|
||||
line,
|
||||
true
|
||||
)[1]:sub(col, col):match('%s') == nil
|
||||
end
|
||||
|
||||
-- Add additional capabilities supported by nvim-cmp
|
||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
local kind_icons = {
|
||||
Text = "",
|
||||
Method = "",
|
||||
Function = "",
|
||||
Constructor = "",
|
||||
Field = "",
|
||||
Variable = "",
|
||||
Class = "ﴯ",
|
||||
Interface = "",
|
||||
Module = "",
|
||||
Property = "ﰠ",
|
||||
Unit = "",
|
||||
Value = "",
|
||||
Enum = "",
|
||||
Keyword = "",
|
||||
Snippet = "",
|
||||
Color = "",
|
||||
File = "",
|
||||
Reference = "",
|
||||
Folder = "",
|
||||
EnumMember = "",
|
||||
Constant = "",
|
||||
Struct = "",
|
||||
Event = "",
|
||||
Operator = "",
|
||||
TypeParameter = ""
|
||||
}
|
||||
|
||||
-- nvim-cmp setup
|
||||
local cmp = require 'cmp'
|
||||
cmp.setup {
|
||||
mapping = {
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
|
||||
-- they way you will only jump inside the snippet region
|
||||
elseif luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
},
|
||||
formatting = {
|
||||
format = function(_, vim_item)
|
||||
vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind)
|
||||
return vim_item
|
||||
end,
|
||||
},
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' },
|
||||
{ name = 'path' },
|
||||
{ name = 'buffer' },
|
||||
},
|
||||
}
|
3
lua/plugins/gitsigns.lua
Normal file
3
lua/plugins/gitsigns.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
require('gitsigns').setup {
|
||||
keymaps = {}, -- NO default keybindings
|
||||
}
|
1
lua/plugins/lsp.lua
Normal file
1
lua/plugins/lsp.lua
Normal file
|
@ -0,0 +1 @@
|
|||
local lspconfig = require('lspconfig')
|
29
lua/plugins/lualine.lua
Normal file
29
lua/plugins/lualine.lua
Normal file
|
@ -0,0 +1,29 @@
|
|||
require('lualine').setup {
|
||||
options = {
|
||||
icons_enabled = true,
|
||||
theme = 'base16',
|
||||
component_separators = { left = '|', right = '|'},
|
||||
section_separators = { left = '', right = ''},
|
||||
disabled_filetypes = {},
|
||||
always_divide_middle = true,
|
||||
globalstatus = true,
|
||||
},
|
||||
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 = {},
|
||||
extensions = {}
|
||||
}
|
25
lua/plugins/mason.lua
Normal file
25
lua/plugins/mason.lua
Normal file
|
@ -0,0 +1,25 @@
|
|||
local mason = require("mason").setup{
|
||||
ensure_installed= {
|
||||
'shellcheck',
|
||||
'shfmt'
|
||||
}
|
||||
}
|
||||
local mason_lspconfig = require("mason-lspconfig").setup{
|
||||
ensure_installed={
|
||||
'ansiblels',
|
||||
'bashls'
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
require("mason-lspconfig").setup_handlers({
|
||||
-- The first entry (without a key) will be the default handler
|
||||
-- and will be called for each installed server that doesn't have
|
||||
-- a dedicated handler.
|
||||
function (server_name) -- default handler (optional)
|
||||
require("lspconfig")[server_name].setup {}
|
||||
end,
|
||||
-- Next, you can provide targeted overrides for specific servers.
|
||||
--
|
||||
})
|
13
lua/plugins/neotree.lua
Normal file
13
lua/plugins/neotree.lua
Normal file
|
@ -0,0 +1,13 @@
|
|||
local neotree = require 'neo-tree'
|
||||
|
||||
neotree.setup({
|
||||
event_handlers = {
|
||||
{
|
||||
event = "file_opened",
|
||||
handler = function(file_path)
|
||||
--auto close
|
||||
require("neo-tree").close_all()
|
||||
end
|
||||
},
|
||||
}
|
||||
})
|
22
lua/plugins/treesitter.lua
Normal file
22
lua/plugins/treesitter.lua
Normal file
|
@ -0,0 +1,22 @@
|
|||
-- Tree sitter
|
||||
local ts = require 'nvim-treesitter.configs'
|
||||
|
||||
ts.setup {
|
||||
ensure_installed = {
|
||||
'bash',
|
||||
'c',
|
||||
'cmake',
|
||||
'dockerfile',
|
||||
'latex',
|
||||
'lua',
|
||||
'markdown',
|
||||
'markdown_inline',
|
||||
'python',
|
||||
'yaml'
|
||||
},
|
||||
sync_install = false,
|
||||
highlight = {
|
||||
enable = true,
|
||||
additional_vim_regex_highlighting = false,
|
||||
}
|
||||
}
|
2
lua/plugins/whichkey.lua
Normal file
2
lua/plugins/whichkey.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
local wk = require 'which-key'
|
||||
wk.register()
|
92
lua/settings.lua
Normal file
92
lua/settings.lua
Normal file
|
@ -0,0 +1,92 @@
|
|||
-- General Option
|
||||
|
||||
vim.g.mapleader = " "
|
||||
vim.g.maplocalleader = " "
|
||||
|
||||
vim.opt.autoindent = true
|
||||
vim.opt.background = 'dark'
|
||||
vim.opt.backupdir = os.getenv("HOME") .. '/.local/tmp/nvim'
|
||||
vim.opt.clipboard = 'unnamedplus' --Use system clipboard
|
||||
vim.opt.colorcolumn = '80'
|
||||
vim.opt.directory = os.getenv("HOME") .. '/.local/tmp/nvim'
|
||||
vim.opt.expandtab = true
|
||||
vim.opt.foldmethod = 'syntax'
|
||||
vim.opt.gdefault = true -- search: all occurrences by default
|
||||
vim.opt.hlsearch = true -- search: hightlight terms
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.incsearch = true
|
||||
vim.opt.laststatus = 1
|
||||
-- show special character
|
||||
vim.opt.listchars = {tab = '→ ', trail = '␣', eol = '', extends = '…' }
|
||||
|
||||
vim.opt.signcolumn = "yes" -- alway show sign column
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
vim.opt.cursorline = true -- highlight current line
|
||||
vim.opt.shiftwidth = 4
|
||||
vim.opt.showmatch = true
|
||||
vim.opt.smartcase = true -- search: try :to be smart about cases
|
||||
vim.opt.smartindent = true
|
||||
vim.opt.tabstop = 4
|
||||
vim.opt.termguicolors = true -- 24 bits color support
|
||||
vim.opt.wildmenu = true -- activate enhanced user menu
|
||||
vim.opt.wildmode = 'lastused:full,list' -- enhance menu
|
||||
vim.opt.pumheight = 10
|
||||
vim.opt.pumwidth = 50
|
||||
vim.opt.pumblend = 10
|
||||
|
||||
-- Options than need vim.cmd
|
||||
-- vim.cmd('syntax on')
|
||||
|
||||
-- -- Code Fold
|
||||
-- "Load and save view atomatocally (save and restore fold)
|
||||
vim.cmd('au BufWinLeave *.* mkview')
|
||||
vim.cmd('au BufWinEnter *.* silent! loadview')
|
||||
|
||||
|
||||
-- Diagnostic settings
|
||||
--
|
||||
-- diagnostic windows must be float
|
||||
vim.diagnostic.config {
|
||||
virtual_text = false,
|
||||
signs = true,
|
||||
underline = true,
|
||||
}
|
||||
|
||||
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
||||
for type, icon in pairs(signs) do
|
||||
local hl = "DiagnosticSign" .. type
|
||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
||||
end
|
||||
|
||||
-- You will likely want to reduce updatetime which affects CursorHold
|
||||
-- note: this setting is global and should be set only once
|
||||
vim.o.updatetime = 250
|
||||
vim.cmd [[autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {scope='cursor', header = "", prefix = "", focus=false})]]
|
||||
|
||||
-- Autotype
|
||||
vim.cmd('au BufRead,BufNewFile *.md setlocal textwidth=80')
|
||||
vim.cmd('au BufRead,BufNewFile *.tex setlocal textwidth=80')
|
||||
vim.cmd('au BufNewFile,BufRead /tmp/neomutt* set tw=72 fo=awq comments+=nb:> noautoindent filetype=mail')
|
||||
|
||||
-- Ignore these filenames during enhanced command line completion.
|
||||
vim.opt.wildignore = {
|
||||
'*.bak',
|
||||
'*.class',
|
||||
'*.aux',
|
||||
'*.out',
|
||||
'*.toc',
|
||||
'*.jpg',
|
||||
'*.bmp',
|
||||
'*.gif',
|
||||
'*.png',
|
||||
'*.luac',
|
||||
'*.o',
|
||||
'*.obj',
|
||||
'*.exe',
|
||||
'*.dll',
|
||||
'*.manifest',
|
||||
'*.pyc',
|
||||
'*.spl',
|
||||
'*.sw?'
|
||||
}
|
Reference in a new issue