Add proper support for snippets, and tab width
This commit is contained in:
parent
0ce6e0e6ed
commit
43456e196f
@ -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 = ' '
|
||||||
|
@ -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',
|
||||||
@ -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
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
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()
|
||||||
|
unpack = unpack or table.unpack
|
||||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
return col ~= 0 and
|
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||||
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col,
|
|
||||||
col)
|
|
||||||
:match("%s") == nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local luasnip = require("luasnip")
|
||||||
|
local cmp = require("cmp")
|
||||||
|
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
|
-- ... Your other configuration ...
|
||||||
snippet = {
|
snippet = {
|
||||||
-- REQUIRED - you must specify a snippet engine
|
-- REQUIRED - you must specify a snippet engine
|
||||||
expand = function(args)
|
expand = function(args)
|
||||||
@ -17,28 +18,22 @@ cmp.setup({
|
|||||||
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
||||||
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
|
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
|
||||||
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
|
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
|
||||||
end
|
end,
|
||||||
},
|
},
|
||||||
window = {
|
mapping = {
|
||||||
-- completion = cmp.config.window.bordered(),
|
|
||||||
-- documentation = cmp.config.window.bordered(),
|
|
||||||
},
|
|
||||||
mapping = cmp.mapping.preset.insert({
|
|
||||||
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
|
||||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
||||||
['<C-Space>'] = cmp.mapping.complete(),
|
|
||||||
['<C-e>'] = cmp.mapping.abort(),
|
|
||||||
['<CR>'] = cmp.mapping.confirm({select = true}),
|
|
||||||
["<Tab>"] = cmp.mapping(function(fallback)
|
["<Tab>"] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_next_item()
|
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
|
elseif luasnip.expand_or_jumpable() then
|
||||||
luasnip.expand_or_jump()
|
luasnip.expand_or_jump()
|
||||||
|
elseif has_words_before() then
|
||||||
|
cmp.complete()
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
end, { "i", "s" }),
|
end, { "i", "s" }),
|
||||||
|
|
||||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_prev_item()
|
cmp.select_prev_item()
|
||||||
@ -47,27 +42,53 @@ cmp.setup({
|
|||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
end, {"i", "s"})
|
end, { "i", "s" }),
|
||||||
}),
|
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||||
sources = cmp.config.sources({{name = 'nvim_lsp'}}, {{name = 'treesitter'}},
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||||
{{name = 'luasnip'}},
|
['<C-Space>'] = cmp.mapping.complete(),
|
||||||
{{name = 'buffer'}, {name = 'path'}})
|
['<C-e>'] = cmp.mapping.abort(),
|
||||||
|
['<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 = "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 = {{name = 'nvim_lsp_document_symbol'}, {name = 'buffer'}}
|
sources = {
|
||||||
})
|
{ 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
0
lua/plugins/test.java
Normal file
Loading…
Reference in New Issue
Block a user