Last active
July 20, 2020 06:25
-
-
Save lovung/917a521457e51cdc7f6b38ebfe84bee5 to your computer and use it in GitHub Desktop.
Example vimrc for Golang and Flutter developer
This file contains 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
call plug#begin('~/.vim/plugged') | |
" Declare the list of plugins. | |
Plug 'tpope/vim-sensible' | |
Plug 'junegunn/seoul256.vim' | |
" code | |
Plug 'pangloss/vim-javascript' | |
" linters | |
Plug 'w0rp/ale' | |
" helpers | |
"Plug 'scrooloose/nerdtree' | |
Plug 'easymotion/vim-easymotion' | |
Plug 'preservim/nerdtree' | |
Plug 'jiangmiao/auto-pairs' | |
Plug 'itchyny/lightline.vim' | |
Plug 'maximbaz/lightline-ale' | |
Plug 'junegunn/goyo.vim' | |
" Plug 'psliwka/vim-smoothie' | |
Plug 'mhinz/vim-startify' | |
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' } | |
Plug 'ekalinin/dockerfile.vim' | |
"git | |
Plug 'airblade/vim-gitgutter' | |
Plug 'itchyny/vim-gitbranch' | |
Plug 'tpope/vim-fugitive' | |
Plug 'junegunn/gv.vim' | |
Plug 'jreybert/vimagit' | |
Plug 'rhysd/git-messenger.vim' | |
"fzf | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | |
Plug 'junegunn/fzf.vim' | |
"coc.vim | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
"theme | |
Plug 'dracula/vim', { 'as': 'dracula' } | |
Plug 'haishanh/night-owl.vim' | |
Plug 'ayu-theme/ayu-vim' | |
Plug 'arcticicestudio/nord-vim' | |
Plug 'patstockwell/vim-monokai-tasty' | |
Plug 'joshdick/onedark.vim' | |
" Plug for flutter | |
Plug 'dart-lang/dart-vim-plugin' | |
Plug 'thosakwe/vim-flutter' | |
Plug 'liuchengxu/vim-clap' | |
Plug 'natebosch/vim-lsc' | |
Plug 'natebosch/vim-lsc-dart' | |
Plug 'wincent/command-t' | |
Plug 'tpope/vim-commentary' | |
Plug 'Xuyuanp/nerdtree-git-plugin' | |
Plug 'yuttie/comfortable-motion.vim' | |
" Golang | |
Plug 'sebdah/vim-delve' | |
Plug 'fatih/vim-go' | |
Plug 'ryanoasis/vim-devicons' | |
Plug 'buoto/gotests-vim' | |
" List ends here. Plugins become visible to Vim after this call. | |
call plug#end() | |
" Global setting | |
syntax on | |
color ayu | |
colorscheme onedark | |
set background=dark | |
set number | |
set relativenumber | |
set encoding=utf-8 | |
set fileencoding=utf-8 | |
set nomodeline | |
set hidden | |
set cmdheight=2 | |
set tabstop=4 | |
set shiftwidth=4 | |
set softtabstop=4 | |
set expandtab | |
set showcmd | |
set cursorline | |
set list | |
set lcs=tab:\|\ " | |
set termguicolors | |
set wildmenu | |
set showmatch | |
set lazyredraw | |
set incsearch | |
set hlsearch | |
" if hidden is not set, TextEdit might fail. | |
set hidden | |
" Some servers have issues with backup files, see #649 | |
set nobackup | |
set nowritebackup | |
" Better display for messages | |
set cmdheight=2 | |
" You will have bad experience for diagnostic messages when it's default 4000. | |
set updatetime=300 | |
" don't give |ins-completion-menu| messages. | |
set shortmess+=c | |
" always show signcolumns | |
set signcolumn=yes | |
filetype plugin on | |
filetype indent on | |
filetype plugin indent on " required | |
let ayucolor="mirage" | |
let g:go_def_mapping_enabled = 0 | |
let g:user_emmet_mode='a' | |
let g:user_emmet_leader_key='<Tab>' | |
let g:user_emmet_settings= { | |
\ 'javascript.jsx' : { | |
\ 'extends': 'jsx', | |
\ }, | |
\} | |
let g:go_auto_sameids = 1 | |
let g:go_highlight_structs = 1 | |
let g:go_highlight_interfaces = 1 | |
let g:go_highlight_methods = 1 | |
let g:go_highlight_functions = 1 | |
let g:go_highlight_operators = 1 | |
let g:go_highlight_build_constraints = 1 | |
let g:go_highlight_extra_types = 1 | |
let g:go_highlight_function_parameters = 1 | |
let g:go_highlight_function_calls = 1 | |
let g:go_highlight_types = 1 | |
let g:go_hightlight_fields = 1 | |
let g:go_highlight_generate_tags = 1 | |
let g:go_highlight_variable_declarations = 1 | |
let g:go_highlight_variable_assignments = 1 | |
let g:go_fmt_command = "goimports" | |
let g:go_def_mode='gopls' | |
let g:go_info_mode='gopls' | |
let g:NERDSpaceDelims = 1 | |
let g:NERDCompactSexyComs = 1 | |
let g:NERDTreeMouseMode=3 | |
let g:go_debug_windows = { | |
\ 'vars': 'rightbelow 60vnew', | |
\ 'stack': 'rightbelow 10new', | |
\ } | |
" Auto cmd | |
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') | |
"NerdTree configurations | |
autocmd StdinReadPre * let s:std_in=1 | |
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif | |
" nerdCommenter | |
" 2 spaces indent for yaml files | |
autocmd FileType yaml,yml setlocal ts=2 sts=2 sw=2 expandtab | |
" json | |
autocmd FileType json syntax match Comment +\/\/.\+$+ | |
"go lang | |
autocmd FileType go nmap <leader>b <Plug>(go-build) | |
autocmd FileType go nmap <leader>r <Plug>(go-run) | |
autocmd FileType dart setlocal ts=2 sts=2 sw=2 expandtab | |
autocmd BufEnter *.cls setlocal filetype=java | |
autocmd BufEnter *.zsh-theme setlocal filetype=zsh | |
autocmd BufEnter Makefile setlocal noexpandtab | |
autocmd BufEnter *.sh setlocal tabstop=2 | |
autocmd BufEnter *.sh setlocal shiftwidth=2 | |
autocmd BufEnter *.sh setlocal softtabstop=2 | |
augroup end | |
""" Specified setting and mapping | |
let mapleader=" " | |
"set guifont=Fira\ Code\ Retina\ 11 | |
nmap <C-e> :e#<CR> | |
nmap ; :Buffers<CR> | |
nnoremap <Leader>ff :Files<Cr> | |
nnoremap <Leader>t :Rg<Cr> | |
" turn off search highlight | |
nnoremap <leader><space> :nohlsearch<CR> | |
"==============COC configurations======================== | |
"==============COC configurations======================== | |
" Use tab for trigger completion with characters ahead and navigate. | |
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin. | |
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. | |
inoremap <silent><expr> <c-space> coc#refresh() | |
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position. | |
" Coc only does snippet and additional edit on confirm. | |
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" | |
" Or use `complete_info` if your vim support it, like: | |
" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" | |
" Remap keys for gotos | |
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) | |
" Highlight symbol under cursor on CursorHold | |
autocmd CursorHold * silent call CocActionAsync('highlight') | |
" Remap for rename current word | |
nmap <leader>rn <Plug>(coc-rename) | |
" Remap for do codeAction of current line | |
nmap <leader>ac <Plug>(coc-codeaction) | |
" Fix autofix problem of current line | |
nmap <leader>qf <Plug>(coc-fix-current) | |
" Create mappings for function text object, requires document symbols feature of languageserver. | |
xmap if <Plug>(coc-funcobj-i) | |
xmap af <Plug>(coc-funcobj-a) | |
omap if <Plug>(coc-funcobj-i) | |
omap af <Plug>(coc-funcobj-a) | |
" Use <TAB> for select selections ranges, needs server support, like: coc-tsserver, coc-python | |
nmap <silent> <TAB> <Plug>(coc-range-select) | |
xmap <silent> <TAB> <Plug>(coc-range-select) | |
" Use `:Format` to format current buffer | |
command! -nargs=0 Format :call CocAction('format') | |
" Use `:Fold` to fold current buffer | |
command! -nargs=? Fold :call CocAction('fold', <f-args>) | |
" use `:OR` for organize import of current buffer | |
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') | |
" Add status line support, for integration with other plugin, checkout `:h coc-status` | |
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} | |
" Using CocList | |
" Show all diagnostics | |
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr> | |
" Manage extensions | |
nnoremap <silent> <space>e :<C-u>CocList extensions<cr> | |
" Show commands | |
nnoremap <silent> <space>c :<C-u>CocList commands<cr> | |
" Find symbol of current document | |
nnoremap <silent> <space>o :<C-u>CocList outline<cr> | |
" Search workspace symbols | |
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr> | |
" Do default action for next item. | |
nnoremap <silent> <space>j :<C-u>CocNext<CR> | |
" Do default action for previous item. | |
nnoremap <silent> <space>k :<C-u>CocPrev<CR> | |
" Resume latest coc list | |
nnoremap <silent> <space>p :<C-u>CocListResume<CR> | |
" Use U to show documentation in preview window | |
nnoremap <silent> U :call <SID>show_documentation()<CR> | |
function! s:show_documentation() | |
if (index(['vim','help'], &filetype) >= 0) | |
execute 'h '.expand('<cword>') | |
else | |
call CocAction('doHover') | |
endif | |
endfunction | |
"==================NERDTree================================== | |
:set mouse=a | |
:nnoremap tt :NERDTreeToggle<CR> | |
:nnoremap tf :NERDTreeFocus<CR> | |
"=================Vim-clap configurations==================== | |
nnoremap <leader>cg :Clap grep<cr> | |
"=================Dart/Flutter configurations================ | |
let g:lsc_server_commands = {'dart': 'dart_language_server'} | |
let g:lsc_auto_map = { | |
\ 'GoToDefinition': 'gD', | |
\ 'GoToDefinitionSplit': ['<C-W>]', '<C-W><C-]>'], | |
\ 'FindReferences': 'gR', | |
\ 'NextReference': 'gnr', | |
\ 'PreviousReference': 'gpr', | |
\ 'FindImplementations': 'gI', | |
\ 'FindCodeActions': 'ga', | |
\ 'Rename': 'grn', | |
\ 'ShowHover': v:true, | |
\ 'DocumentSymbol': 'go', | |
\ 'WorkspaceSymbol': 'gS', | |
\ 'SignatureHelp': 'gm', | |
\ 'Completion': 'completefunc', | |
\} | |
autocmd CompleteDone * silent! pclose | |
" Some of these key choices were arbitrary; | |
" it's just an example. | |
"nnoremap <leader>fa :FlutterRun<cr> | |
"nnoremap <leader>fq :FlutterQuit<cr> | |
"nnoremap <leader>fr :FlutterHotReload<cr> | |
"nnoremap <leader>fR :FlutterHotRestart<cr> | |
"nnoremap <leader>fD :FlutterVisualDebug<cr> | |
call dart#ToggleFormatOnSave() | |
"================= Custom for fast developing================ | |
" For local replace | |
nnoremap fr gd[{V%::s/<C-R>///gc<left><left><left> | |
" For global replace | |
nnoremap fR gD:%s/<C-R>///gc<left><left><left> | |
" For insert 1 character | |
nnoremap <Space> i_<Esc>r | |
" move vertically by visual line | |
nnoremap j gj | |
nnoremap k gk | |
" move to beginning/end of line | |
nnoremap B ^ | |
nnoremap E $ | |
" $/^ doesn't do anything | |
nnoremap $ <nop> | |
nnoremap ^ <nop> | |
" highlight last inserted text | |
nnoremap gV `[v`] | |
" jk is escape | |
inoremap jk <esc> | |
" 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> | |
" save session | |
nnoremap <leader>s :mksession<CR> | |
" Split navigations | |
"nnoremap <C-J> <C-W><C-J> | |
"nnoremap <C-K> <C-W><C-K> | |
nnoremap <C-L> <C-W><C-L> | |
nnoremap <C-H> <C-W><C-H> | |
" Replace the whore word with clipboard | |
nnoremap <leader>raw "_dawhp | |
inoremap <C-f> <Right> | |
inoremap <C-b> <Left> | |
" Switch to previous file | |
nmap <C-e> :e#<CR> | |
" Vim easymotion | |
nmap <leader>g <Plug>(easymotion-overwin-f) | |
nmap <leader>l <Plug>(easymotion-overwin-line) | |
" Remap the hjkl | |
nnoremap L l | |
nnoremap H h | |
nnoremap l w | |
nnoremap h b | |
" Resize split window | |
nnoremap <silent> + :exe "vertical resize +5"<CR> | |
nnoremap <silent> _ :exe "vertical resize -5"<CR> | |
" Open terminal | |
nnoremap <Leader>at :call FloatTerm()<CR> | |
" Open tig, yes TIG, A FLOATING TIGGGG!!!!!! | |
nnoremap <Leader>ag :call FloatTerm('"tig"')<CR> | |
" Floating Term | |
let s:float_term_border_win = 0 | |
let s:float_term_win = 0 | |
function! FloatTerm(...) | |
" Configuration | |
let height = float2nr((&lines - 2) * 0.6) | |
let row = float2nr((&lines - height) / 2) | |
let width = float2nr(&columns * 0.6) | |
let col = float2nr((&columns - width) / 2) | |
" Border Window | |
let border_opts = { | |
\ 'relative': 'editor', | |
\ 'row': row - 1, | |
\ 'col': col - 2, | |
\ 'width': width + 4, | |
\ 'height': height + 2, | |
\ 'style': 'minimal' | |
\ } | |
" Terminal Window | |
let opts = { | |
\ 'relative': 'editor', | |
\ 'row': row, | |
\ 'col': col, | |
\ 'width': width, | |
\ 'height': height, | |
\ 'style': 'minimal' | |
\ } | |
let top = "╭" . repeat("─", width + 2) . "╮" | |
let mid = "│" . repeat(" ", width + 2) . "│" | |
let bot = "╰" . repeat("─", width + 2) . "╯" | |
let lines = [top] + repeat([mid], height) + [bot] | |
let bbuf = nvim_create_buf(v:false, v:true) | |
call nvim_buf_set_lines(bbuf, 0, -1, v:true, lines) | |
let s:float_term_border_win = nvim_open_win(bbuf, v:true, border_opts) | |
let buf = nvim_create_buf(v:false, v:true) | |
let s:float_term_win = nvim_open_win(buf, v:true, opts) | |
" Styling | |
hi FloatWinBorder guifg=#87bb7c | |
call setwinvar(s:float_term_border_win, '&winhl', 'Normal:FloatWinBorder') | |
call setwinvar(s:float_term_win, '&winhl', 'Normal:Normal') | |
if a:0 == 0 | |
terminal | |
else | |
call termopen(a:1) | |
endif | |
startinsert | |
" Close border window when terminal window close | |
autocmd TermClose * ++once :bd! | call nvim_win_close(s:float_term_border_win, v:true) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment