comparison vim-setup/.vimrc @ 151:c033667da5f9 hg-web

Merging latest merge into hg-web
author June Park <parkjune1995@gmail.com>
date Sat, 10 Jan 2026 13:35:09 -0800
parents c37490913530
children 790930d9bb90
comparison
equal deleted inserted replaced
147:6de849867459 151:c033667da5f9
57 57
58 " Yank into clipboard 58 " Yank into clipboard
59 nnoremap <leader>y "+y 59 nnoremap <leader>y "+y
60 vnoremap <leader>y "+y 60 vnoremap <leader>y "+y
61 61
62 " FZF 62 command! -bang -nargs=* RG
63 " Add fzf to runtimepath 63 \ call fzf#vim#grep(
64 set rtp += ~/.fzf 64 \ 'rg --column --line-number --no-heading --color=always --smart-case --hidden '.shellescape(<q-args>),
65 \ 1,
66 \ fzf#vim#with_preview(),
67 \ <bang>0)
68
65 " <leader>ff: Fuzzy file search 69 " <leader>ff: Fuzzy file search
66 nnoremap <leader>ff :Files<CR> 70 nnoremap <leader>ff :Files<CR>
67 71
68 " <leader>fb: Fuzzy search within buffer 72 " <leader>fb: Fuzzy search within buffer
69 nnoremap <leader>fb :Buffers<CR> 73 nnoremap <leader>fb :Buffers<CR>
72 nnoremap <leader>ft :Tags<CR> 76 nnoremap <leader>ft :Tags<CR>
73 77
74 " <leader>fs: Ripgrep search for word (normal mode) 78 " <leader>fs: Ripgrep search for word (normal mode)
75 nnoremap <leader>fs :RG<CR> 79 nnoremap <leader>fs :RG<CR>
76 80
77 " <leader>fs: Ripgrep search for selected text (visual mode) 81 " <leader>fs: Open Ripgrep search prompt
78 vnoremap <leader>fs :<C-u>execute 'Rg ' . getreg('"')<CR> 82 nnoremap <leader>fs :RG<CR>
83
84 function! RipgrepCursor(query)
85 call fzf#vim#grep(
86 \ 'rg --column --line-number --no-heading --color=always --smart-case -- '.shellescape(a:query),
87 \ 1,
88 \ fzf#vim#with_preview(),
89 \ 0)
90 endfunction
91
92 " <leader>gr: Search word under cursor (Normal)
93 nnoremap <silent> <leader>gr :call RipgrepCursor(expand('<cword>'))<CR>
94
95 " <leader>gr: Search selection (Visual)
96 vnoremap <silent> <leader>gr y:call RipgrepCursor(@@)<CR>
97
98 nnoremap <leader>gd <C-w>}
99 nnoremap <leader>gD <C-]>
79 100
80 " Open man in vim 101 " Open man in vim
81 noremap <c-k> :h <cword><cr> 102 noremap <c-k> :h <cword><cr>
82 103
83 " vim wiki 104 " vim wiki
93 " Enable links to markdown files 114 " Enable links to markdown files
94 let g:wiki_link_extension = '.md' 115 let g:wiki_link_extension = '.md'
95 116
96 " Turn on man vim mode 117 " Turn on man vim mode
97 runtime! ftplugin/man.vim 118 runtime! ftplugin/man.vim
119
98 " Keyword 120 " Keyword
99 set keywordprg=:Man 121 set keywordprg=:Man
100 122
123 " FZF enbale vim
124 set rtp+=/opt/homebrew/opt/fzf
125
126 " For some reason it include ( or ) when I use it in here
127 set iskeyword-=( iskeyword-=)
128
129 " ============================================================================
130 " Markdown Clipboard Image Paste
131 " ============================================================================
132 " Configuration: Set your API endpoint URL (leave empty to save locally)
133 let g:clipboard_image_upload_url = ''
134
135 " Optional: Custom curl options (e.g., for auth headers)
136 " let g:clipboard_image_curl_opts = '-H "Authorization: Bearer YOUR_TOKEN"'
137 let g:clipboard_image_curl_opts = ''
138
139 function! PasteClipboardImage()
140 if &filetype != 'markdown'
141 echo "Clipboard image paste only works in markdown files"
142 return
143 endif
144
145 if !executable('pngpaste')
146 echo "Error: pngpaste not found. Install with: brew install pngpaste"
147 return
148 endif
149
150 let l:tmpfile = tempname() . '.png'
151
152 let l:result = system('pngpaste ' . shellescape(l:tmpfile) . ' 2>&1')
153
154 if v:shell_error != 0
155 echo "No image in clipboard or pngpaste failed: " . l:result
156 return
157 endif
158
159 if !filereadable(l:tmpfile)
160 echo "Failed to save clipboard image"
161 return
162 endif
163
164 if g:clipboard_image_upload_url == ''
165 let l:dir = expand('%:p:h')
166 let l:random = localtime() . '_' . rand()
167 let l:filename = 'image_' . l:random . '.png'
168 let l:filepath = l:dir . '/' . l:filename
169
170 call rename(l:tmpfile, l:filepath)
171
172 if !filereadable(l:filepath)
173 echo "Failed to save image locally"
174 call delete(l:tmpfile)
175 return
176 endif
177
178 let l:url = l:filename
179 echo "Image saved locally: " . l:filename
180 else
181 echo "Uploading image..."
182
183 let l:curl_cmd = 'curl -s -X POST'
184 let l:curl_cmd .= ' -H "Content-Type: image/png"'
185 let l:curl_cmd .= ' --data-binary @' . shellescape(l:tmpfile)
186 if g:clipboard_image_curl_opts != ''
187 let l:curl_cmd .= ' ' . g:clipboard_image_curl_opts
188 endif
189 let l:curl_cmd .= ' ' . shellescape(g:clipboard_image_upload_url)
190
191 let l:url = system(l:curl_cmd)
192
193 call delete(l:tmpfile)
194
195 if v:shell_error != 0
196 echo "Upload failed: " . l:url
197 return
198 endif
199
200 let l:url = substitute(l:url, '^\s*\(.\{-}\)\s*$', '\1', '')
201 echo "Image uploaded!"
202 endif
203
204 " Insert markdown image syntax at cursor
205 execute "normal! a" . l:markdown_img . "\<Esc>"
206 endfunction
207
208 autocmd FileType markdown nnoremap <buffer> <leader>p :call PasteClipboardImage()<CR>
209
101 " Setup LSP + completion (I will turn on and off depending on sitautions) 210 " Setup LSP + completion (I will turn on and off depending on sitautions)
102 lua << EOF 211 " lua << EOF
103 vim.lsp.set_log_level('OFF') 212 " vim.lsp.set_log_level('OFF')
104 213 "
105 local cmp = require('cmp') 214 " local cmp = require('cmp')
106 local luasnip = require('luasnip') 215 " local luasnip = require('luasnip')
107 local lspconfig = require('lspconfig') 216 " local lspconfig = require('lspconfig')
108 local util = require('lspconfig.util') 217 " local util = require('lspconfig.util')
109 218 "
110 -- ────────────────────────────── 219 " -- ──────────────────────────────
111 -- nvim-cmp setup (unchanged) 220 " -- nvim-cmp setup (unchanged)
112 -- ────────────────────────────── 221 " -- ──────────────────────────────
113 cmp.setup({ 222 " cmp.setup({
114 snippet = { 223 " snippet = {
115 expand = function(args) luasnip.lsp_expand(args.body) end, 224 " expand = function(args) luasnip.lsp_expand(args.body) end,
116 }, 225 " },
117 mapping = cmp.mapping.preset.insert({ 226 " mapping = cmp.mapping.preset.insert({
118 ['<C-Space>'] = cmp.mapping.complete(), 227 " ['<C-Space>'] = cmp.mapping.complete(),
119 ['<CR>'] = cmp.mapping.confirm({ select = true }), 228 " ['<CR>'] = cmp.mapping.confirm({ select = true }),
120 ['<C-J>'] = cmp.mapping.select_next_item(), 229 " ['<C-J>'] = cmp.mapping.select_next_item(),
121 ['<C-K>'] = cmp.mapping.select_prev_item(), 230 " ['<C-K>'] = cmp.mapping.select_prev_item(),
122 }), 231 " }),
123 sources = cmp.config.sources({ 232 " sources = cmp.config.sources({
124 { name = 'nvim_lsp', group_index = 1 }, 233 " { name = 'nvim_lsp', group_index = 1 },
125 { name = 'luasnip', group_index = 1 }, 234 " { name = 'luasnip', group_index = 1 },
126 { name = 'buffer', group_index = 2 }, 235 " { name = 'buffer', group_index = 2 },
127 }) 236 " })
128 }) 237 " })
129 238 "
130 local capabilities = require('cmp_nvim_lsp').default_capabilities() 239 " local capabilities = require('cmp_nvim_lsp').default_capabilities()
131 240 "
132 -- ts_ls 241 " -- ts_ls
133 lspconfig.ts_ls.setup({ 242 " lspconfig.ts_ls.setup({
134 capabilities = capabilities, 243 " capabilities = capabilities,
135 root_dir = require('lspconfig.util').root_pattern('tsconfig.json'), 244 " root_dir = require('lspconfig.util').root_pattern('tsconfig.json'),
136 init_options = { 245 " init_options = {
137 maxTsServerMemory = 8192, 246 " maxTsServerMemory = 8192,
138 preferences = { 247 " preferences = {
139 includePackageJsonAutoImports = "auto", 248 " includePackageJsonAutoImports = "auto",
140 }, 249 " },
141 }, 250 " },
142 filetypes = { "typescript", "typescriptreact", "javascript", "javascriptreact" }, 251 " filetypes = { "typescript", "typescriptreact", "javascript", "javascriptreact" },
143 settings = { 252 " settings = {
144 typescript = { 253 " typescript = {
145 inlayHints = { 254 " inlayHints = {
146 includeInlayParameterNameHints = "all", 255 " includeInlayParameterNameHints = "all",
147 includeInlayParameterNameHintsWhenArgumentMatchesName = false, 256 " includeInlayParameterNameHintsWhenArgumentMatchesName = false,
148 includeInlayFunctionParameterTypeHints = true, 257 " includeInlayFunctionParameterTypeHints = true,
149 includeInlayVariableTypeHints = true, 258 " includeInlayVariableTypeHints = true,
150 includeInlayPropertyDeclarationTypeHints = true, 259 " includeInlayPropertyDeclarationTypeHints = true,
151 includeInlayFunctionLikeReturnTypeHints = true, 260 " includeInlayFunctionLikeReturnTypeHints = true,
152 includeInlayEnumMemberValueHints = true, 261 " includeInlayEnumMemberValueHints = true,
153 }, 262 " },
154 }, 263 " },
155 }, 264 " },
156 265 "
157 -- Force tsserver to reload the tsconfig every time (fixes 95% of path alias issues) 266 " -- Force tsserver to reload the tsconfig every time (fixes 95% of path alias issues)
158 on_attach = function(client, bufnr) 267 " on_attach = function(client, bufnr)
159 -- Optional: show when LSP attaches 268 " -- Optional: show when LSP attaches
160 print("ts_ls attached to " .. vim.fn.getcwd()) 269 " print("ts_ls attached to " .. vim.fn.getcwd())
161 end, 270 " end,
162 }) 271 " })
163 272 "
164 -- Python 273 " -- Python
165 lspconfig.basedpyright.setup({ 274 " lspconfig.basedpyright.setup({
166 capabilities = capabilities, 275 " capabilities = capabilities,
167 on_attach = function(client, bufnr) 276 " on_attach = function(client, bufnr)
168 -- Optional: notify when Python LSP attaches 277 " -- Optional: notify when Python LSP attaches
169 print("basedpyright attached to " .. vim.fn.getcwd()) 278 " print("basedpyright attached to " .. vim.fn.getcwd())
170 279 "
171 -- Common LSP keymaps (you can put them once at the bottom instead if you prefer) 280 " -- Common LSP keymaps (you can put them once at the bottom instead if you prefer)
172 -- local bufopts = { noremap = true, silent = true, buffer = bufnr } 281 " -- local bufopts = { noremap = true, silent = true, buffer = bufnr }
173 -- vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) 282 " -- vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
174 -- vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) 283 " -- vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
175 -- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) 284 " -- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
176 -- vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts) 285 " -- vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
177 -- vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, bufopts) 286 " -- vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, bufopts)
178 -- vim.keymap.set('n', '\\d', vim.diagnostic.open_float, bufopts) 287 " -- vim.keymap.set('n', '\\d', vim.diagnostic.open_float, bufopts)
179 -- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, bufopts) 288 " -- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, bufopts)
180 -- vim.keymap.set('n', ']d', vim.diagnostic.goto_next, bufopts) 289 " -- vim.keymap.set('n', ']d', vim.diagnostic.goto_next, bufopts)
181 end, 290 " end,
182 settings = { 291 " settings = {
183 basedpyright = { 292 " basedpyright = {
184 analysis = { 293 " analysis = {
185 autoSearchPaths = true, 294 " autoSearchPaths = true,
186 useLibraryCodeForTypes = true, 295 " useLibraryCodeForTypes = true,
187 diagnosticMode = "workspace", -- or "openFiles" if you have huge monorepos 296 " diagnosticMode = "workspace", -- or "openFiles" if you have huge monorepos
188 typeCheckingMode = "standard", -- "strict" if you want maximum strictness 297 " typeCheckingMode = "standard", -- "strict" if you want maximum strictness
189 }, 298 " },
190 }, 299 " },
191 }, 300 " },
192 root_dir = util.root_pattern( 301 " root_dir = util.root_pattern(
193 "venv", -- This is what I mostly use 302 " "venv", -- This is what I mostly use
194 "pyproject.toml", -- belows are whatever they use I guess 303 " "pyproject.toml", -- belows are whatever they use I guess
195 "setup.py", 304 " "setup.py",
196 "setup.cfg", 305 " "setup.cfg",
197 "requirements.txt", 306 " "requirements.txt",
198 ".git" 307 " ".git"
199 ), 308 " ),
200 }) 309 " })
201 310 "
202 EOF 311 " EOF
203 312 "
204 " Optional key mappings for LSP 313 " " Optional key mappings for LSP
205 nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR> 314 " nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
206 nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR> 315 " nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
207 nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR> 316 " nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
208 nnoremap <silent> \d <cmd>lua vim.diagnostic.open_float(nil, { border = "rounded" })<CR> 317 " nnoremap <silent> \d <cmd>lua vim.diagnostic.open_float(nil, { border = "rounded" })<CR>
209 nnoremap <silent> [d <cmd>lua vim.diagnostic.goto_prev()<CR> 318 " nnoremap <silent> [d <cmd>lua vim.diagnostic.goto_prev()<CR>
210 nnoremap <silent> ]d <cmd>lua vim.diagnostic.goto_next()<CR> 319 " nnoremap <silent> ]d <cmd>lua vim.diagnostic.goto_next()<CR>
211 nnoremap <silent> \ca <cmd>lua vim.lsp.buf.code_action()<CR> 320 " nnoremap <silent> \ca <cmd>lua vim.lsp.buf.code_action()<CR>