Last active
December 1, 2025 04:53
-
-
Save Aadv1k/ec7dbe9e0d2ef5c50c9613020503527c to your computer and use it in GitHub Desktop.
A minimal, yet highly functional `.vimrc` I use everywhere (windows, linux, gvim)
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
| syntax on | |
| let mapleader=" " | |
| " https://stackoverflow.com/questions/69145357/vim-almost-hangs-with-100-line-typescript-file | |
| set regexpengine=0 | |
| filetype plugin indent on | |
| set colorcolumn=80 | |
| set nu | |
| set guicursor= | |
| set smartindent autoindent | |
| set expandtab | |
| set tabstop=4 softtabstop=4 | |
| set shiftwidth=4 | |
| set hidden | |
| set noerrorbells | |
| set belloff=all | |
| set noswapfile | |
| set ttimeoutlen=100 | |
| set termguicolors | |
| set background=dark | |
| color retrobox | |
| set incsearch | |
| set nohlsearch | |
| set smartcase | |
| set ignorecase | |
| set scrolloff=8 | |
| set wrap | |
| set formatoptions-=cro | |
| set encoding=utf-8 | |
| set splitbelow | |
| set splitright | |
| let g:netrw_liststyle=3 | |
| let g:netrw_banner=0 | |
| let g:netrw_browse_split=2 | |
| let g:netrw_winsize=25 | |
| function! MkNote() | |
| let notesDir = '~/Documents/notes' | |
| let noteNameDelim = '-' | |
| let noteExt = '.txt' | |
| call inputsave() | |
| let rawNoteName = trim(input('MkNote>')) | |
| call inputrestore() | |
| if empty(rawNoteName) | |
| return | |
| endif | |
| let noteName = strftime('%d%m%y') . noteNameDelim . join(split(rawNoteName), noteNameDelim) | |
| let notePath = notesDir . '/' . noteName . noteExt | |
| execute 'new ' . notePath | |
| endfunction | |
| nnoremap <leader>nt <cmd>call MkNote()<CR> | |
| function! SetIndent(indent) | |
| set tabstop=a:indent softtabstop=a:indent shiftwidth=a:indent | |
| endfunction | |
| function! Format(givenCommand) | |
| let currentFile = expand('%:r') | |
| silent execute '!' . a:givenCommand . ' ' . currentFile | |
| edit! | |
| endfunction | |
| let g:pluginPath = glob('~') .. "/.vim/pack/user/opt/" | |
| function! EnsureInstalled(pluginSource, pluginName, alias = a:pluginName) | |
| if !isdirectory(g:pluginPath) | |
| call mkdir(g:pluginPath, 'p') | |
| endif | |
| let l:pluginDir = g:pluginPath .. a:alias | |
| if isdirectory(l:pluginDir) | |
| return | |
| endif | |
| call mkdir(l:pluginDir, 'p') | |
| let l:gitCmd = "git clone --depth=1 [email protected]:" .. trim(a:pluginSource) .. "/" .. trim(a:pluginName) .. " " .. l:pluginDir | |
| let l:result = system(l:gitCmd) | |
| if v:shell_error != 0 | |
| echom "[FAIL] Could not install " .. a:pluginSource .. "/" .. a:pluginName .. " " .. l:result | |
| else | |
| echom "[SUCCESS] Installed " .. a:pluginSource .. "/" .. a:pluginName | |
| endif | |
| endfunction | |
| function! Execute(runA, runB='') | |
| let currentFile = expand('%') | |
| let cmdA = '!' . a:runA . ' ' . currentFile | |
| if empty(a:runB) | |
| execute cmdA | |
| else | |
| let cmdB = '!' . a:runB . ' ' . currentFile | |
| execute cmdA . ' && ' . cmdB | |
| endif | |
| endfunction | |
| augroup ProseMode | |
| autocmd! | |
| autocmd FileType markdown setlocal spell spelllang=en_us wrap nonumber | |
| autocmd FileType markdown setlocal textwidth=999 | |
| augroup END | |
| augroup RustMode | |
| autocmd! | |
| autocmd FileType rust nmap <silent> <Leader>js :execute '!rustc ' . expand('%') . ' && ./' . expand('%:r') <CR> | |
| autocmd FileType rust nmap <silent> <Leader>fmt <cmd>call Format('rustfmt')<CR> | |
| augroup END | |
| augroup HtmlMode | |
| autocmd! | |
| autocmd FileType javascript,javascriptreact,markdown,css,html,json,typescript nmap <silent> <Leader>fmt <cmd>call Format('prettier --write')<CR> | |
| autocmd FileType typescript nmap <silent> <Leader>js <cmd>call Execute('tsc', 'node')<CR> | |
| autocmd FileType html,jsx nmap <CR> <c-y>, | |
| autocmd FileType javascript nmap <Leader>js <cmd>call Execute('node')<CR> | |
| augroup END | |
| augroup PyMode | |
| autocmd! | |
| autocmd FileType python nmap <silent> <Leader>fmt <cmd>call Format('python3 -m autopep8 --in-place --aggressive')<CR> | |
| autocmd FileType python nmap <Leader>js <cmd>call Execute('python3')<CR> | |
| augroup END | |
| augroup CppMode | |
| autocmd! | |
| autocmd FileType c nmap <silent> <Leader>js :execute '!gcc % -o ' . expand('%:r') . ' && ./' . expand('%:r') <CR> | |
| autocmd FileType cpp nmap <silent> <Leader>js :execute '!g++ % -o' . expand('%:r') . ' && ./' . expand('%:r') <CR> | |
| autocmd FileType c nmap <silent> <Leader>fmt <cmd>call Format('clang-format')<CR> | |
| augroup END | |
| augroup LuaMode | |
| autocmd! | |
| autocmd FileType lua nnoremap <Leader>js <cmd>call Execute('lua')<CR> | |
| augroup END | |
| """"""""""""""""""""""" | |
| """"""""""""""""""""""" | |
| """"""""Plugins"""""""" | |
| """"""""""""""""""""""" | |
| """"""""""""""""""""""" | |
| runtime! ftplugin/man.vim | |
| set laststatus=2 | |
| call EnsureInstalled("tpope", "vim-surround") | |
| packadd! vim-surround | |
| call EnsureInstalled("junegunn", "fzf") | |
| packadd! fzf | |
| call EnsureInstalled("junegunn", "fzf.vim") | |
| packadd! fzf.vim | |
| nnoremap <C-p> <cmd>Files<CR> | |
| """"""""""""""""""""""" | |
| """"""""""""""""""""""" | |
| """"""""Keymaps"""""""" | |
| """"""""""""""""""""""" | |
| """"""""""""""""""""""" | |
| nmap <silent> <leader>e <cmd>Vexplore<CR> | |
| nmap <silent> <leader>sp <cmd>split<CR> | |
| nmap <silent> <leader>vsp <cmd>vsplit<CR> | |
| nmap ]e <cmd>cnext<CR> | |
| nmap [e <cmd>cprevious<CR> | |
| inoremap , ,<c-g>u | |
| inoremap . .<c-g>u | |
| inoremap ( (<c-g>u | |
| " this doesn't work unfortunately | |
| nmap <C-S-Right> :vertical res +2 <CR> | |
| nmap <C-S-Left> :vertical res -2 <CR> | |
| nmap <C-S-Up> :res +2 <CR> | |
| nmap <C-S-Down> :res -2 <CR> | |
| nnoremap <Tab> :tabn<CR> | |
| nnoremap J mzJ`z | |
| nnoremap n nzzzv | |
| nnoremap N Nzzzv | |
| noremap j gj | |
| noremap k gk | |
| nnoremap Y y$ | |
| vnoremap > >gv | |
| vnoremap < <gv | |
| vnoremap J :m '>+1<CR>gv=gv | |
| vnoremap K :m '<-2<CR>gv=gv | |
| cnoreabbrev man Man | |
| cnoreabbrev W w | |
| cnoreabbrev Wq wq | |
| cnoreabbrev WQ wq | |
| cnoreabbrev Q q | |
| cnoreabbrev so so % |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment