Skip to content

Instantly share code, notes, and snippets.

@maxlibin
Created April 27, 2022 03:31
Show Gist options
  • Save maxlibin/9728df5b761756297c6f79831761eda9 to your computer and use it in GitHub Desktop.
Save maxlibin/9728df5b761756297c6f79831761eda9 to your computer and use it in GitHub Desktop.
Vim Config
// ~/.config/nvim/init.vim
lua require('init')
lua require('plugins')
call plug#begin('~/.vim/plugged')
Plug 'reasonml-editor/vim-reason-plus'
Plug 'TaDaa/vimade'
Plug 'tpope/vim-fugitive'
Plug 'folke/tokyonight.nvim', { 'branch': 'main' }
Plug 'dracula/vim', { 'as': 'dracula' }
Plug 'kyazdani42/nvim-web-devicons'
Plug 'folke/trouble.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'tpope/vim-surround'
Plug 'mattn/emmet-vim'
Plug 'airblade/vim-gitgutter'
Plug 'maxbrunsfeld/vim-yankstack'
Plug 'drewtempelmeyer/palenight.vim'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'honza/vim-snippets'
Plug 'ryanoasis/vim-devicons'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'voldikss/vim-floaterm'
Plug 'jiangmiao/auto-pairs'
Plug 'sheerun/vim-polyglot'
Plug 'terryma/vim-multiple-cursors'
call plug#end()
" let g:LanguageClient_serverCommands = {
" \ 'reason': ['/Users/max/workspace/rls-macos/reason-language-server']
" \ }
" For Neovim 0.1.3 and 0.1.4 - https://github.com/neovim/neovim/pull/2198
if (has('nvim'))
let $NVIM_TUI_ENABLE_TRUE_COLOR = 1
endif
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
if (has("termguicolors"))
set termguicolors
endif
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" Set up vertical vs block cursor for insert/normal mode
if &term =~ "screen-256color."
let &t_ti.="\eP\e[1 q\e\\"
let &t_SI.="\eP\e[5 q\e\\"
let &t_EI.="\eP\e[1 q\e\\"
let &t_te.="\eP\e[0 q\e\\"
else
let &t_ti.="\<Esc>[1 q"
let &t_SI.="\<Esc>[5 q"
let &t_EI.="\<Esc>[1 q"
let &t_te.="\<Esc>[0 q"
endif
set background=dark
" Load the colorscheme
let g:tokyonight_style = "night"
let g:tokyonight_italic_functions = 1
let g:tokyonight_sidebars = [ "qf", "vista_kind", "terminal", "packer" ]
" Change the "hint" color to the "orange" color, and make the "error" color bright red
let g:tokyonight_colors = {
\ 'hint': 'orange',
\ 'error': '#ff0000'
\ }
colorscheme tokyonight
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
" ------------------------------------------------------------------------------
" Configs for COC plugin
" ------------------------------------------------------------------------------
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
"
" ------------------------------------------------------------------------------
" Keys mapping
" ------------------------------------------------------------------------------
nnoremap <space>e :CocCommand explorer<CR>
" nmap <C-g> :GFiles<CR>
nmap <C-h> :History<CR>
" nmap <C-f> :Rg!
nmap <C-s> :w<CR>
noremap <silent> <C-S-Left> :vertical resize +1<CR>
noremap <silent> <C-S-Right> :vertical resize -1<CR>
nnoremap <silent> <C-z> :FloatermToggle<Enter>
tnoremap <silent> <C-z> <C-\><C-n>:FloatermToggle<CR>
nmap <C-g> :Telescope find_files<CR>
nmap <C-f> :Telescope live_grep<CR>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
imap jj <Esc>
imap kk <Esc>
" " Shift + J/K moves selected lines down/up in visual mode
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" -----------------------------------------------------------------------------
" Formting ReasonML with bsrefmt
augroup reasonml
autocmd!
autocmd FileType reason nmap <silent> == :! yarn bsrefmt --in-place -w 120 %:p <CR> :e! <CR>
augroup END
autocmd InsertEnter, InsertLeave * set cul!
" enable autocomplete
let g:deoplete#enable_at_startup = 1
let g:floaterm_width = 0.8
let g:floaterm_height = 0.8
hi FloatermBorder guifg=cyan
autocmd BufNewFile,BufRead *.atd set syntax=ocaml
// ~/.config/nvim/lua/init.lua
vim.syntax = "enable"
local set = vim.opt
set.tabstop = 2
set.shiftwidth = 2
set.softtabstop = 2
set.colorcolumn = "120"
set.expandtab = true
set.number = true
set.rnu = true
set.wrap = false
set.swapfile = false
set.backup = false
set.smartindent = true
set.undofile = true
set.incsearch = true
set.ignorecase = true
set.lazyredraw = true
set.signcolumn = "yes"
set.cursorline = true
set.cursorcolumn = true
set.mouse = "nc"
set.undodir="~/.vim/undordir"
set.guicursor="i:ver25-iCursor"
set.guifont="Fira Code:h12"
-- set.rtp="/Users/max/workspace/frontend/_opam/share/ocp-indent/vim"
-- TextEdit might fail if hidden is not set.
set.hidden = true
-- Some servers have issues with backup files, see #649.
set.writebackup = false
-- Give more space for displaying messages.
set.cmdheight = 3
-- Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
-- delays and poor user experience.
set.updatetime = 300
require("trouble").setup {}
require'nvim-treesitter.configs'.setup {}
vim.opt.list = true
vim.opt.listchars:append("space:⋅")
vim.opt.listchars:append("eol:↴")
require("indent_blankline").setup {
space_char_blankline = " ",
show_current_context = true,
show_current_context_start = true,
}
// ~/.config/nvim/lua/plugins.lua
return require('packer').startup(function()
-- Packer can manage itself
use 'wbthomason/packer.nvim'
use {
"folke/trouble.nvim",
requires = "kyazdani42/nvim-web-devicons",
config = function()
require("trouble").setup {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
}
end
}
use {
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate'
}
use "lukas-reineke/indent-blankline.nvim"
use {
'nvim-telescope/telescope.nvim',
requires = { {'nvim-lua/plenary.nvim'} }
}
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment