Last active
August 6, 2021 03:38
-
-
Save ayoubelmhamdi/3c18bc539a47946577b0e04c6b56ea07 to your computer and use it in GitHub Desktop.
mini.lu for neovim with luasnip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim.cmd([[ | |
autocmd BufWritePost mini.lua source <afile> | PackerCompile | |
set mouse=a | |
set clipboard=unnamedplus | |
set nowrap | |
set rnu nu | |
set autoindent | |
set smartindent | |
set tabstop=4 | |
set softtabstop=4 | |
set shiftwidth=2 | |
set expandtab | |
set smarttab | |
set backspace=indent,eol,start | |
set colorcolumn=60 | |
set scrolloff=7 | |
set updatetime=300 | |
set directory=$HOME/.local/vim/dir/,. | |
set noswapfile | |
set nowritebackup | |
set backupdir=$HOME/.local/vim/backup | |
set nobackup | |
set undodir+=$HOME/.local/vim/undodir | |
set undofile | |
set wildignore+=*.o,*.obj,.git,*.pyc | |
set inccommand=split " -- Make substitution work in realtime | |
inoremap <silent><expr> <C-Space> compe#complete() | |
inoremap <silent><expr> <CR> compe#confirm('<CR>') | |
inoremap <silent><expr> <C-e> compe#close('<C-e>') | |
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 }) | |
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 }) | |
imap <silent><expr> <C-E> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-E>' | |
smap <silent><expr> <C-E> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-E>' | |
imap <silent><expr> <Tab> luasnip#expand_or_jumpable() ? '<Plug>luasnip-expand-or-jump' : '<Tab>' | |
inoremap <silent> <S-Tab> <cmd>lua require'luasnip'.jump(-1)<Cr> | |
snoremap <silent> <Tab> <cmd>lua require('luasnip').jump(1)<Cr> | |
snoremap <silent> <S-Tab> <cmd>lua require('luasnip').jump(-1)<Cr> | |
]]) | |
--local use = require('packer').use | |
--require('packer').startup( | |
--function() | |
require('packer').startup(function() | |
use 'wbthomason/packer.nvim' | |
use 'hrsh7th/nvim-compe' | |
use 'L3MON4D3/LuaSnip' | |
use 'rafamadriz/friendly-snippets' | |
end) | |
vim.o.completeopt = "menuone,noselect" | |
require'compe'.setup { | |
enabled = true; | |
autocomplete = true; | |
debug = false; | |
min_length = 1; | |
preselect = 'enable'; | |
throttle_time = 80; | |
source_timeout = 200; | |
resolve_timeout = 800; | |
incomplete_delay = 400; | |
max_abbr_width = 100; | |
max_kind_width = 100; | |
max_menu_width = 100; | |
documentation = { | |
border = { '', '' ,'', ' ', '', '', '', ' ' }, -- the border option is the same as `|help nvim_open_win|` | |
winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder", | |
max_width = 120, | |
min_width = 60, | |
max_height = math.floor(vim.o.lines * 0.3), | |
min_height = 1, | |
}; | |
source = { | |
path = true; | |
buffer = true; | |
calc = true; | |
nvim_lsp = true; | |
nvim_lua = true; | |
vsnip = false; | |
ultisnips = true; | |
luasnip = true; | |
}; | |
} | |
local t = function(str) | |
return vim.api.nvim_replace_termcodes(str, true, true, true) | |
end | |
local check_back_space = function() | |
local col = vim.fn.col('.') - 1 | |
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then | |
return true | |
else | |
return false | |
end | |
end | |
_G.tab_complete = function() | |
if vim.fn.pumvisible() == 1 then | |
return t "<C-n>" | |
elseif require("luasnip").expand_or_jumpable() then | |
return t "<cmd>lua require'luasnip'.jump(1)<Cr>" | |
elseif check_back_space() then | |
return t "<Tab>" | |
else | |
return vim.fn["compe#complete"]() | |
end | |
end | |
_G.s_tab_complete = function() | |
if vim.fn.pumvisible() == 1 then | |
return t "<C-p>" | |
elseif require("luasnip").jumpable(-1) then | |
return t "<cmd>lua require'luasnip'.jump(-1)<CR>" | |
else | |
return t "<S-Tab>" | |
end | |
end | |
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true}) | |
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true}) | |
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true}) | |
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true}) | |
require('luasnip.loaders.from_vscode').load() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment