Created
February 27, 2026 09:18
-
-
Save al-maisan/3a2a57392c0ce43b10f58e6f5899923d to your computer and use it in GitHub Desktop.
.vimrc
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
| " A sensible vimrc for Go development | |
| " | |
| " Please note that the following settings are some default that I used | |
| " for years. However it might be not the case for you (and your | |
| " environment). I highly encourage to change/adapt the vimrc to your own | |
| " needs. Think of a vimrc as a garden that needs to be maintained and fostered | |
| " throughout years. Keep it clean and useful - Fatih Arslan | |
| call plug#begin() | |
| Plug 'fatih/vim-go' | |
| Plug 'tpope/vim-surround' | |
| Plug 'tpope/vim-repeat' | |
| Plug 'ycm-core/YouCompleteMe' | |
| Plug 'SirVer/ultisnips' | |
| Plug 'honza/vim-snippets' | |
| Plug 'rust-lang/rust.vim' | |
| " Plug 'skywind3000/gutentags_plus' " not needed with YCM + rust-analyzer | |
| " 1. PaperColor | |
| Plug 'NLKNguyen/papercolor-theme' | |
| " 2. Solarized | |
| Plug 'altercation/vim-colors-solarized' | |
| " 3. Gruvbox | |
| Plug 'morhetz/gruvbox' | |
| " 4. One Light | |
| Plug 'rakr/vim-one' | |
| " 5. GitHub Light | |
| Plug 'projekt0n/github-nvim-theme' | |
| " 6. Tomorrow Light | |
| Plug 'chriskempson/vim-tomorrow-theme' | |
| " 7. Nord Light (community variant with light mode) | |
| Plug 'shaunsingh/nord.nvim' " or check other forks that offer light | |
| " 8. Badwolf | |
| Plug 'sjl/badwolf' | |
| " 9. Iceberg Light | |
| Plug 'cocopon/iceberg.vim' | |
| " 10. Ayu Light | |
| Plug 'ayu-theme/ayu-vim' | |
| Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
| Plug 'junegunn/fzf.vim' | |
| call plug#end() | |
| set background=light | |
| colorscheme Tomorrow | |
| nmap <silent> cp :!echo %:p \| xclip -selection clipboard<CR><ESC> | |
| let mapleader="," | |
| nnoremap <leader>gc :YcmCompleter GoToCallers<CR> | |
| nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR> | |
| nnoremap <leader>gf :YcmCompleter GoToDefinition<CR> | |
| nnoremap <leader>gi :YcmCompleter GoToImplementation<CR> | |
| nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR> | |
| let g:ycm_use_ultisnips_completer = 1 | |
| "let g:UltiSnipsExpandTrigger = "<tab>" | |
| let g:UltiSnipsExpandTrigger='<Enter>' | |
| let g:go_build_tags = "integrationtests" | |
| let g:UltiSnipsListSnippets = "<c-tab>" | |
| let g:UltiSnipsJumpForwardTrigger = "<c-j>" | |
| let g:UltiSnipsJumpBackwardTrigger = "<c-k>" | |
| let g:matchparen_timeout = 1000 | |
| let g:matchparen_insert_timeout = 1000 | |
| let g:go_auto_type_info = 1 " Automatically show type info | |
| let g:go_doc_popup_window = 1 " Use popup window for docs | |
| " rust.vim | |
| let g:rustfmt_autosave = 0 | |
| """""""""""""""""""""" | |
| " Settings " | |
| """""""""""""""""""""" | |
| set nocompatible " Enables us Vim specific features | |
| filetype off " Reset filetype detection first ... | |
| filetype plugin indent on " ... and enable filetype detection | |
| set ttyfast " Indicate fast terminal conn for faster redraw | |
| set ttymouse=xterm2 " Indicate terminal type for mouse codes | |
| set ttyscroll=3 " Speedup scrolling | |
| set laststatus=2 " Show status line always | |
| set encoding=utf-8 " Set default encoding to UTF-8 | |
| set autoread " Automatically read changed files | |
| set autoindent " Enabile Autoindent | |
| set backspace=indent,eol,start " Makes backspace key more powerful. | |
| set incsearch " Shows the match while typing | |
| set hlsearch " Highlight found searches | |
| set noerrorbells " No beeps | |
| set nonumber " Show line numbers | |
| set showcmd " Show me what I'm typing | |
| set noswapfile " Don't use swapfile | |
| set nobackup " Don't create annoying backup files | |
| set splitright " Vertical windows should be split to right | |
| set splitbelow " Horizontal windows should split to bottom | |
| set autowrite " Automatically save before :next, :make etc. | |
| set hidden " Buffer should still exist if window is closed | |
| set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats | |
| set noshowmatch " Do not show matching brackets by flickering | |
| set noshowmode " We show the mode with airline or lightline | |
| set noignorecase " Search case insensitive... | |
| set smartcase " ... but not it begins with upper case | |
| set completeopt=menu,menuone " Show popup menu, even if there is one entry | |
| set pumheight=10 " Completion window max size | |
| set nocursorcolumn " Do not highlight column (speeds up highlighting) | |
| set nocursorline " Do not highlight cursor (speeds up highlighting) | |
| set lazyredraw " Wait to redraw | |
| " Enable to copy to clipboard for operations like yank, delete, change and put | |
| " http://stackoverflow.com/questions/20186975/vim-mac-how-to-copy-to-clipboard-without-pbcopy | |
| if has('unnamedplus') | |
| set clipboard^=unnamed | |
| set clipboard^=unnamedplus | |
| endif | |
| " This enables us to undo files even if you exit Vim. | |
| if has('persistent_undo') | |
| set undofile | |
| set undodir=~/.config/vim/tmp/undo// | |
| endif | |
| " Colorscheme | |
| syntax enable | |
| set t_Co=256 | |
| let g:rehash256 = 1 | |
| """""""""""""""""""""" | |
| " Mappings " | |
| """""""""""""""""""""" | |
| " Jump to next error with Ctrl-n and previous error with Ctrl-m. Close the | |
| " quickfix window with <leader>a | |
| map <C-n> :cnext<CR> | |
| map <C-m> :cprevious<CR> | |
| nnoremap <leader>a :cclose<CR> | |
| " Visual linewise up and down by default (and use gj gk to go quicker) | |
| noremap <Up> gk | |
| noremap <Down> gj | |
| " 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 | |
| " Act like D and C | |
| nnoremap Y y$ | |
| " Enter automatically into the files directory | |
| " autocmd BufEnter * silent! lcd %:p:h | |
| """"""""""""""""""""" | |
| " Plugins " | |
| """"""""""""""""""""" | |
| " vim-go | |
| let g:go_def_mode='gopls' | |
| let g:go_fmt_command = "goimports" | |
| let g:go_autodetect_gopath = 1 | |
| let g:go_list_type = "quickfix" | |
| 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_extra_types = 1 | |
| let g:go_highlight_generate_tags = 1 | |
| let g:go_auto_type_info = 1 | |
| "let g:go_auto_sameids = 1 | |
| set updatetime=750 | |
| augroup go | |
| autocmd! | |
| " Show by default 4 spaces for a tab | |
| autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=3 shiftwidth=3 | |
| " :GoBuild and :GoTestCompile | |
| autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR> | |
| autocmd filetype go nmap <leader>c :GoCallers | |
| " :GoImplements | |
| autocmd FileType go nmap <Leader>i <Plug>(go-implements) | |
| augroup END | |
| augroup rust | |
| autocmd! | |
| " YCM-based navigation (rust-analyzer) | |
| autocmd FileType rust nmap <buffer> <leader>gf :YcmCompleter GoToDefinition<CR> | |
| autocmd FileType rust nmap <buffer> <C-]> :YcmCompleter GoToDefinition<CR> | |
| autocmd FileType rust nmap <buffer> <leader>gl :YcmCompleter GoToDeclaration<CR> | |
| autocmd FileType rust nmap <buffer> <leader>gi :YcmCompleter GoToImplementation<CR> | |
| autocmd FileType rust nmap <buffer> <leader>gc :YcmCompleter GoToCallers<CR> | |
| autocmd FileType rust nmap <buffer> <leader>gr :YcmCompleter GoToReferences<CR> | |
| autocmd FileType rust nmap <buffer> <leader>gt :YcmCompleter GoToType<CR> | |
| autocmd FileType rust nmap <buffer> <leader>gd :YcmCompleter GetDoc<CR> | |
| autocmd FileType rust nmap <buffer> K :YcmCompleter GetDoc<CR> | |
| autocmd FileType rust nmap <buffer> <leader>rn :YcmCompleter RefactorRename<Space> | |
| autocmd FileType rust nmap <buffer> <leader>fx :YcmCompleter FixIt<CR> | |
| " Build / check | |
| autocmd FileType rust nmap <buffer> <leader>b :!cargo build<CR> | |
| autocmd FileType rust nmap <buffer> <leader>t :!cargo test<CR> | |
| autocmd FileType rust nmap <buffer> <leader>ck :!cargo check<CR> | |
| " Cargo quickfix integration | |
| autocmd FileType rust setlocal makeprg=cargo\ check | |
| autocmd FileType rust setlocal errorformat= | |
| \%-G, | |
| \%-Gerror:\ aborting\ %.%#, | |
| \%-Gerror:\ Could\ not\ compile\ %.%#, | |
| \%Eerror[E%n]:\ %m, | |
| \%Eerror:\ %m, | |
| \%Wwarning:\ %m, | |
| \%Inote:\ %m, | |
| \%C\ %#-->\ %f:%l:%c | |
| augroup END | |
| " build_go_files is a custom function that builds or compiles the test file. | |
| " It calls :GoBuild if its a Go file, or :GoTestCompile if it's a test 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 | |
| " | |
| " mhr customizations | |
| " | |
| cab demo set guifont=Ubuntu\ Mono\ 14 | |
| cab normal set guifont=Ubuntu\ Mono\ 12 | |
| cab ww win 161 54:vs | |
| cab nw only:win 100 54 | |
| set nows wildmode=list:longest | |
| map Y :e# | |
| cab shc e ~/.bashrc | |
| cab vrc e ~/.vimrc | |
| cab alc e ~/.bash_aliases | |
| nn :bd | |
| nn :close | |
| nn ,, :ls:e # | |
| nn :res +6 | |
| nn :res -6 | |
| nnoremap <F5> :vimgrep '\<<C-R><C-W>\>' **/*.go:syntax on | |
| nnoremap <F6> :vimgrep '\<<C-R><C-W>\>' **/*.*:syntax on | |
| " nnoremap <F7> :vimgrep /\<<C-R><C-W>\>/ `find . -type f -name '*.go' \! -name '*_test.go'`<CR>:syntax on<CR> | |
| function! VimgrepWord() | |
| let pat = '\<' . expand('<cword>') . '\>' | |
| let files = [] | |
| for ext in ['py','go','sh','tf','rs'] | |
| call extend(files, globpath('.', '**/*.' . ext, 0, 1)) | |
| endfor | |
| call filter(files, 'v:val !~# ''/\.git/'' && | |
| \ v:val !~# ''/(^|/)node_modules/'' && | |
| \ v:val !~# ''/(^|/)(venv|\.venv)/'' && | |
| \ v:val !~# ''\*_test\.go$''') | |
| if empty(files) | |
| echo "No candidate files." | |
| return | |
| endif | |
| try | |
| execute 'silent vimgrep /' . escape(pat, '/') . '/ ' . | |
| \ join(map(files, 'fnameescape(v:val)')) | |
| catch /^Vim\%((\a\+)\)\=:E480/ | |
| echo "No matches for: " . pat | |
| cclose | return | |
| endtry | |
| endfunction | |
| nnoremap <F7> :call VimgrepWord()<CR> | |
| nnoremap ,. :e <c-r>=escape(expand("%:h"), "")<cr>/ | |
| autocmd BufNewFile,BufRead Makefile syntax on | |
| autocmd BufNewFile,BufRead Makefile set ts=3 sts=3 sw=3 | |
| autocmd BufNewFile,BufRead *.yaml syntax on | |
| autocmd BufNewFile,BufRead *.yaml set expandtab mls=0 ts=2 sts=2 sw=2 | |
| autocmd BufNewFile,BufRead *.md syntax on | |
| autocmd BufNewFile,BufRead *.md set expandtab mls=0 ts=4 sts=4 sw=4 | |
| autocmd BufNewFile,BufRead *.sql syntax on | |
| autocmd BufNewFile,BufRead *.sql set expandtab mls=0 ts=4 sts=4 sw=4 | |
| autocmd BufNewFile,BufRead *.rs syntax on | |
| autocmd BufNewFile,BufRead *.rs set expandtab mls=0 ts=4 sts=4 sw=4 | |
| autocmd BufNewFile,BufRead *.eml syntax on | |
| autocmd BufNewFile,BufRead *.eml set spell expandtab tabstop=3 shiftwidth=3 | |
| map <S-Insert> <MiddleMouse> | |
| map! <S-Insert> <MiddleMouse> | |
| " Preview window on the upper side of the window with 40% height, | |
| " hidden by default, ctrl-/ to toggle | |
| let g:fzf_preview_window = ['down:40%:hidden', 'ctrl-/'] | |
| nnoremap <silent> <Leader>f :Rg<CR> | |
| nnoremap <C-p> :Files<CR> | |
| set nofixendofline | |
| map ," ysiW" | |
| map ,' ysiW' | |
| map ,` ysiW` | |
| nnoremap ;; :let @" = expand("%:p:.")<Bar> let @+ = expand("%:p:.")<CR> | |
| " ── :CopyType — yank variable/expr type into register t ────────────── | |
| function! CopyType() abort | |
| " Use vim-go's synchronous info function if available | |
| try | |
| let l:type = go#lsp#GetInfo() | |
| catch | |
| echo "Could not get type info" | |
| return | |
| endtry | |
| let l:type = trim(l:type) | |
| if empty(l:type) | |
| echo "No type information" | |
| return | |
| endif | |
| let @t = l:type | |
| echo '@t → ' . @t | |
| endfunction | |
| command! CopyType call CopyType() | |
| nnoremap <leader>yt :CopyType<CR> | |
| " ── Jump to *type* definition ---------------------------------------------- | |
| " Command form | |
| command! -nargs=0 JumpType execute 'GoDefType' | |
| " Key mapping: press F2 | |
| nnoremap <silent> <F2> :GoDefType<CR> | |
| " Map only in Go buffers | |
| autocmd FileType go nnoremap <buffer> <silent> <F8> :GoFillStruct<CR> | |
| " (optional) also from Insert mode, then return to insert | |
| autocmd FileType go inoremap <buffer> <silent> <F8> <Esc>:GoFillStruct<CR>a | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment