Last active
July 20, 2021 15:27
-
-
Save lovung/ac5c96e0ffdb15c036d62189f4f3cfb5 to your computer and use it in GitHub Desktop.
New init.vim generate from https://vim-bootstrap.com/ with customization
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-bootstrap | |
"***************************************************************************** | |
"" Vim-Plug core | |
"***************************************************************************** | |
let vimplug_exists=expand('~/.config/nvim/autoload/plug.vim') | |
if has('win32')&&!has('win64') | |
let curl_exists=expand('C:\Windows\Sysnative\curl.exe') | |
else | |
let curl_exists=expand('curl') | |
endif | |
let g:vim_bootstrap_langs = "go" | |
let g:vim_bootstrap_editor = "neovim" " nvim or vim | |
if !filereadable(vimplug_exists) | |
if !executable(curl_exists) | |
echoerr "You have to install curl or first install vim-plug yourself!" | |
execute "q!" | |
endif | |
echo "Installing Vim-Plug..." | |
echo "" | |
silent exec "!"curl_exists" -fLo " . shellescape(vimplug_exists) . " --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" | |
let g:not_finish_vimplug = "yes" | |
autocmd VimEnter * PlugInstall | |
endif | |
" Required: | |
call plug#begin(expand('~/.config/nvim/plugged')) | |
"***************************************************************************** | |
"" Plug install packages | |
"***************************************************************************** | |
Plug 'scrooloose/nerdtree' | |
Plug 'tpope/vim-commentary' | |
Plug 'tpope/vim-fugitive' | |
Plug 'vim-airline/vim-airline' | |
Plug 'vim-airline/vim-airline-themes' | |
Plug 'airblade/vim-gitgutter' | |
Plug 'vim-scripts/grep.vim' | |
Plug 'vim-scripts/CSApprox' | |
Plug 'Raimondi/delimitMate' | |
Plug 'majutsushi/tagbar' | |
Plug 'dense-analysis/ale' | |
Plug 'Yggdroot/indentLine' | |
Plug 'editor-bootstrap/vim-bootstrap-updater' | |
Plug 'sheerun/vim-polyglot' | |
Plug 'tpope/vim-rhubarb' " required by fugitive to :Gbrowse | |
Plug 'Mizux/vim-colorschemes' | |
Plug 'yuttie/comfortable-motion.vim' | |
Plug 'mg979/vim-visual-multi', {'branch': 'master'} | |
if isdirectory('/usr/local/opt/fzf') | |
Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim' | |
else | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' } | |
Plug 'junegunn/fzf.vim' | |
endif | |
let g:make = 'gmake' | |
if exists('make') | |
let g:make = 'make' | |
endif | |
Plug 'Shougo/vimproc.vim', {'do': g:make} | |
"" Vim-Session | |
Plug 'xolox/vim-misc' | |
Plug 'xolox/vim-session' | |
"" Snippets | |
Plug 'SirVer/ultisnips' | |
Plug 'honza/vim-snippets' | |
Plug 'hrsh7th/vim-vsnip' | |
Plug 'hrsh7th/vim-vsnip-integ' | |
"" Color | |
Plug 'tomasr/molokai' | |
Plug 'dracula/vim', { 'as': 'dracula' } | |
Plug 'ayu-theme/ayu-vim' | |
Plug 'morhetz/gruvbox' | |
Plug 'liuchengxu/space-vim-dark' | |
" FloatTerm | |
Plug 'voldikss/vim-floaterm' | |
"***************************************************************************** | |
"" Custom bundles | |
"***************************************************************************** | |
Plug 'puremourning/vimspector' | |
Plug 'neovim/nvim-lspconfig' | |
Plug 'hrsh7th/nvim-compe' | |
" go | |
"" Go Lang Bundle | |
Plug 'fatih/vim-go', {'do': ':GoInstallBinaries'} | |
Plug 'sebdah/vim-delve' | |
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " We recommend updating the parsers on update | |
Plug 'wakatime/vim-wakatime' | |
"***************************************************************************** | |
"***************************************************************************** | |
"" Include user's extra bundle | |
if filereadable(expand("~/.config/nvim/local_bundles.vim")) | |
source ~/.config/nvim/local_bundles.vim | |
endif | |
call plug#end() | |
" Required: | |
filetype plugin indent on | |
"***************************************************************************** | |
"" Basic Setup | |
"*****************************************************************************" | |
" Theme | |
set background=dark | |
color gruvbox | |
colorscheme gruvbox | |
let ayucolor="mirage" | |
"" Encoding | |
set encoding=utf-8 | |
set fileencoding=utf-8 | |
set fileencodings=utf-8 | |
set ttyfast | |
"" Fix backspace indent | |
set backspace=indent,eol,start | |
"" Tabs. May be overridden by autocmd rules | |
set tabstop=4 | |
set softtabstop=0 | |
set shiftwidth=4 | |
set expandtab | |
"" Map leader to , | |
let mapleader=',' | |
"" Enable hidden buffers | |
set hidden | |
"" Searching | |
set hlsearch | |
set incsearch | |
set ignorecase | |
set smartcase | |
set fileformats=unix,dos,mac | |
if exists('$SHELL') | |
set shell=$SHELL | |
else | |
set shell=/bin/sh | |
endif | |
" session management | |
let g:session_directory = "~/.config/nvim/session" | |
let g:session_autoload = "no" | |
let g:session_autosave = "no" | |
let g:session_command_aliases = 1 | |
" Other | |
set showcmd | |
set signcolumn=yes | |
" You will have bad experience for diagnostic messages when it's default 4000. | |
set updatetime=100 | |
" don't give |ins-completion-menu| messages. | |
set shortmess+=c | |
set wildmenu | |
set wildmode=longest:full,full | |
set showmatch | |
set lazyredraw | |
set wildoptions=pum | |
set pumblend=50 | |
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite | |
set wildignore+=*.o,*.obj,.git,*.rbc,*.pyc,__pycache__ | |
set lcs=tab:\|\ " | |
set cursorline | |
hi Cursor guifg=green guibg=green | |
hi Cursor2 guifg=red guibg=red | |
set guicursor=n-v-c:block-Cursor/lCursor,i-ci-ve:ver25-Cursor2/lCursor2,r-cr:hor20,o:hor50 | |
" code folding | |
set foldlevel=99 | |
set foldmethod=expr | |
set foldexpr=nvim_treesitter#foldexpr() | |
nmap <leader>fc :foldclose<CR> | |
nmap <leader>fo :foldopen<CR> | |
nmap <leader>fa :set foldlevel=99<CR> | |
nmap <leader>fl :set foldlevel=0<CR> | |
"***************************************************************************** | |
"" Visual Settings | |
"***************************************************************************** | |
" Some Linux distributions set filetype in /etc/vimrc. | |
" Clear filetype flags before changing runtimepath to force Vim to reload them. | |
filetype off | |
filetype plugin indent off | |
set runtimepath+=$GOROOT/misc/vim | |
filetype plugin indent on | |
syntax on | |
set ruler | |
set number | |
set relativenumber | |
let no_buffers_menu=1 | |
" silent! colorscheme space-vim-dark | |
hi Comment cterm=italic | |
set mousemodel=popup | |
set t_Co=256 | |
set guioptions=egmrti | |
set gfn=Monospace\ 10 | |
if has("gui_running") | |
if has("gui_mac") || has("gui_macvim") | |
set guifont=Menlo:h12 | |
set transparency=7 | |
endif | |
else | |
let g:CSApprox_loaded = 1 | |
" IndentLine | |
let g:indentLine_enabled = 1 | |
let g:indentLine_concealcursor = 0 | |
let g:indentLine_char = '┆' | |
let g:indentLine_faster = 1 | |
if $COLORTERM == 'gnome-terminal' | |
set term=gnome-256color | |
else | |
if $TERM == 'xterm' | |
set term=xterm-256color | |
endif | |
endif | |
endif | |
if &term =~ '256color' | |
set t_ut= | |
endif | |
"" Disable the blinking cursor. | |
set gcr=a:blinkon0 | |
set scrolloff=3 | |
"" Status bar | |
set laststatus=2 | |
"" Use modeline overrides | |
set modeline | |
set modelines=10 | |
set title | |
set titleold="Terminal" | |
set titlestring=%F | |
set statusline=%F%m%r%h%w%=(%{&ff}/%Y)\ (line\ %l\/%L,\ col\ %c)\ | |
" Search mappings: These will make it so that going to the next one in a | |
" search will center on the line it's found in. | |
nnoremap n nzzzv | |
nnoremap N Nzzzv | |
if exists("*fugitive#statusline") | |
set statusline+=%{fugitive#statusline()} | |
endif | |
"***************************************************************************** | |
"" Abbreviations | |
"***************************************************************************** | |
"" no one is really happy until you have this shortcuts | |
cnoreabbrev W! w! | |
cnoreabbrev Q! q! | |
cnoreabbrev Qall! qall! | |
cnoreabbrev Wq wq | |
cnoreabbrev Wa wa | |
cnoreabbrev wQ wq | |
cnoreabbrev WQ wq | |
cnoreabbrev W w | |
cnoreabbrev Q q | |
cnoreabbrev Qall qall | |
"" NERDTree configuration | |
let g:NERDTreeChDirMode=2 | |
let g:NERDTreeIgnore=['\.rbc$', '\~$', '\.pyc$', '\.db$', '\.sqlite$', '__pycache__'] | |
let g:NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$'] | |
let g:NERDTreeShowBookmarks=1 | |
let g:nerdtree_tabs_focus_on_files=1 | |
let g:NERDTreeMapOpenInTabSilent = '<RightMouse>' | |
let g:NERDTreeWinSize = 50 | |
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite | |
nnoremap tt :NERDTreeToggle<CR> | |
nnoremap tf :NERDTreeFocus<CR> | |
nnoremap nf :NERDTreeFind<CR> | |
" grep.vim | |
nnoremap <silent> <leader>fr :Rgrep<CR> | |
let Grep_Default_Options = '-IR' | |
let Grep_Skip_Files = '*.log *.db' | |
let Grep_Skip_Dirs = '.git node_modules' | |
" terminal emulation | |
nnoremap <silent> <leader>sh :terminal<CR> | |
"***************************************************************************** | |
"" Commands | |
"***************************************************************************** | |
" remove trailing whitespaces | |
command! FixWhitespace :%s/\s\+$//e | |
"***************************************************************************** | |
"" Functions | |
"***************************************************************************** | |
if !exists('*s:setupWrapping') | |
function s:setupWrapping() | |
set wrap | |
set wm=2 | |
set textwidth=79 | |
endfunction | |
endif | |
"***************************************************************************** | |
"" Autocmd Rules | |
"***************************************************************************** | |
"" The PC is fast enough, do syntax highlight syncing from start unless 200 lines | |
augroup vimrc-sync-fromstart | |
autocmd! | |
autocmd BufEnter * :syntax sync maxlines=200 | |
augroup END | |
"" Remember cursor position | |
augroup vimrc-remember-cursor-position | |
autocmd! | |
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif | |
augroup END | |
"" txt | |
augroup vimrc-wrapping | |
autocmd! | |
autocmd BufRead,BufNewFile *.txt call s:setupWrapping() | |
augroup END | |
"" make/cmake | |
augroup vimrc-make-cmake | |
autocmd! | |
autocmd FileType make setlocal noexpandtab | |
autocmd BufNewFile,BufRead CMakeLists.txt setlocal filetype=cmake | |
augroup END | |
" proto | |
augroup filetype | |
au! BufRead,BufNewFile *.proto setfiletype proto | |
augroup end | |
set autoread | |
"***************************************************************************** | |
"" Mappings | |
"***************************************************************************** | |
"" Split | |
noremap <Leader>h :<C-u>split<CR> | |
noremap <Leader>v :<C-u>vsplit<CR> | |
"" Git | |
noremap <Leader>ga :Gwrite<CR> | |
noremap <Leader>gc :Git commit --verbose<CR> | |
noremap <Leader>gsh :Gpush<CR> | |
noremap <Leader>gll :Gpull<CR> | |
noremap <Leader>gs :Gstatus<CR> | |
noremap <Leader>gb :Gblame<CR> | |
noremap <Leader>gd :Gvdiff<CR> | |
noremap <Leader>gr :Gremove<CR> | |
" session management | |
nnoremap <leader>so :OpenSession<Space> | |
nnoremap <leader>ss :SaveSession<Space> | |
nnoremap <leader>sd :DeleteSession<CR> | |
nnoremap <leader>sc :CloseSession<CR> | |
"" Tabs | |
" nnoremap <Tab> gt | |
" nnoremap <S-Tab> gT | |
nnoremap <silent> <S-t> :tabnew<CR> | |
"" Set working directory | |
nnoremap <leader>. :lcd %:p:h<CR> | |
"" Opens an edit command with the path of the currently edited file filled in | |
noremap <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR> | |
"" Opens a tab edit command with the path of the currently edited file filled | |
noremap <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR> | |
"" fzf.vim | |
set wildmode=list:longest,list:full | |
set wildignore+=*.o,*.obj,.git,*.rbc,*.pyc,__pycache__ | |
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.9 } } | |
let $FZF_DEFAULT_COMMAND = "find * -path '*/\.*' -prune -o -path 'node_modules/**' -prune -o -path 'target/**' -prune -o -path 'dist/**' -prune -o -type f -print -o -type l -print 2> /dev/null" | |
let $FZF_DEFAULT_OPTS="--ansi --preview-window 'right:80%' --layout reverse --margin=1,4 --preview 'bat --theme=gruvbox --color=always --style=header,grid --line-range :300 {}'" | |
command! -bang -nargs=* RG | |
\ call fzf#vim#grep( | |
\ 'rg --column --line-number --no-heading --color=always --smart-case -g "!{.git/node_modules}/*" -- '.shellescape(<q-args>), 1, | |
\ fzf#vim#with_preview(), <bang>0) | |
nnoremap <leader>fv :RG<Cr> | |
" The Silver Searcher | |
if executable('ag') | |
let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git -g ""' | |
set grepprg=ag\ --nogroup\ --nocolor | |
endif | |
" ripgrep | |
if executable('rg') | |
let $FZF_DEFAULT_COMMAND = 'rg --files --hidden --follow --glob "!{.git,node_modules}/*"' | |
set grepprg=rg\ --vimgrep | |
command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>).'| tr -d "\017"', 1, <bang>0) | |
endif | |
cnoremap <C-P> <C-R>=expand("%:p:h") . "/" <CR> | |
nmap <C-e> :e#<CR> | |
nnoremap <silent> <leader>b :Buffers<CR> | |
nnoremap <silent> <leader>ee :FZF -m<CR> | |
"Recovery commands from history through FZF | |
nmap <leader>y :History:<CR> | |
" " snippets | |
let g:UltiSnipsExpandTrigger="<tab>" | |
let g:UltiSnipsJumpForwardTrigger="<tab>" | |
let g:UltiSnipsJumpBackwardTrigger="<c-b>" | |
let g:UltiSnipsEditSplit="vertical" | |
" ale | |
let g:ale_linters = {} | |
" Tagbar | |
nmap <silent> <F4> :TagbarToggle<CR> | |
let g:tagbar_autofocus = 1 | |
" Disable visualbell | |
set noerrorbells visualbell t_vb= | |
if has('autocmd') | |
autocmd GUIEnter * set visualbell t_vb= | |
endif | |
"" Copy/Paste/Cut | |
if has('unnamedplus') | |
set clipboard=unnamed,unnamedplus | |
endif | |
noremap YY "+y<CR> | |
noremap <leader>p "+gP<CR> | |
noremap XX "+x<CR> | |
if has('macunix') | |
" pbcopy for OSX copy/paste | |
vmap <C-x> :!pbcopy<CR> | |
vmap <C-c> :w !pbcopy<CR><CR> | |
endif | |
"" Buffer nav | |
noremap <leader>z :bp<CR> | |
noremap <leader>q :bp<CR> | |
noremap <leader>x :bn<CR> | |
noremap <leader>w :bn<CR> | |
"" Close buffer | |
noremap <leader>c :bd<CR> | |
"" Clean search (highlight) | |
nnoremap <silent> <ESC><ESC> :noh<cr> | |
"" Switching windows | |
noremap <C-j> <C-w>j | |
noremap <C-k> <C-w>k | |
noremap <C-l> <C-w>l | |
noremap <C-h> <C-w>h | |
"" Vmap for maintain Visual Mode after shifting > and < | |
vmap < <gv | |
vmap > >gv | |
"" Move visual block | |
vnoremap J :m '>+1<CR>gv=gv | |
vnoremap K :m '<-2<CR>gv=gv | |
"" Open current line on GitHub | |
nnoremap <Leader>o :.Gbrowse<CR> | |
"***************************************************************************** | |
"" Custom configs | |
"***************************************************************************** | |
" Moving | |
" move to beginning/end of line | |
nnoremap B ^ | |
nnoremap E $ | |
" Remap the hjkl | |
nnoremap L l | |
nnoremap H h | |
nnoremap l w | |
nnoremap h b | |
" jk is escape | |
inoremap jk <esc> | |
inoremap :w<CR> <ESC>:w<CR> | |
inoremap :q<CR> <ESC>:q<CR> | |
inoremap <C-l> <Right> | |
inoremap <C-h> <Left> | |
" Save | |
nnoremap <D-s> :w<CR> | |
" Windows | |
" Resize split window | |
nnoremap <silent> + :exe "vertical resize +5"<CR> | |
nnoremap <silent> _ :exe "vertical resize -5"<CR> | |
nnoremap <silent> = :exe "resize +5"<CR> | |
nnoremap <silent> - :exe "resize -5"<CR> | |
" Remap paste | |
vnoremap p "_dP | |
" edit vimrc/zshrc and load vimrc bindings | |
nnoremap <leader>ev :vsp $MYVIMRC<CR> | |
nnoremap <leader>ez :vsp ~/.zshrc<CR> | |
nnoremap <leader>sv :source $MYVIMRC<CR> | |
" go | |
" vim-go | |
" run :GoBuild or :GoTestCompile based on the go file | |
" function! s:build_go_files() | |
" let l:file = expand('%') | |
" if l:file =~# '^\f\+_test\.go$' | |
" call go#test#Test(0, 1) | |
" elseif l:file =~# '^\f\+\.go$' | |
" call go#cmd#Build(0) | |
" endif | |
" endfunction | |
let g:go_list_type = "quickfix" | |
let g:go_fmt_command = "goimports" | |
let g:go_fmt_fail_silently = 1 | |
let g:go_highlight_types = 1 | |
let g:go_highlight_fields = 1 | |
let g:go_highlight_functions = 1 | |
let g:go_highlight_function_calls = 1 | |
let g:go_highlight_function_parameters = 1 | |
let g:go_highlight_methods = 1 | |
let g:go_highlight_format_strings = 1 | |
let g:go_highlight_operators = 1 | |
let g:go_highlight_diagnostic_warnings = 1 | |
let g:go_highlight_variable_assignments = 1 | |
let g:go_highlight_variable_declarations = 1 | |
let g:go_highlight_build_constraints = 1 | |
let g:go_highlight_structs = 1 | |
let g:go_highlight_generate_tags = 1 | |
let g:go_highlight_space_tab_error = 0 | |
let g:go_highlight_array_whitespace_error = 0 | |
let g:go_highlight_trailing_whitespace_error = 0 | |
let g:go_highlight_extra_types = 1 | |
let g:go_fmt_command = "goimports" | |
let g:go_def_mode='gopls' | |
let g:go_info_mode='gopls' | |
let g:go_metalinter_autosave_enabled = ['vet', 'golint', 'test'] | |
let g:go_debug_windows = { | |
\ 'vars': 'rightbelow 60vnew', | |
\ 'stack': 'rightbelow 10new', | |
\ } | |
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 | |
" Auto-format *.go (golang) files prior to saving them | |
autocmd BufWritePre *.go lua vim.lsp.buf.formatting_sync(nil, 300) | |
augroup go | |
au! | |
au Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit') | |
au Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit') | |
au Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split') | |
au Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe') | |
au FileType go nmap <leader>gr <Plug>(go-run) | |
au FileType go nmap <leader>gt <Plug>(go-test) | |
au FileType go nmap <Leader>gc <Plug>(go-coverage-toggle) | |
au FileType go nmap <Leader>gi <Plug>(go-info) | |
" au FileType go nmap <leader>rb :<C-u>call <SID>build_go_files()<CR> | |
augroup END | |
" Auto build and run unit test | |
" augroup auto_go | |
" autocmd! | |
" autocmd BufWritePost *.go :GoBuild | |
" autocmd BufWritePost *_test.go :GoTest | |
" augroup end | |
" Auto build and run unit test | |
augroup auto_json | |
autocmd! | |
autocmd BufWritePost *.json :%!python -m json.tool | |
augroup end | |
au BufRead,BufNewFile *.go set filetype=go | |
" ale | |
:call extend(g:ale_linters, { | |
\"go": ['golint', 'go vet'], }) | |
" Vimspector configurations | |
nnoremap <F1> :call vimspector#Launch()<CR> | |
nnoremap <leader>dl :call vimspector#Launch()<CR> | |
nnoremap <F5> :call vimspector#Continue()<CR> | |
nnoremap <leader>dc :call vimspector#Continue()<CR> | |
nnoremap <F2> :call vimspector#Reset()<CR> | |
nnoremap <leader>dq :call vimspector#Reset()<CR> | |
nnoremap <F3> :call vimspector#Stop()<CR> | |
nnoremap <leader>ds :call vimspector#Stop()<CR> | |
nnoremap <F4> :call vimspector#Restart()<CR> | |
nnoremap <leader>dr :call vimspector#Restart()<CR> | |
nnoremap <F6> :call vimspector#Pause()<CR> | |
nnoremap <F9> :call vimspector#ToggleBreakpoint()<CR> | |
nnoremap <leader>dp :call vimspector#ToggleBreakpoint()<CR> | |
nnoremap <F10> :call vimspector#StepOver()<CR> | |
nnoremap <leader>dn :call vimspector#StepOver()<CR> | |
nnoremap <F11> :call vimspector#StepInto()<CR> | |
nnoremap <leader>di :call vimspector#StepInto()<CR> | |
nnoremap <F12> :call vimspector#StepOut()<CR> | |
nnoremap <leader>do :call vimspector#StepOut()<CR> | |
"***************************************************************************** | |
"***************************************************************************** | |
"" Include user's local vim config | |
if filereadable(expand("~/.config/nvim/local_init.vim")) | |
source ~/.config/nvim/local_init.vim | |
endif | |
"***************************************************************************** | |
"" Convenience variables | |
"***************************************************************************** | |
"==============Completion Configuration=============================== | |
let g:compe = {} | |
let g:compe.enabled = v:true | |
let g:compe.autocomplete = v:true | |
let g:compe.debug = v:false | |
let g:compe.min_length = 1 | |
let g:compe.preselect = 'enable' | |
let g:compe.throttle_time = 80 | |
let g:compe.source_timeout = 200 | |
let g:compe.resolve_timeout = 800 | |
let g:compe.incomplete_delay = 400 | |
let g:compe.max_abbr_width = 100 | |
let g:compe.max_kind_width = 100 | |
let g:compe.max_menu_width = 100 | |
let g:compe.documentation = v:true | |
let g:compe.source = {} | |
let g:compe.source.path = v:true | |
let g:compe.source.buffer = v:true | |
let g:compe.source.calc = v:true | |
let g:compe.source.nvim_lsp = v:true | |
let g:compe.source.nvim_lua = v:true | |
let g:compe.source.vsnip = v:true | |
let g:compe.source.ultisnips = v:true | |
let g:compe.source.luasnip = v:true | |
let g:compe.source.emoji = v:true | |
" Set completeopt to have a better completion experience | |
set completeopt=menuone,noinsert,noselect | |
highlight link CompeDocumentation NormalFloat | |
inoremap <silent><expr> <C-Space> compe#complete() | |
inoremap <silent><expr> <CR> compe#confirm('<CR>') | |
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 }) | |
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 }) | |
inoremap <silent><expr> <Tab> compe#confirm() | |
lua << EOF | |
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 | |
return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil | |
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['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['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 | |
"==============LSP Configuration=============================== | |
lua << EOF | |
local nvim_lsp = require('lspconfig') | |
-- Use an on_attach function to only map the following keys | |
-- after the language server attaches to the current buffer | |
local on_attach = function(client, bufnr) | |
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end | |
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end | |
--Enable completion triggered by <c-x><c-o> | |
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | |
-- Mappings. | |
local opts = { noremap=true, silent=true } | |
-- See `:help vim.lsp.*` for documentation on any of the below functions | |
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts) | |
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts) | |
buf_set_keymap('n', '<leader>doc', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts) | |
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) | |
buf_set_keymap('n', '<leader>help', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | |
-- buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) | |
-- buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) | |
-- buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) | |
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | |
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | |
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | |
buf_set_keymap('n', '<leader>td', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) | |
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) | |
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) | |
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | |
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | |
end | |
-- Use a loop to conveniently call 'setup' on multiple servers and | |
-- map buffer local keybindings when the language server attaches | |
local servers = { "pyright", "gopls", "tsserver" } | |
for _, lsp in ipairs(servers) do | |
nvim_lsp[lsp].setup { | |
on_attach = on_attach, | |
flags = { | |
debounce_text_changes = 150, | |
} | |
} | |
end | |
EOF | |
"==============FloatTerm configurations======================== | |
" FloatTerm | |
nnoremap <silent> <Leader>tn :FloatermNew<CR> | |
tnoremap <silent> <Leader>tn <C-\><C-n>:FloatermNew<CR> | |
nnoremap <silent> <Leader>tq :FloatermKill<CR> | |
tnoremap <silent> <Leader>tq <C-\><C-n>:FloatermKill<CR> | |
nnoremap <silent> <Leader>tt :FloatermToggle<CR> | |
tnoremap <silent> <Leader>tt <C-\><C-n>:FloatermToggle<CR> | |
nnoremap <silent> <Leader>ff :FloatermNew fzf<CR> | |
tnoremap <silent> <Leader>ff <C-\><C-n>:FloatermNew fzf<CR> | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Find Nearest | |
" Source: http://vim.1045645.n5.nabble.com/find-closest-occurrence-in-both-directions-td1183340.html | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
function! FindNearest(pattern) | |
let @/=a:pattern | |
let b:prev = search(a:pattern, 'bncW') | |
if b:prev | |
let b:next = search(a:pattern, 'ncW') | |
if b:next | |
let b:cur = line('.') | |
if b:cur - b:prev == b:next - b:cur | |
" on a match | |
elseif b:cur - b:prev < b:next - b:cur | |
? | |
else | |
/ | |
endif | |
else | |
? | |
endif | |
else | |
/ | |
endif | |
endfunction | |
function! FindAbove(pattern) | |
let @/=a:pattern | |
let b:prev = search(a:pattern, 'bncW') | |
if b:prev | |
? | |
else | |
/ | |
endif | |
endfunction | |
command! -nargs=1 FA call FindAbove(<q-args>) | |
nmap \ :FA<space> | |
""" Select between conflict blocks | |
" select ours | |
nmap <leader>so \<<<<<<<<CR>dd/=======<CR>V/>>>>>>><CR>d<ESC> | |
" select theirs | |
nmap <leader>st \<<<<<<<<CR>V/=======<CR>d/>>>>>>><CR>dd<ESC> | |
" select both | |
nmap <leader>sb /<<<<<<<<CR>dd/=======<CR>dd/>>>>>>><CR>dd<ESC> | |
" find next conflict | |
nmap <leader>nc /<<<<<<<<CR> | |
lua <<EOF | |
require'nvim-treesitter.configs'.setup { | |
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages | |
ignore_install = { "javascript" }, -- List of parsers to ignore installing | |
highlight = { | |
enable = true, -- false will disable the whole extension | |
-- disable = { "c", "rust" }, -- list of language that will be disabled | |
}, | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment