Skip to content

Commit 2d8c8c5

Browse files
committed
Variant nvim-lua#2
1 parent 2550eef commit 2d8c8c5

File tree

12 files changed

+555
-386
lines changed

12 files changed

+555
-386
lines changed

lua/Lazy.lua

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,32 @@ end
1212
vim.opt.rtp:prepend(lazypath)
1313

1414
require('lazy').setup({
15+
'nvim-lua/plenary.nvim',
16+
1517
-- Git related plugins
1618
'tpope/vim-fugitive',
1719
'tpope/vim-rhubarb',
1820

1921
-- Detect tabstop and shiftwidth automatically
2022
-- 'tpope/vim-sleuth',
2123

22-
"famiu/bufdelete.nvim",
24+
'famiu/bufdelete.nvim',
2325
{
2426
'akinsho/bufferline.nvim',
25-
version = "*",
27+
version = '*',
2628
dependencies = 'nvim-tree/nvim-web-devicons',
2729
opts = {
2830
options = {
2931
offsets = {
3032
{
31-
filetype = "NvimTree",
32-
text = "File Explorer",
33-
text_align = "center",
33+
filetype = 'NvimTree',
34+
text = 'File Explorer',
35+
text_align = 'center',
3436
separator = false,
3537
},
3638
},
3739
},
38-
}
40+
},
3941
},
4042

4143
{
@@ -48,54 +50,55 @@ require('lazy').setup({
4850

4951
{
5052
'windwp/nvim-autopairs',
51-
event = "insertenter",
52-
opts = {}
53+
event = 'insertenter',
54+
opts = {},
5355
},
5456
{
55-
"windwp/nvim-ts-autotag",
57+
'windwp/nvim-ts-autotag',
5658
config = function()
57-
require("nvim-ts-autotag").setup()
59+
require('nvim-ts-autotag').setup()
5860
end,
5961
},
6062

6163
{
62-
"folke/trouble.nvim",
63-
dependencies = { "nvim-tree/nvim-web-devicons" },
64+
'folke/trouble.nvim',
65+
dependencies = { 'nvim-tree/nvim-web-devicons' },
6466
opts = {},
6567
},
6668

6769
{
68-
"petertriho/nvim-scrollbar",
69-
event = "VeryLazy",
70+
'petertriho/nvim-scrollbar',
71+
event = 'VeryLazy',
7072
config = function()
71-
local scrollbar = require("scrollbar")
72-
scrollbar.setup({
73+
local scrollbar = require 'scrollbar'
74+
scrollbar.setup {
7375
show_in_active_only = true,
7476
handle = {
7577
blend = 0,
76-
text = " ",
77-
color = "#1c1c1c",
78+
text = ' ',
79+
color = '#1c1c1c',
7880
color_nr = 234,
7981
},
8082
marks = {
81-
Search = { color = "#C9A554" },
82-
Error = { color = "#685742" },
83-
Warn = { color = "#B36D43" },
84-
Info = { color = "#5f875f" },
85-
Hint = { color = "#5f875f" },
86-
Misc = { color = "#bb7744" },
87-
Cursor = { color = "#222222", text = " " },
88-
}
89-
})
83+
Search = { color = '#C9A554' },
84+
Error = { color = '#685742' },
85+
Warn = { color = '#B36D43' },
86+
Info = { color = '#5f875f' },
87+
Hint = { color = '#5f875f' },
88+
Misc = { color = '#bb7744' },
89+
Cursor = { color = '#222222', text = ' ' },
90+
},
91+
}
9092
end,
9193
},
9294

9395
{
94-
"kylechui/nvim-surround",
95-
version = "*", -- Use for stability; omit to use `main` branch for the latest features
96-
event = "VeryLazy",
96+
'kylechui/nvim-surround',
97+
version = '*', -- Use for stability; omit to use `main` branch for the latest features
98+
event = 'VeryLazy',
9799
opts = {},
98100
},
99101

100-
{ import = 'plugins' }
102+
{ import = 'plugins' },
103+
{ import = 'plugins.lsp' },
101104
}, {})

lua/keymaps.lua

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,43 @@ vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = tr
2121
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
2222

2323
-- Better window navigation
24-
keymap("n", "<C-h>", "<C-w>h", opts)
25-
keymap("n", "<C-j>", "<C-w>j", opts)
26-
keymap("n", "<C-k>", "<C-w>k", opts)
27-
keymap("n", "<C-l>", "<C-w>l", opts)
24+
keymap('n', '<C-h>', '<C-w>h', opts)
25+
keymap('n', '<C-j>', '<C-w>j', opts)
26+
keymap('n', '<C-k>', '<C-w>k', opts)
27+
keymap('n', '<C-l>', '<C-w>l', opts)
2828

2929
-- Resize with arrows
30-
keymap("n", "<C-Up>", ";resize -2<CR>", opts)
31-
keymap("n", "<C-Down>", ";resize +2<CR>", opts)
32-
keymap("n", "<C-Left>", ":vertical resize -2<CR>", opts)
33-
keymap("n", "<C-Right>", ":vertical resize +2<CR>", opts)
30+
keymap('n', '<C-Up>', ';resize -2<CR>', opts)
31+
keymap('n', '<C-Down>', ';resize +2<CR>', opts)
32+
keymap('n', '<C-Left>', ':vertical resize -2<CR>', opts)
33+
keymap('n', '<C-Right>', ':vertical resize +2<CR>', opts)
3434

3535
-- Navigate buffers
36-
keymap("n", "<S-l>", ":bnext<CR>", opts)
37-
keymap("n", "<S-h>", ":bprevious<CR>", opts)
36+
keymap('n', '<S-l>', ':bnext<CR>', opts)
37+
keymap('n', '<S-h>', ':bprevious<CR>', opts)
3838

3939
-- Clear highlights
4040
-- keymap("n", "<leader>h", "<cmd>nohlsearch<CR>", opts)
4141

4242
-- Cancel search highlighting with ESC
43-
keymap("n", "<ESC>", ":nohlsearch<Bar>:echo<CR>", opts)
43+
keymap('n', '<ESC>', ':nohlsearch<Bar>:echo<CR>', opts)
4444

4545
-- Close buffers
46-
keymap("n", "<S-q>", "<cmd>Bdelete!<CR>", opts)
46+
keymap('n', '<S-q>', '<cmd>Bdelete!<CR>', opts)
4747

4848
-- Paste over currently selected text without yanking it
49-
keymap("v", "p", '"_dP', opts)
49+
-- keymap("v", "p", '"_dP', opts)
5050

5151
-- Insert --
5252
-- Press jk fast to enter
53-
keymap("i", "jj", "<ESC>", opts)
54-
keymap("i", "kk", "<ESC>", opts)
53+
keymap('i', 'jj', '<ESC>', opts)
54+
keymap('i', 'kk', '<ESC>', opts)
5555

5656
-- Visual --
5757
-- Stay in indent mode
58-
keymap("v", "<", "<gv", opts)
59-
keymap("v", ">", ">gv", opts)
58+
keymap('v', '<', '<gv', opts)
59+
keymap('v', '>', '>gv', opts)
6060

6161
-- Move selected line / block of text in visual mode
62-
keymap("x", "K", ":move '<-2<CR>gv-gv", opts)
63-
keymap("x", "J", ":move '>+1<CR>gv-gv", opts)
62+
keymap('x', 'K', ":move '<-2<CR>gv-gv", opts)
63+
keymap('x', 'J', ":move '>+1<CR>gv-gv", opts)

lua/options.lua

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ vim.o.mouse = 'a'
3737
-- See `:help 'clipboard'`
3838
vim.o.clipboard = 'unnamedplus'
3939

40-
vim.opt.colorcolumn = "79"
40+
vim.opt.colorcolumn = '79'
4141

4242
-- searching
4343
vim.o.hlsearch = true
4444
vim.o.incsearch = true
45-
vim.o.inccommand = "split"
45+
vim.o.inccommand = 'split'
4646

4747
-- Keep signcolumn on by default
4848
vim.wo.signcolumn = 'yes'
@@ -92,19 +92,19 @@ vim.o.smartcase = true
9292
vim.o.infercase = true
9393

9494
-- make backspace behave in a sane manner
95-
vim.o.backspace = "indent,eol,start"
95+
vim.o.backspace = 'indent,eol,start'
9696

9797
-- show matching brackets/parenthesis
9898
vim.opt.showmatch = true
9999

100100
-- disable startup message
101-
vim.opt.shortmess:append("sI")
101+
vim.opt.shortmess:append 'sI'
102102

103103
-- cmd display (set to zero to autohide)
104104
vim.opt.cmdheight = 1
105105

106106
-- gutter sizing
107-
vim.opt.signcolumn = "yes:2"
107+
vim.opt.signcolumn = 'yes:2'
108108

109109
-- syntax highlighting
110110
vim.opt.termguicolors = true
@@ -125,10 +125,21 @@ vim.opt.cursorline = true
125125
-- set cursorcolumn = true
126126

127127
-- show invisibles
128-
vim.opt.listchars = { tab = " ", trail = "·", extends = "»", precedes = "«", nbsp = "" }
128+
vim.opt.listchars = { tab = ' ', trail = '·', extends = '»', precedes = '«', nbsp = '' }
129129
vim.opt.list = true
130130

131131
-- split style
132-
vim.opt.fillchars = { vert = "" }
132+
vim.opt.fillchars = { vert = '' }
133133
vim.opt.splitbelow = true
134134
vim.opt.splitright = true
135+
136+
local function system(command)
137+
local file = assert(io.popen(command, 'r'))
138+
local output = file:read('*all'):gsub('%s+', '')
139+
file:close()
140+
return output
141+
end
142+
143+
if vim.fn.executable 'python3' > 0 then
144+
vim.g.python3_host_prog = system 'which python3'
145+
end

lua/plugins/cmp.lua

Lines changed: 67 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,74 @@
1-
local M = {
2-
-- Autocompletion
1+
return {
32
'hrsh7th/nvim-cmp',
3+
event = 'InsertEnter',
44
dependencies = {
5-
-- Snippet Engine & its associated nvim-cmp source
6-
'L3MON4D3/LuaSnip',
7-
'saadparwaiz1/cmp_luasnip',
5+
'hrsh7th/cmp-buffer', -- source for text in buffer
6+
'hrsh7th/cmp-path', -- source for file system paths
7+
'L3MON4D3/LuaSnip', -- snippet engine
8+
'saadparwaiz1/cmp_luasnip', -- for autocompletion
9+
'rafamadriz/friendly-snippets', -- useful snippets
10+
'onsails/lspkind.nvim', -- vs-code like pictograms
11+
},
12+
config = function()
13+
local cmp = require 'cmp'
814

9-
-- Adds LSP completion capabilities
10-
'hrsh7th/cmp-nvim-lsp',
15+
local luasnip = require 'luasnip'
1116

12-
-- Adds a number of user-friendly snippets
13-
-- 'rafamadriz/friendly-snippets',
14-
},
15-
}
17+
local lspkind = require 'lspkind'
1618

17-
function M.config()
18-
local cmp = require 'cmp'
19-
local luasnip = require 'luasnip'
20-
require('luasnip.loaders.from_vscode').lazy_load()
21-
luasnip.config.setup {}
19+
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
20+
require('luasnip.loaders.from_vscode').lazy_load()
2221

23-
cmp.setup {
24-
snippet = {
25-
expand = function(args)
26-
luasnip.lsp_expand(args.body)
27-
end,
28-
},
29-
mapping = cmp.mapping.preset.insert {
30-
['<C-j>'] = cmp.mapping.select_next_item(),
31-
['<C-k>'] = cmp.mapping.select_prev_item(),
32-
['<C-d>'] = cmp.mapping.scroll_docs(-4),
33-
['<C-u>'] = cmp.mapping.scroll_docs(4),
34-
['<C-Space>'] = cmp.mapping.complete {},
35-
['<CR>'] = cmp.mapping.confirm {
36-
behavior = cmp.ConfirmBehavior.Replace,
37-
select = true,
22+
cmp.setup {
23+
completion = {
24+
completeopt = 'menu,menuone,preview,noselect',
3825
},
39-
['<Tab>'] = cmp.mapping(function(fallback)
40-
if cmp.visible() then
41-
cmp.select_next_item()
42-
elseif luasnip.expand_or_locally_jumpable() then
43-
luasnip.expand_or_jump()
44-
else
45-
fallback()
46-
end
47-
end, { 'i', 's' }),
48-
['<S-Tab>'] = cmp.mapping(function(fallback)
49-
if cmp.visible() then
50-
cmp.select_prev_item()
51-
elseif luasnip.locally_jumpable(-1) then
52-
luasnip.jump(-1)
53-
else
54-
fallback()
55-
end
56-
end, { 'i', 's' }),
57-
},
58-
sources = {
59-
{ name = 'nvim_lsp' },
60-
{ name = 'luasnip' },
61-
},
62-
}
63-
end
64-
65-
return M
26+
snippet = { -- configure how nvim-cmp interacts with snippet engine
27+
expand = function(args)
28+
luasnip.lsp_expand(args.body)
29+
end,
30+
},
31+
mapping = cmp.mapping.preset.insert {
32+
['<C-k>'] = cmp.mapping.select_prev_item(), -- previous suggestion
33+
['<C-j>'] = cmp.mapping.select_next_item(), -- next suggestion
34+
['<C-b>'] = cmp.mapping.scroll_docs(-4),
35+
['<C-f>'] = cmp.mapping.scroll_docs(4),
36+
['<C-Space>'] = cmp.mapping.complete(), -- show completion suggestions
37+
['<C-e>'] = cmp.mapping.abort(), -- close completion window
38+
['<CR>'] = cmp.mapping.confirm { select = false },
39+
['<Tab>'] = cmp.mapping(function(fallback)
40+
if cmp.visible() then
41+
cmp.select_next_item()
42+
elseif luasnip.expand_or_locally_jumpable() then
43+
luasnip.expand_or_jump()
44+
else
45+
fallback()
46+
end
47+
end, { 'i', 's' }),
48+
['<S-Tab>'] = cmp.mapping(function(fallback)
49+
if cmp.visible() then
50+
cmp.select_prev_item()
51+
elseif luasnip.locally_jumpable(-1) then
52+
luasnip.jump(-1)
53+
else
54+
fallback()
55+
end
56+
end, { 'i', 's' }),
57+
},
58+
-- sources for autocompletion
59+
sources = cmp.config.sources {
60+
{ name = 'nvim_lsp' },
61+
{ name = 'luasnip' }, -- snippets
62+
{ name = 'buffer' }, -- text within current buffer
63+
{ name = 'path' }, -- file system paths
64+
},
65+
-- configure lspkind for vs-code like pictograms in completion menu
66+
formatting = {
67+
format = lspkind.cmp_format {
68+
maxwidth = 50,
69+
ellipsis_char = '...',
70+
},
71+
},
72+
}
73+
end,
74+
}

0 commit comments

Comments
 (0)