Skip to content

Instantly share code, notes, and snippets.

@bokwoon95
Last active March 13, 2023 12:07
Show Gist options
  • Save bokwoon95/d9420fce4836f6b518b02bd60a1bc376 to your computer and use it in GitHub Desktop.
Save bokwoon95/d9420fce4836f6b518b02bd60a1bc376 to your computer and use it in GitHub Desktop.
nmap <buffer> <expr> <Plug>(fern-my-open-expand-collapse)
\ fern#smart#leaf(
\ "<Plug>(fern-action-open)",
\ "<Plug>(fern-action-expand)",
\ "<Plug>(fern-action-collapse)",
\ )
nmap <buffer> <CR> <Plug>(fern-my-open-expand-collapse)
nmap <buffer> <2-LeftMouse> <Plug>(fern-my-open-expand-collapse)
inoremap <buffer> <C-q><C-q> w http.ResponseWriter, r *http.Request
setlocal tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
command! EV edit $MYVIMRC
command! SV source $MYVIMRC
function! MyHighlights() abort
highlight clear VertSplit
highlight clear Folded
highlight clear SignColumn
highlight clear FoldColumn
highlight MatchParen ctermfg=NONE ctermbg=NONE cterm=underline guifg=NONE guibg=NONE gui=underline
highlight StatusLine ctermfg=233 ctermbg=103 cterm=bold gui=bold
highlight StatusLineNC ctermfg=0 ctermbg=NONE cterm=underline guibg=NONE gui=underline
highlight DiffAdd ctermfg=2 ctermbg=NONE cterm=NONE guifg=2 guibg=NONE gui=NONE
highlight DiffDelete ctermfg=1 ctermbg=NONE cterm=NONE guifg=1 guibg=NONE gui=NONE
highlight DiffChange ctermfg=5 ctermbg=NONE cterm=NONE guifg=5 guibg=NONE gui=NONE
highlight NonText ctermbg=NONE guibg=NONE
highlight EndOfBuffer ctermbg=NONE guibg=NONE
endfunction
augroup MyColors
autocmd!
autocmd ColorScheme * call MyHighlights()
augroup END
colorscheme morning
set hidden
set number
set mouse=a
set wildignorecase
set linebreak
set ignorecase smartcase
set tabstop=4 shiftwidth=4 softtabstop=4 expandtab
set list
set listchars=tab:\|\ ,trail:·
set foldopen-=block
set breakindent
set inccommand=nosplit
set fillchars+=vert:│
set matchpairs+=<:>
set whichwrap+=[,],<,>,h,l
set lazyredraw
set noequalalways
set foldcolumn=1
set completeopt-=preview " get rid of preview scratch buffer on <C-x><C-o>
set splitbelow splitright
fun! RestoreCursorPosition() abort
if &ft =~ 'gitcommit\|gitcommit'
return
endif
call setpos(".", getpos("'\""))
endfun
augroup Basics
autocmd!
autocmd FocusGained,BufEnter * silent! checktime " To trigger vim's autoread on focus gained or buffer enter
autocmd FocusGained,BufEnter * silent! SignifyRefresh
autocmd BufReadPost * call RestoreCursorPosition()
augroup END
autocmd! Filetype vim setlocal foldmethod=marker tabstop=2 softtabstop=2 shiftwidth=2 expandtab
set foldtext=repeat('\ ',indent(v:foldstart)).foldtext()
noremap <silent> <expr> k v:count == 0 ? "gk" : "k"
noremap <silent> <expr> j v:count == 0 ? "gj" : "j"
noremap <C-j> 5gj
noremap <C-k> 5gk
noremap <C-h> 4<C-y>
noremap <C-l> 4<C-e>
noremap <BS> <C-^>
nnoremap <Space>b :ls<CR>:b<Space>
inoremap <expr> <C-y> !pumvisible() ? "<C-o>:set paste<CR><C-r><C-o>+<C-o>:set nopaste<CR>" : "\<C-y>"
command! TL verbose setlocal tabstop? softtabstop? shiftwidth? expandtab?
command! T2 setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
command! T4 setlocal tabstop=4 softtabstop=4 shiftwidth=4 expandtab
command! T8 setlocal tabstop=8 softtabstop=8 shiftwidth=8 expandtab
command! Tb2 setlocal tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab
command! Tb4 setlocal tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
command! Tb8 setlocal tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab
command! Spa setlocal paste
command! Sna setlocal nopaste
nnoremap Q @q
map M %
noremap H g^
nnoremap L g$
onoremap L g$
xnoremap L g$h
xnoremap < <gv
xnoremap > >gv
nnoremap x "_x
nnoremap c "_c
nnoremap C "_C
nnoremap D "_D
xnoremap x "_x
xnoremap c "_c
xnoremap C "_C
xnoremap D "_D
set noswapfile
nnoremap <Space>ss :%s//g<Left><Left>
xnoremap <Space>ss :s//g<Left><Left>
xnoremap <Space>sr "xy:%s/<C-r><C-r>=substitute(escape(@x, '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR>/<C-r><C-r>=substitute(escape(@x, '/'), ' ', ' ', 'g')<CR>/g<Left><Left><Space><BS>
nnoremap <Space>hh :nohls<CR>
nnoremap <Space>ww :let b:wsv=winsaveview()<CR>
\:let b:old_search=@/<CR>
\:%s/\s\+$//e<CR>
\:let @/=b:old_search<CR>
\:silent! call winrestview(b:wsv)<CR>
\:echo '+++ Trailing whitespaces purged +++'<CR>
xnoremap <silent> * :<C-u>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy/<C-R><C-R>=substitute(escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
nnoremap <C-x>f :e<Space><C-r>=expand('%:h').'/'<CR><C-z>
command! BD :Bdelete
xnoremap Y "+y
nnoremap ZX :wqa!<CR>
noremap <M-C-q> :wqa!<CR>
nnoremap gh `[v`]
" readline
inoremap <C-b> <Left>
inoremap <C-f> <Right>
inoremap <C-a> <C-o>g0
inoremap <C-e> <C-o>g$
inoremap <M-b> <C-Left>
inoremap <M-f> <C-Right>
" behave mswin
set selectmode=mouse,key
set mousemodel=popup
set keymodel=
set selection=inclusive
snoremap <BS> c<BS>
" cut
vnoremap <C-X> "+x
vnoremap <S-Del> "+x
" copy
vnoremap <C-c> "+y
vnoremap <C-Insert> "+y
" paste
map <C-v> "+gP
map <S-Insert> "+gP
cmap <C-v> <C-r>+
cmap <S-Insert> <C-r>+
inoremap <C-v> <C-o>:set paste<CR><C-r><C-r>+<C-o>:set nopaste<CR>
inoremap <S-Insert> <C-o>:set paste<CR><C-r><C-r>+<C-o>:set nopaste<CR>
" save
noremap <C-s> :update<CR>
vnoremap <C-s> <C-c>:update<CR>
inoremap <C-s> <Esc>:update<CR>gi
" undo
noremap <C-z> u
inoremap <C-z> <C-o>u
" redo
noremap <A-z> <C-r>
inoremap <A-z> <C-o><C-r>
" movement
inoremap <Up> <C-o>gk
inoremap <Down> <C-o>gj
inoremap <A-Left> <C-Left>
inoremap <A-Right> <C-Right>
inoremap <A-Up> <C-o>g0
inoremap <A-Down> <C-o>g$
" sidescroll
nnoremap <A-'> 4zl
nnoremap <A-;> 4zh
set statusline=
set statusline+=%{has('nvim')?'[':'('} " [(
set statusline+=%{strlen(&ft)?&ft:'none'}, " Filetype
set statusline+=%{strlen(&fenc)?&fenc:&enc}, " Encoding
set statusline+=%{&fileformat} " File format (dos, unix)
set statusline+=%{has('nvim')?']':')'} " ])
set statusline+=\ %f " t filename, f relative filepath, F absolute filepath
set statusline+=%{&modified?'\ +':''} " Show '+' when file has been modified
set statusline+=%{&readonly?'\ [RO]':''} " Show 'RO' when file is in readonly
set statusline+=%{!&modifiable?'\ [noma]':''} " Show 'noma' when file is nonmodifiable
set statusline+=%= " Right align
set statusline+=\ %{exists('g:loaded_obsession')?ObsessionStatus():''} " Obsession status
set statusline+=\ %{exists('g:loaded_fugitive')?fugitive#head(7):''} " Git branch
set statusline+=\ %(%l,%c%V%) " Show line, column, virtual column (denoted with a '-' in front)
set statusline+=\ %3p%%\ " Percentage of file shown
set statusline+=%{has('nvim')?'[':'('} " [(
set statusline+=%(%{'help'!=&filetype?bufnr('%'):''}%) " Buffer number
set statusline+=%{has('nvim')?']':')'} " ])
tnoremap <C-w><C-]> <C-\><C-n>
" vim-matchup
let g:matchup_matchparen_status_offscreen = 0
" nvim-telescope
nnoremap <Space>ff <cmd>Telescope find_files<cr>
nnoremap <Space>fg <cmd>Telescope live_grep<cr>
nnoremap <Space>fb <cmd>lua require('telescope.builtin').buffers({ sort_mru = true, ignore_current_buffer = true })<cr>
nnoremap <Space>b <cmd>lua require('telescope.builtin').buffers({ sort_mru = true, ignore_current_buffer = true })<cr>
nnoremap <Space>fh <cmd>Telescope oldfiles<cr>
" tmux-navigator
let g:tmux_navigator_no_mappings = 1
nnoremap <silent> <M-h> :TmuxNavigateLeft<CR>
nnoremap <silent> <M-j> :TmuxNavigateDown<CR>
nnoremap <silent> <M-k> :TmuxNavigateUp<CR>
nnoremap <silent> <M-l> :TmuxNavigateRight<CR>
nnoremap <silent> <M-\> :TmuxNavigatePrevious<CR>
inoremap <silent> <M-h> <C-o>:TmuxNavigateLeft<CR>
inoremap <silent> <M-j> <C-o>:TmuxNavigateDown<CR>
inoremap <silent> <M-k> <C-o>:TmuxNavigateUp<CR>
inoremap <silent> <M-l> <C-o>:TmuxNavigateRight<CR>
inoremap <silent> <M-\> <C-o>:TmuxNavigatePrevious<CR>
" nvim-lsp
lua << EOF
local err, nvim_lsp = pcall(require, 'lspconfig')
if not(err) then
return
end
-- 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', 'K', '<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', '<C-k>', '<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', '<space>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', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setqflist()<CR>', opts)
buf_set_keymap('n', '<space>fm', '<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 = { 'gopls', 'tsserver' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
}
}
end
EOF
lua <<EOF
-- https://github.com/golang/tools/blob/master/gopls/doc/vim.md#neovim-install
function goimports(timeout_ms)
local context = { only = { "source.organizeImports" } }
vim.validate { context = { context, "t", true } }
local params = vim.lsp.util.make_range_params()
params.context = context
-- See the implementation of the textDocument/codeAction callback
-- (lua/vim/lsp/handler.lua) for how to do this properly.
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, timeout_ms)
if not result or next(result) == nil then return end
local actions = result[1].result
if not actions then return end
local action = actions[1]
-- textDocument/codeAction can return either Command[] or CodeAction[]. If it
-- is a CodeAction, it can have either an edit, a command or both. Edits
-- should be executed first.
if action.edit or type(action.command) == "table" then
if action.edit then
vim.lsp.util.apply_workspace_edit(action.edit, "utf-8")
end
if type(action.command) == "table" then
vim.lsp.buf.execute_command(action.command)
end
else
vim.lsp.buf.execute_command(action)
end
end
EOF
autocmd! BufWritePre *.go lua goimports(1000)
" markdown-preview.nvim
let g:mkdp_auto_close = 0
" ragtag
let g:ragtag_global_maps = 0
imap <C-x>/ <Plug>ragtagHtmlComplete
" vim-bbye
nnoremap _ :Bdelete!<CR>
set clipboard+=unnamedplus
vnoremap P "0p
nnoremap <Space>l :let @+=join([expand('%'), line(".")], ':')<CR>
" fern.vim
let g:fern#disable_default_mappings = 1
let g:fern#disable_drawer_auto_quit = 1
let g:fern#disable_viewer_hide_cursor = 1
nnoremap <silent> <C-n> :Fern . -drawer -width=35 -toggle<CR><C-w>=
function! FernInit() abort
setlocal nonumber
nmap <buffer><expr>
\ <Plug>(fern-my-open-expand-collapse)
\ fern#smart#leaf(
\ "\<Plug>(fern-action-open:select)",
\ "\<Plug>(fern-action-expand)",
\ "\<Plug>(fern-action-collapse)",
\ )
nmap <buffer> <CR> <Plug>(fern-my-open-expand-collapse)
nmap <buffer> <2-LeftMouse> <Plug>(fern-my-open-expand-collapse)
nmap <buffer> m <Plug>(fern-action-mark:toggle)j
nmap <buffer> C <Plug>(fern-action-mark:clear)
nmap <buffer> a <Plug>(fern-action-new-path)
nmap <buffer> A <Plug>(fern-action-choice)
nmap <buffer> d <Plug>(fern-action-remove)
nmap <buffer> <Backspace> <Plug>(fern-action-collapse)
nmap <buffer> r <Plug>(fern-action-move)
nmap <buffer> R <Plug>(fern-action-reload)
nmap <buffer> <nowait> i <Plug>(fern-action-hidden:toggle)
nmap <buffer> <nowait> < <Plug>(fern-action-leave)
nmap <buffer> <nowait> > <Plug>(fern-action-enter)
nmap <buffer> c <Plug>(fern-action-clipboard-copy)
nmap <buffer> p <Plug>(fern-action-clipboard-paste)
endfunction
augroup FernEvents
autocmd!
autocmd FileType fern call FernInit()
augroup END
nnoremap <S-Left> :SidewaysLeft<CR>
nnoremap <S-Right> :SidewaysRight<CR>
cnoremap <C-q> <C-v>
setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
https://github.com/neovim/nvim-lspconfig
https://github.com/nvim-lua/plenary.nvim
https://github.com/nvim-telescope/telescope.nvim
https://github.com/iamcco/markdown-preview.nvim
https://github.com/AndrewRadev/sideways.vim
https://github.com/godlygeek/tabular
https://github.com/wellle/targets.vim
https://github.com/tpope/vim-commentary
https://github.com/tpope/vim-eunuch
https://github.com/andymass/vim-matchup
https://github.com/romainl/vim-qlist
https://github.com/tpope/vim-repeat
https://github.com/mhinz/vim-signify
https://github.com/tpope/vim-surround
https://github.com/moll/vim-bbye
https://github.com/lambdalisue/fern.vim
https://github.com/romainl/vim-qf
https://github.com/tpope/vim-unimpaired
https://github.com/AndrewRadev/sideways.vim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment