Skip to content

Instantly share code, notes, and snippets.

@pwang2
Last active August 12, 2024 19:33
Show Gist options
  • Save pwang2/33797ca5e8eec8c4ac32c79c05b9b499 to your computer and use it in GitHub Desktop.
Save pwang2/33797ca5e8eec8c4ac32c79c05b9b499 to your computer and use it in GitHub Desktop.
init-prev.vim - vimscript config
" vim: foldmethod=marker:foldmarker={{{,}}}:foldlevelstart=0:foldclose=all:
set title
set wrap
set splitright
set expandtab
set splitbelow
set number
set relativenumber
set termguicolors
set nofoldenable
set shell =zsh
set mouse =a
set ts =2
set sw =2
set laststatus =3
set timeoutlen =300
set synmaxcol =200
set ttimeoutlen =0
set background =light
set updatetime =500
set wildignore +=node_modules/**,.git/**,dist/**
"{{{ nvim only
" if has("clipboard")
" set clipboard +=unnamedplus
" endif
if has('nvim')
function! CFoldText()
let line = getline(v:foldstart)
let sub = substitute(line, '.*\<\(\w\+\)(.*).*', '\1(...)', 'g')
return '' . sub . '  ' . (v:foldend - v:foldstart + 1)
endfunction
set signcolumn =auto:2
set foldcolumn =0
set foldmethod =expr
set foldexpr =nvim_treesitter#foldexpr()
set foldtext =CFoldText()
set foldnestmax =3
set foldminlines=1
set fillchars +=eob:\ "remove tilde
set fillchars +=fold:\ "remove
set fillchars +=foldclose:\
set fillchars +=foldopen:\
endif
"}}}
"{{{ variables
if exists("$TMUX")
let &t_SI = "\<Esc>Ptmux;\<Esc>\e[5 q\<Esc>\\"
let &t_SR = "\<Esc>Ptmux;\<Esc>\e[4 q\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\e[1 q\<Esc>\\"
else
let &t_SI = "\e[5 q"
let &t_SR = "\e[4 q"
let &t_EI = "\e[1 q"
endif
let g:loaded_ruby_provider = 0
let g:loaded_perl_provider = 0
let g:loaded_node_provider = 0
let mapleader = ' '
let maplocalleader = ';'
let g:mapleader = ' '
let g:maplocalleader = ';'
let g:ale_sign_error = '>>'
let g:ale_sign_warning = '--'
let g:ale_linters = {
\ 'json': ['prettier', 'jq'],
\ 'javascript': ['eslint'],
\ 'typescript': ['eslint'],
\ 'vue': ['eslint'],
\ 'tex': ['texlab'],
\ 'rust': ['rust_analyzer'],
\}
let g:ale_linters_explicit = 1
let g:ale_echo_msg_format = '[%linter%]: %s'
let g:ale_cursor_detail = 0
let g:ale_floating_preview = 0
let g:ale_floating_window_border = ['│', '─', '╭', '╮', '╯', '╰']
let g:ale_javascript_eslint_executable = "eslint_d"
let g:ale_javascript_eslint_use_global = 1
let g:ale_r_lintr_options =<< trim END
with_defaults(
object_usage_linter=NULL,
commented_code_linter=NULL,
camel_case_linter=NULL,
object_name_linter=NULL,
line_length_linter(200))
END
let g:ale_completion_enabled = 0
if $THIS_MACHINE_SUCKS == 1
let g:ale_floating_preview = 0
" enable this will cause performance issue on slow machine
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_enter = 0
endif
let g:neoformat_enabled_vue = ['eslint_d']
let g:neoformat_html_prettier = {'exe': 'prettier', 'args': ['--parser', 'html', '--print-width', '160'], 'stdin': 1}
let g:neoformat_vue_eslint_d = {'exe': 'eslint_d', 'args': ['--stdin', '--fix-to-stdout', '--stdin-filename', '%:p'], 'stdin': 1}
let g:goyo_width = 120
let g:goyo_height = 120
let g:limelight_conceal_guifg = '#777777'
let g:UltiSnipsJumpForwardTrigger = '<Plug>(ultisnips_jump_forward)'
let g:UltiSnipsJumpBackwardTrigger = '<Plug>(ultisnips_jump_backward)'
let g:UltiSnipsListSnippets = '<c-x><c-s>'
" let g:UltiSnipsExpandTrigger = '<Plug>(ultisnips_expand)'
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsRemoveSelectModeMappings = 0
let R_assign_map = '<M-->'
let g:vimspector_enable_mappings = 'VISUAL_STUDIO'
let g:tex_flavor = 'latex'
let g:vimtex_view_method ='zathura'
let g:vimtex_view_method = 'general'
let g:vimtex_quickfix_mode = 0
let g:tex_conceal = 'abdmg'
let g:magma_image_provider = "kitty"
let g:mkdp_browserfunc = 'OpenMarkdownPreview'
" }}}
"{{{ functions
function! UpdateRemotePlugins(...)
let &rtp=&rtp
UpdateRemotePlugins
endfunction
function! s:wilder_init() abort
let l:accent = wilder#make_hl('WilderAccent', 'Pmenu', [{}, {'foreground': 198, 'background': 'NONE', 'bold': 0}, {'foreground': '#ff4303'}])
call wilder#setup({'modes': [':', '/', '?']})
call wilder#set_option('renderer', wilder#popupmenu_renderer(wilder#popupmenu_border_theme({
\ 'pumblend': 0,
\ 'border': 'rounded',
\ 'highlighter': wilder#basic_highlighter(),
\ 'left': [' ', wilder#popupmenu_devicons()],
\ 'highlights': { 'accent': l:accent }
\ })))
endfunction
function! s:goyo_enter()
silent Gitsigns detach
lua require('lualine').hide()
if executable('tmux') && strlen($TMUX)
silent !tmux set status off
silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
endif
endfunction
function! s:goyo_leave()
silent Gitsigns attach
if executable('tmux') && strlen($TMUX)
silent !tmux set status on
silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
endif
endfunction
function! Sync_gist()
let l:lastline = getline('$')
if l:lastline =~ "GistID"
let l:gid = matchlist(l:lastline, '.\+GistID:\s*\(.\+\)')[1]
let l:cmd = '%!gist -r '. l:gid . ' -f '. expand('%:t')
silent execute(l:cmd)
if trim(getline('$')) == trim(l:lastline)
echom("new version downloaded from gist")
silent write
else
echoe("Remote version not expected, reload disk version")
execute(':e!')
endif
endif
endfunction
function! Post_gist()
let l:lastline = getline('$')
if getbufinfo('%')[0].changed && l:lastline =~ "GistID"
let l:gid = matchlist(l:lastline, '.\+GistID:\s*\(.\+\)')[1]
let l:result = execute(":w !gist -u ". l:gid . ' -f '. expand('%:t'))
if trim(l:result) == trim("https://gist.github.com/pwang2/". l:gid)
echom("🙂 update successfully.")
else
echoe("🤔 update failed.")
endif
endif
endfunction
function! s:hi_patch()
hi link FoldColumn Comment
hi Folded guibg=NONE guifg=#569cd6
hi Pmenu guibg=NONE guifg=#898989
hi Normal guibg=NONE
hi CmpItemAbbrDeprecated guibg=NONE guifg=#808080 gui=strikethrough
hi CmpItemAbbrMatch guibg=NONE guifg=#569CD6
hi CmpItemAbbrMatchFuzzy guibg=NONE guifg=#569CD6
hi CmpItemKindVariable guibg=NONE guifg=#9CDCFE
hi CmpItemKindInterface guibg=NONE guifg=#9CDCFE
hi CmpItemKindText guibg=NONE guifg=#9CDCFE
hi CmpItemKindFunction guibg=NONE guifg=#C586C0
hi CmpItemKindMethod guibg=NONE guifg=#C586C0
hi CmpItemKindKeyword guibg=NONE guifg=#D4D4D4
hi CmpItemKindProperty guibg=NONE guifg=#D4D4D4
hi CmpItemKindUnit guibg=NONE guifg=#D4D4D4
hi NormalFloat guibg=NONE
hi FloatBorder guifg=#569cd6
endfunction
function! SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
echo map(synstack(line('.'), col('.')), 'synIDattr(synIDtrans(v:val), "name")')
endfunc
function! OpenMarkdownPreview(url)
execute "silent !google-chrome " . a:url
endfunc
function! s:no_highlight()
if getfsize(@%) > 100000
syntax off
setlocal ft=
setlocal syn=
endif
endfunc
"}}}
"{{{ plugins
call plug#begin()
Plug 'christoomey/vim-tmux-navigator'
Plug 'edkolev/tmuxline.vim'
Plug 'godlygeek/tabular'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
Plug 'mattn/emmet-vim'
Plug 'mattn/webapi-vim'
Plug 'sbdchd/neoformat'
Plug 'simeji/winresizer'
Plug 'terryma/vim-multiple-cursors'
Plug 'tkhren/vim-fake'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-obsession'
Plug 'tpope/vim-repeat'
" Plug 'tpope/vim-sensible'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-rsi'
Plug 'voldikss/vim-floaterm'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'w0rp/ale'
Plug 'joshdick/onedark.vim'
Plug 'sonph/onehalf', { 'rtp': 'vim' }
Plug 'dracula/vim', { 'as': 'dracula' }
Plug 'puremourning/vimspector', { 'for': [ 'cs', 'javascript'] }
Plug 'powerman/vim-plugin-AnsiEsc', { 'for': 'cs' }
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
Plug 'ntpeters/vim-better-whitespace'
Plug 'neoclide/jsonc.vim'
Plug 'rust-lang/rust.vim'
if has('nvim')
if !exists('g:vscode')
Plug 'nvim-telescope/telescope.nvim'
endif
Plug 'sindrets/diffview.nvim'
Plug 'gelguy/wilder.nvim', { 'do': function('UpdateRemotePlugins') }
Plug 'numToStr/Comment.nvim'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npm install' }
Plug 'ibhagwan/smartyank.nvim'
" Plug 'github/copilot.vim'
Plug 'jalvesaq/Nvim-R'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'neovim/nvim-lspconfig'
Plug 'mfussenegger/nvim-dap'
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'kyazdani42/nvim-web-devicons'
Plug 'folke/lsp-colors.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'lewis6991/gitsigns.nvim'
Plug 'kyazdani42/nvim-tree.lua'
Plug 'folke/trouble.nvim'
Plug 'ggandor/lightspeed.nvim'
Plug 'stevearc/dressing.nvim'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/cmp-emoji'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp-signature-help'
Plug 'quangnguyen30192/cmp-nvim-ultisnips'
Plug 'onsails/lspkind-nvim'
Plug 'nvim-lualine/lualine.nvim'
Plug 'akinsho/bufferline.nvim', {'branch': 'main'}
" experimental
Plug 'dstein64/vim-startuptime'
Plug 'goolord/alpha-nvim'
Plug 'echasnovski/mini.nvim'
Plug 'norcalli/nvim-colorizer.lua'
Plug 'windwp/nvim-ts-autotag'
" Plug 'nvim-treesitter/nvim-treesitter-refactor'
Plug 'vim-scripts/AnsiEsc.vim'
Plug 'rhysd/vim-grammarous'
Plug 'MunifTanjim/nui.nvim'
" fix csharp_ls go to def metadata
Plug 'Decodetalkers/csharpls-extended-lsp.nvim'
Plug 'hoffs/omnisharp-extended-lsp.nvim'
" Plug 'lervag/vimtex', { 'for': 'tex' }
" Plug 'carlsmedstad/vim-bicep'
" Plug 'dccsillag/magma-nvim', { 'do': ':UpdateRemotePlugins' }
" Plug 'Bryley/neoai.nvim'
" Plug 'OmniSharp/omnisharp-vim'
" Plug 'tzachar/cmp-tabnine', { 'do': './install.sh' }
endif
call plug#end()
"}}}
"{{{ key mappings
noremap <F1> <Nop>
noremap Q <Nop>
noremap <CR><CR> :noh<CR>
noremap j gj
noremap k gk
nnoremap <Tab> gt
nnoremap <S-Tab> gT
noremap <leader>[ :bp<CR>
noremap <leader>] :bn<CR>
noremap <leader>k :ALEPrevious<CR>
noremap <leader>j :ALENext<CR>
noremap <leader>t :NvimTreeToggle<CR>
nnoremap <leader>q :q<CR>
noremap <leader>w :w<CR>
noremap <leader>rr :LspRestart<CR>
nnoremap <silent> <leader><space> :Goyo<CR><C-c>
nnoremap <silent> <leader>ft :FloatermToggle<CR>
nnoremap <silent> <leader>gd :DiffviewOpen<CR>
nnoremap <C-p> <cmd>Telescope find_files<CR>
nnoremap <leader>f <cmd>Telescope resume<CR>
nnoremap <leader>ff <cmd>Telescope find_files<CR>
nnoremap <leader>fg <cmd>Telescope live_grep<CR>
nnoremap <leader>fb <cmd>Telescope buffers<CR>
nnoremap <leader>fh <cmd>Telescope help_tags<CR>
nnoremap <leader>xx <cmd>Trouble<CR>
nnoremap gr <cmd>Trouble lsp_references<CR>
nnoremap <space>dl :call vimspector#Launch()<CR>
nnoremap <space>dr :call vimspector#Reset()<CR>
nnoremap <space>dc :call vimspector#Continue()<CR>
nnoremap <space>db :call vimspector#ToggleBreakpoint()<CR>
nnoremap <space>dC :call vimspector#ClearBreakpoints()<CR>
nnoremap <space>ds <Plug>VimspectorStop
nnoremap <space>dk <Plug>VimspectorRestart
nnoremap <space>do <Plug>VimspectorStepOut
nnoremap <space>di <Plug>VimspectorStepInto
nnoremap <space>dd <Plug>VimspectorStepOver
nmap <space>de <Plug>VimspectorBalloonEval
xmap <space>de <Plug>VimspectorBalloonEval
let c = 1
while c < 20
silent execute "nnoremap <leader>" . c . " :" . c . "b\<CR>"
let c += 1
endwhile
"}}}
"{{{ autocmds
augroup general
au!
au ColorScheme * call <SID>hi_patch()
au User GoyoEnter nested call <SID>goyo_enter()
au User GoyoLeave nested call <SID>goyo_leave()
au BufReadPost * call Sync_gist()
au BufWritePre * call Post_gist()
au BufWritePost $MYVIMRC :so $MYVIMRC
au BufWinEnter VimspectorPrompt AnsiEsc
au FileType * nnoremap <buffer><silent> <localleader>dd :lua vim.diagnostic.reset()<CR>
au FileType * nnoremap <buffer><silent> <localleader>f :lua vim.lsp.buf.format { async = true } <CR><CR>
au FileType javascript,vue,typescript nnoremap <buffer><silent> <localleader>f :Neoformat eslint_d <bar> :Neoformat prettier<CR><CR>
au FileType json,markdown,css,scss nnoremap <buffer> <localleader>f :Neoformat prettier <CR>
au FileType python nnoremap <buffer> <localleader>f :Neoformat black<CR>
au FileType html nnoremap <buffer> <localleader>f :%!prettier --parser html --print-width 1000 <CR>
au FileType r,javascript,html autocmd BufWritePre <buffer> %s/\s\+$//e
au FileType r nnoremap <buffer><silent> <CR> :call SendLineToR("down")<CR>
au FileType alpha lua vim.b.miniindentscope_disable=true
au CmdlineEnter * ++once if has('nvim') && !exists('g:vscode') | call <SID>wilder_init() | call wilder#main#start() | endif
augroup END
augroup cursorline_only_in_activewindow
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
augroup END
augroup no_syntax_hl_for_large_file
au!
au BufWinEnter * if getfsize(@%) > 100000 | syntax off | endif
augroup END
augroup vimrc_sync_fromstart
autocmd!
autocmd BufEnter * :syntax sync maxlines=200
augroup END
augroup vimrc_remember_cursor_position
autocmd!
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
augroup END
"}}}
colorscheme onehalfdark
"GistID: 33797ca5e8eec8c4ac32c79c05b9b499
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment