Skip to content

Instantly share code, notes, and snippets.

@polikeiji
Last active February 11, 2022 04:19
Show Gist options
  • Save polikeiji/8fee1622500bc9dcdf1e73bee8c29503 to your computer and use it in GitHub Desktop.
Save polikeiji/8fee1622500bc9dcdf1e73bee8c29503 to your computer and use it in GitHub Desktop.
Neovim configuration for my Windows laptop
set incsearch
set hlsearch
set ts=4 sw=4 sts=0
set et
filetype plugin indent on
syntax enable
set path+=**
set backspace=indent,eol,start
set number
set relativenumber
set autowrite
au TermOpen * setlocal nonumber norelativenumber
au BufNewFile,BufRead Jenkinsfile setf groovy
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType grooby setlocal ts=2 sts=2 sw=2 expandtab
set encoding=utf-8
set fencs=utf-8,iso-2022-jp,sjis,euc-jp
let g:python3_host_prog = '~/miniconda3/bin/python'
tnoremap <expr> <C-R> '<C-\><C-N>"'.nr2char(getchar()).'pi'
" WSL yank support
let s:clip = '/mnt/c/Windows/System32/clip.exe' " change this path according to your mount point
if executable(s:clip)
augroup WSLYank
autocmd!
autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
augroup END
endif
" Copy to clipboard
vnoremap <leader>y “+y
nnoremap <leader>Y “+yg_
nnoremap <leader>y “+y
nnoremap <leader>yy “+yy
" Paste from clipboard
nnoremap <leader>p “+p
nnoremap <leader>P “+P
vnoremap <leader>p “+p
vnoremap <leader>P “+P
" In insert or command mode, move normally by using Ctrl
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>
cnoremap <C-h> <Left>
cnoremap <C-j> <Down>
cnoremap <C-k> <Up>
cnoremap <C-l> <Right>
call plug#begin(stdpath('data') . '/plugged')
Plug 'cocopon/iceberg.vim'
Plug 'christoomey/vim-system-copy'
Plug 'Chiel92/vim-autoformat'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' }
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-compe'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
Plug 'cespare/vim-toml'
Plug 'tpope/vim-fugitive'
Plug 'dense-analysis/ale'
Plug 'lukas-reineke/indent-blankline.nvim'
call plug#end()
colorscheme iceberg
" LSP config (the mappings used in the default file don’t quite work right)
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> <C-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> <C-n> <cmd>lua vim.lsp.diagnostic.goto_prev()<CR>
nnoremap <silent> <C-p> <cmd>lua vim.lsp.diagnostic.goto_next()<CR>
" auto-format
let g:autoformat_verbosemode = 1
let g:formatdef_buildifier = '"buildifier"'
autocmd BufWritePre *.js lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.jsx lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.rs lua vim.lsp.buf.formatting_sync(nil, 100)
lua << EOF
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;
incomplete_delay = 400;
max_abbr_width = 100;
max_kind_width = 100;
max_menu_width = 100;
documentation = false;
source = {
path = true;
buffer = true;
calc = true;
vsnip = true;
nvim_lsp = true;
nvim_lua = true;
spell = true;
tags = true;
snippets_nvim = true;
treesitter = 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
-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet’s placeholder
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
elseif vim.fn.call("vsnip#available", {1}) == 1 then
return t "<Plug>(vsnip-expand-or-jump)"
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 vim.fn.call("vsnip#jumpable", {-1}) == 1 then
return t "<Plug>(vsnip-jump-prev)"
else
-- If <S-Tab> is not working in your terminal, change it to <C-h>
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})
EOF
lua << EOF
require'lspconfig'.pyright.setup{}
require'lspconfig'.terraformls.setup{}
require'lspconfig'.gopls.setup{}
require'lspconfig'.rust_analyzer.setup{}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment