Skip to content

Instantly share code, notes, and snippets.

@Aadv1k
Last active February 23, 2024 06:10
Show Gist options
  • Save Aadv1k/ec7dbe9e0d2ef5c50c9613020503527c to your computer and use it in GitHub Desktop.
Save Aadv1k/ec7dbe9e0d2ef5c50c9613020503527c to your computer and use it in GitHub Desktop.
A minimal, yet highly functional `.vimrc` I use everywhere (windows, linux, gvim)
syntax on
if has("gui_running")
set guifont=Iosevka\ Curly:h12
set guioptions-=m
set guioptions-=T
set guioptions-=r
endif
set background=dark
if v:version >= 900 && has("gui_running")
colorscheme retrobox
else
colorscheme wildcharm
endif
let mapleader=" "
let g:text_width = 100
exec 'set textwidth=' . g:text_width
exec 'set colorcolumn=' . g:text_width
set noerrorbells
set belloff=all
set backspace=2
set nu
set guicursor=
set smartindent autoindent
set expandtab
set tabstop=4 softtabstop=4
set shiftwidth=4
set hidden
set noerrorbells
set incsearch
set nohlsearch
set smartcase
set ignorecase
set nowrap
set scrolloff=8
set formatoptions-=cro
set encoding=utf-8
let g:netrw_liststyle=3
let g:netrw_banner=0
let g:netrw_browse_split=2
let g:netrw_winsize=80
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
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 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('python')<CR>
augroup END
augroup CppMode
autocmd!
autocmd FileType c nmap <silent> <Leader>cc :execute '!gcc % -o ' . expand('%:r') . ' && ./' . expand('%:r') <CR>
autocmd FileType cpp nmap <silent> <Leader>cc :execute '!g++ % -o' . expand('%:r') . ' && ./' . expand('%:r') <CR>
augroup END
augroup LuaMode
autocmd!
autocmd FileType lua nnoremap <Leader>js <cmd>call Execute('lua')<CR>
augroup END
"""""""""""""""""""""""
"""""""""""""""""""""""
""""""""Keymaps""""""""
"""""""""""""""""""""""
"""""""""""""""""""""""
tmap <Esc> <C-\><C-n>
"" Copying and pasting in the terminal, gVim debauchery
tmap <C-v> <C-W>"+
nmap <silent> <S-l> :tabn<CR>
nmap <silent> <S-h> :tabp<CR>
inoremap , ,<c-g>u
inoremap . .<c-g>u
inoremap ( (<c-g>u
nmap <C-Right> :vertical res +2 <CR>
nmap <C-Left> :vertical res -2 <CR>
nmap <C-Up> :res +2 <CR>
nmap <C-Down> :res -2 <CR>
nmap cs'" vi'"aydi'vhr""ap
nmap cs"' vi""aydi"vhr'"ap
nmap ds" mavi""aydi"xx"ap`a
nnoremap J mzJ`z
nnoremap n nzzzv
nnoremap N Nzzzv
nnoremap Y y$
vnoremap > >gv
vnoremap > >gv
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
imap <c-space> <c-p>
" wow!
cnoremap ;; <c-f>
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