Add proper support for snippets, and tab width

This commit is contained in:
juan 2023-03-09 16:26:45 +08:00
parent 0ce6e0e6ed
commit 43456e196f
Signed by: juan
GPG Key ID: 5C1E5093C74F1DC7
4 changed files with 99 additions and 76 deletions

View File

@ -3,15 +3,12 @@ local o = vim.o
local global = vim.g local global = vim.g
-- look and feel -- look and feel
vim.opt.shortmess:append({I = true}) -- remove intro message
o.termguicolors = true o.termguicolors = true
o.ruler = true o.ruler = true
o.relativenumber = true o.relativenumber = true
o.number = true o.number = true
o.showmode = false o.showmode = false
o.scrolloff = 10 o.scrolloff = 10
o.softtabstop = 2
o.shiftwidth = 2
-- controlling -- controlling
vim.opt.completeopt = {'menu', 'menuone', 'noselect'} vim.opt.completeopt = {'menu', 'menuone', 'noselect'}
@ -19,7 +16,7 @@ o.ignorecase = true
o.smartcase = true o.smartcase = true
o.smartindent = true o.smartindent = true
o.autoindent = true o.autoindent = true
o.mouse = "a" o.mouse = "i"
-- leader settings -- leader settings
global.mapleader = ' ' global.mapleader = ' '

View File

@ -45,7 +45,11 @@ return require('packer').startup(function(use)
} }
-- completer -- completer
use { 'L3MON4D3/LuaSnip', event = 'UIEnter' } use {
'L3MON4D3/LuaSnip',
event = 'UIEnter',
requires = { 'rafamadriz/friendly-snippets' }
}
use { use {
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
event = 'InsertEnter', event = 'InsertEnter',
@ -54,22 +58,22 @@ return require('packer').startup(function(use)
requires = { requires = {
-- local -- local
{ 'hrsh7th/cmp-cmdline', after = 'nvim-cmp' }, { 'hrsh7th/cmp-cmdline', after = 'nvim-cmp' },
{ 'hrsh7th/cmp-buffer', after = 'nvim-cmp' }, { 'hrsh7th/cmp-buffer', after = 'nvim-cmp' },
{ 'hrsh7th/cmp-path', after = 'nvim-cmp' }, { { 'hrsh7th/cmp-path', after = 'nvim-cmp' }, {
'petertriho/cmp-git', 'petertriho/cmp-git',
after = 'nvim-cmp', after = 'nvim-cmp',
config = function() require("cmp_git").setup() end config = function() require("cmp_git").setup() end
}, { 'delphinus/cmp-ctags', after = 'nvim-cmp' }, -- end }, { 'delphinus/cmp-ctags', after = 'nvim-cmp' }, -- end
-- lsp -- lsp
{ 'hrsh7th/cmp-nvim-lsp-document-symbol', after = 'nvim-cmp' }, -- TS { 'hrsh7th/cmp-nvim-lsp-document-symbol', after = 'nvim-cmp' }, -- TS
{ 'ray-x/cmp-treesitter', after = 'nvim-cmp' }, -- end { 'ray-x/cmp-treesitter', after = 'nvim-cmp' }, -- end
-- Snip -- Snip
{ 'saadparwaiz1/cmp_luasnip', after = { 'nvim-cmp', 'LuaSnip' } } { 'saadparwaiz1/cmp_luasnip', after = { 'nvim-cmp', 'LuaSnip' } }
} }
} }
-- formating and editing -- formating and editing
use { "williamboman/mason.nvim", event = 'BufEnter'} use { "williamboman/mason.nvim", event = 'BufEnter' }
use { use {
'windwp/nvim-autopairs', 'windwp/nvim-autopairs',
after = 'nvim-cmp', after = 'nvim-cmp',
@ -146,7 +150,8 @@ return require('packer').startup(function(use)
require 'treesitter-context'.setup { require 'treesitter-context'.setup {
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands) enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit. max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
patterns = { -- Match patterns for TS nodes. These get wrapped to match at word boundaries. patterns = {
-- Match patterns for TS nodes. These get wrapped to match at word boundaries.
-- For all filetypes -- For all filetypes
-- Note that setting an entry here replaces all other patterns for this entry. -- Note that setting an entry here replaces all other patterns for this entry.
-- By setting the 'default' entry below, you can control which nodes you want to -- By setting the 'default' entry below, you can control which nodes you want to

View File

@ -1,73 +1,94 @@
local cmp = require 'cmp' require("luasnip.loaders.from_vscode").lazy_load()
local luasnip = require("luasnip")
local has_words_before = function() local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0)) unpack = unpack or table.unpack
return col ~= 0 and local line, col = unpack(vim.api.nvim_win_get_cursor(0))
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
col)
:match("%s") == nil
end end
local luasnip = require("luasnip")
local cmp = require("cmp")
cmp.setup({ cmp.setup({
snippet = { -- ... Your other configuration ...
-- REQUIRED - you must specify a snippet engine snippet = {
expand = function(args) -- REQUIRED - you must specify a snippet engine
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users. -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users. require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
end -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
}, end,
window = { },
-- completion = cmp.config.window.bordered(), mapping = {
-- documentation = cmp.config.window.bordered(), ["<Tab>"] = cmp.mapping(function(fallback)
}, if cmp.visible() then
mapping = cmp.mapping.preset.insert({ cmp.select_next_item()
['<C-b>'] = cmp.mapping.scroll_docs(-4), -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
['<C-f>'] = cmp.mapping.scroll_docs(4), -- they way you will only jump inside the snippet region
['<C-Space>'] = cmp.mapping.complete(), elseif luasnip.expand_or_jumpable() then
['<C-e>'] = cmp.mapping.abort(), luasnip.expand_or_jump()
['<CR>'] = cmp.mapping.confirm({select = true}), elseif has_words_before() then
["<Tab>"] = cmp.mapping(function(fallback) cmp.complete()
if cmp.visible() then else
cmp.select_next_item() fallback()
elseif luasnip.expand_or_jumpable() then end
luasnip.expand_or_jump() end, { "i", "s" }),
else ["<S-Tab>"] = cmp.mapping(function(fallback)
fallback() if cmp.visible() then
end cmp.select_prev_item()
end, {"i", "s"}), elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
["<S-Tab>"] = cmp.mapping(function(fallback) else
if cmp.visible() then fallback()
cmp.select_prev_item() end
elseif luasnip.jumpable(-1) then end, { "i", "s" }),
luasnip.jump(-1) ['<C-b>'] = cmp.mapping.scroll_docs(-4),
else ['<C-f>'] = cmp.mapping.scroll_docs(4),
fallback() ['<C-Space>'] = cmp.mapping.complete(),
end ['<C-e>'] = cmp.mapping.abort(),
end, {"i", "s"}) ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items
}), -- ... Your other mappings ...
sources = cmp.config.sources({{name = 'nvim_lsp'}}, {{name = 'treesitter'}}, },
{{name = 'luasnip'}}, sources = cmp.config.sources({
{{name = 'buffer'}, {name = 'path'}}) { name = "nvim_lsp" },
{ name = "treesitter" },
{ name = "buffer" },
{ name = "luasnip" }, -- For luasnip users.
{ name = "path" },
{ name = "git" },
{ name = "ctags" },
})
-- ... Your other configuration ...
}) })
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline({ '/', '?' }, {
cmp.setup.cmdline('/', { mapping = cmp.mapping.preset.cmdline(),
mapping = cmp.mapping.preset.cmdline(), sources = {
sources = {{name = 'nvim_lsp_document_symbol'}, {name = 'buffer'}} { name = 'buffer' }
}) }
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({{name = 'path'}}, {{name = 'cmdline'}})
}) })
-- Set configuration for specific filetype. -- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', { cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({{name = 'git'}}, sources = cmp.config.sources({
{{name = 'buffer'}}) { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
-- `:` cmdline setup.
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{
name = 'cmdline',
option = {
ignore_cmds = { 'Man', '!' }
}
}
})
}) })

0
lua/plugins/test.java Normal file
View File