Created
October 27, 2021 15:37
-
-
Save J-MR-T/22f5bf12d135acc10a52809734da129b to your computer and use it in GitHub Desktop.
vimrc (including neovim) 27.10.2021
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
" General config | |
"" Line numbers | |
"set number | |
"" Case-insensitive search | |
set ignorecase | |
""" But only if the search is all lower case, otherwise it (smartly) does | |
" search case-sensitievly | |
set smartcase | |
"" Comma as leader | |
let mapleader = "," | |
"" Terminal size | |
if !has('nvim') | |
set termwinsize=10x0 | |
endif | |
if has('nvim') | |
set splitbelow | |
endif | |
"" Shortcuts | |
" Toggle terminal - bottom | |
if !has('nvim') | |
nnoremap <silent> <F2> :bo term<CR> | |
else | |
" nnoremap <silent> <F2> :10Term<CR> | |
endif | |
map <C-Tab> :bnext<CR> | |
noremap <C-S-Tab> :bprevious<CR> | |
inoremap <C-c> <C-o>:call nerdcommenter#Comment("n","toggle")<C-m> | |
nnoremap <C-c> :call nerdcommenter#Comment("n","toggle")<C-m> | |
vmap <C-c> :call nerdcommenter#Comment("x","toggle")<C-m> | |
""" NerdTree | |
" Map the F3 key to toggle NERDTree open and close. | |
nnoremap <F3> :NERDTreeToggle<cr> | |
" Have nerdtree ignore certain files and directories. | |
let NERDTreeIgnore=['\.git$', '\.jpg$', '\.mp4$', '\.ogg$','\.iso$', '\.pdf$', '\.pyc$', '\.odt$', '\.png$', '\.gif$', '\.db$'] | |
""" Split window controls | |
" You can split the window in Vim by typing :split or :vsplit. | |
"""" Navigate the split view easier by pressing CTRL+j, CTRL+k, CTRL+h, or | |
" CTRL+l. | |
nnoremap <c-j> <c-w>j | |
nnoremap <c-k> <c-w>k | |
nnoremap <c-h> <c-w>h | |
nnoremap <c-l> <c-w>l | |
cnoremap <c-j> <c-w>j | |
cnoremap <c-k> <c-w>k | |
cnoremap <c-h> <c-w>h | |
cnoremap <c-l> <c-w>l | |
"""" Resize split windows using arrow keys by pressing: | |
" CTRL+UP, CTRL+DOWN, CTRL+LEFT, or CTRL+RIGHT. | |
" TODO doesn't work :( | |
nnoremap <c-up> <c-w>+ | |
nnoremap <c-down> <c-w>- | |
nnoremap <c-left> <c-w>< | |
nnoremap <c-right> <c-w>> | |
"" 4 spaces on tab rulz | |
set tabstop=4 | |
set expandtab | |
set shiftwidth=4 | |
set smarttab | |
"" Show matching words during a search. | |
set showmatch | |
"" Use highlighting when doing a search. | |
set hlsearch | |
""" incsearch.vim Plugin Settings | |
map / <Plug>(incsearch-forward) | |
map ? <Plug>(incsearch-backward) | |
map g/ <Plug>(incsearch-stay) | |
let g:incsearch#auto_nohlsearch = 1 | |
" zz to center cursor vertically after search | |
map n <Plug>(incsearch-nohl-n)zz | |
map N <Plug>(incsearch-nohl-N)zz | |
map * <Plug>(incsearch-nohl-*) | |
map # <Plug>(incsearch-nohl-#) | |
map g* <Plug>(incsearch-nohl-g*) | |
map g# <Plug>(incsearch-nohl-g#) | |
hi SpellBad ctermfg=160 ctermbg=016 guifg=#ff0000 guibg=#00ffff | |
hi SpellCap ctermfg=160 ctermbg=016 guifg=#ff0000 guibg=#00ffff | |
"" Set the commands to save in history default number is 20. | |
set history=1000 | |
""" Enable auto completion menu after pressing TAB. | |
"set wildmenu | |
" | |
""" Make wildmenu behave like similar to Bash completion. | |
"set wildmode=list:longest | |
" | |
""" There are certain files that we would never want to edit with Vim. | |
" " Wildmenu will ignore files with these extensions. | |
"set wildignore=*.docx,*.jpg,*.png,*.gif,*.pdf,*.pyc,*.exe,*.flv,*.img,*.xlsx" | |
"" NERDCommenter | |
""" Use compact syntax for prettified multi-line comments | |
let g:NERDCompactSexyComs = 1 | |
""" Align line-wise comment delimiters flush left instead of following code indentation | |
let g:NERDDefaultAlign = 'left' | |
""" Set a language to use its alternate delimiters by default | |
let g:NERDAltDelims_c = 1 | |
""" Allow commenting and inverting empty lines (useful when commenting a region) | |
let g:NERDCommentEmptyLines = 1 | |
""" Enable trimming of trailing whitespace when uncommenting | |
let g:NERDTrimTrailingWhitespace = 1 | |
" Pluginzzzzz | |
call plug#begin('~/.vim/plugged') | |
" Autocompletion | |
"Plug 'ervandew/supertab' | |
"Plug 'maxboisvert/vim-simple-complete' | |
if has('nvim') | |
Plug 'neovim/nvim-lspconfig' | |
Plug 'hrsh7th/nvim-cmp' | |
Plug 'hrsh7th/cmp-nvim-lsp' | |
Plug 'quangnguyen30192/cmp-nvim-ultisnips' | |
endif | |
" Syntax checking | |
"Plug 'vim-syntastic/syntastic' | |
" File explorer | |
Plug 'preservim/nerdtree' | |
" Language support | |
" Toggle terminal | |
"Plug 'pakutoma/toggle-terminal' | |
" Better terminal | |
Plug 'vimlab/split-term.vim' | |
" Parentheses | |
Plug 'jiangmiao/auto-pairs' | |
" Comments | |
Plug 'preservim/nerdcommenter' | |
" Incremental searching | |
Plug 'haya14busa/incsearch.vim' | |
" Status bar | |
Plug 'vim-airline/vim-airline' | |
" Snippets | |
"Plug 'MarcWeber/vim-addon-mw-utils' | |
"Plug 'tomtom/tlib_vim' | |
"Plug 'garbas/vim-snipmate' | |
"let g:snipMate = { 'snippet_version' : 1 } | |
"Plug 'honza/vim-snippets' | |
"" Engine | |
Plug 'SirVer/ultisnips' | |
"" Actual snippets | |
Plug 'honza/vim-snippets' | |
"" Config | |
let g:UltiSnipsExpandTrigger="<tab>" | |
let g:UltiSnipsJumpForwardTrigger="<c-b>" | |
let g:UltiSnipsJumpBackwardTrigger="<c-z>" | |
" Language Packs | |
Plug 'sheerun/vim-polyglot' | |
" Colors | |
Plug 'ap/vim-css-color' | |
call plug#end() | |
" Autocomplete setup | |
set completeopt=menu,menuone,noselect | |
lua <<EOF | |
local nvim_lsp = require('lspconfig') | |
-- Define on_attach function | |
local my_on_attach = function(_, bufnr) | |
-- require('completion').on_attach() | |
local opts = { noremap=true, silent=true } | |
vim.api.nvim_buf_set_keymap(bufnr, 'n','<M-CR>','<cmd>lua vim.lsp.buf.code_action() <CR>',opts) | |
-- TODO make F2 open the documentation for the current method | |
vim.api.nvim_buf_set_keymap(bufnr, 'n','<F2>','<cmd>lua vim.lsp.buf.signature_help() <CR>',opts) | |
end | |
-- Syntactic sugar | |
local press = function(key) | |
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), "n", true) | |
end | |
local has_any_words_before = function() | |
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then | |
return false | |
end | |
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 = vim.lsp.protocol.make_client_capabilities() | |
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) | |
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp | |
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'kotlin_language_server', 'ocamlls', 'bashls' } | |
for _, lsp in ipairs(servers) do | |
nvim_lsp[lsp].setup { | |
on_attach = my_on_attach, | |
capabilities = capabilities, | |
} | |
end | |
-- Setup nvim-cmp. | |
local cmp = require'cmp' | |
cmp.setup({ | |
snippet = { | |
expand = function(args) | |
-- For `vsnip` user. | |
-- vim.fn["vsnip#anonymous"](args.body) | |
-- For `luasnip` user. | |
-- require('luasnip').lsp_expand(args.body) | |
-- For `ultisnips` user. | |
vim.fn["UltiSnips#Anon"](args.body) | |
end, | |
}, | |
mapping = { | |
['<C-p>'] = cmp.mapping.select_prev_item(), | |
['<C-n>'] = cmp.mapping.select_next_item(), | |
['<C-d>'] = cmp.mapping.scroll_docs(-4), | |
['<C-f>'] = cmp.mapping.scroll_docs(4), | |
['<C-Space>'] = cmp.mapping(function(fallback) | |
if vim.fn.complete_info()["selected"] == -1 and vim.fn["UltiSnips#CanExpandSnippet"]() == 1 then | |
press("<C-R>=UltiSnips#ExpandSnippet()<CR>") | |
elseif cmp.visible() then | |
cmp.mapping.complete() | |
end | |
end), | |
['<C-e>'] = cmp.mapping.close(), | |
['<CR>'] = cmp.mapping.confirm { | |
behavior = cmp.ConfirmBehavior.Replace, | |
select = true, | |
}, | |
["<Tab>"] = cmp.mapping(function(fallback) | |
if cmp.visible() == false and vim.fn["UltiSnips#CanExpandSnippet"]() == 1 then | |
press("<C-R>=UltiSnips#ExpandSnippet()<CR>") | |
elseif vim.fn["UltiSnips#CanJumpForwards"]() == 1 then | |
press("<ESC>:call UltiSnips#JumpForwards()<CR>") | |
elseif cmp.visible() then | |
cmp.select_next_item() | |
elseif has_any_words_before() then | |
press("<Tab>") | |
else | |
fallback() | |
end | |
end, { | |
"i", | |
"s", | |
}), | |
["<S-Tab>"] = cmp.mapping(function(fallback) | |
if vim.fn["UltiSnips#CanJumpBackwards"]() == 1 then | |
press("<ESC>:call UltiSnips#JumpBackwards()<CR>") | |
elseif cmp.visible() then | |
cmp.select_prev_item() | |
else | |
fallback() | |
end | |
end, { | |
"i", | |
"s", | |
}), | |
}, | |
sources = { | |
{ name = 'nvim_lsp' }, | |
-- For vsnip user. | |
-- { name = 'vsnip' }, | |
-- For luasnip user. | |
-- { name = 'luasnip' }, | |
-- For ultisnips user. | |
{ name = 'ultisnips' }, | |
{ name = 'buffer' }, | |
} | |
}) | |
EOF | |
" Syntastic | |
"set statusline+=%#warningmsg# | |
"set statusline+=%{SyntasticStatuslineFlag()} | |
"set statusline+=%* | |
" | |
"let g:syntastic_always_populate_loc_list = 1 | |
"let g:syntastic_auto_loc_list = 1 | |
"let g:syntastic_check_on_open = 1 | |
"let g:syntastic_check_on_wq = 0 | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment