Skip to content

Instantly share code, notes, and snippets.

@airstrike
Created February 22, 2025 21:50
Show Gist options
  • Save airstrike/2fbbd6a59f42b4283d80fb166510b0f4 to your computer and use it in GitHub Desktop.
Save airstrike/2fbbd6a59f42b4283d80fb166510b0f4 to your computer and use it in GitHub Desktop.
latest .vimrc (works in vim and VSCode)
" VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the curors - when moving vertical..
set so=4
set ruler "Always show current position
set cmdheight=1 "The commandbar height
" Set backspace config
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set ignorecase "Ignore case when searching
set smartcase
set hlsearch "Highlight search things
set incsearch "Make search act like search in modern browsers
set nolazyredraw "Don't redraw while executing macros
set magic "Set magic on, for regular expressions
set showmatch "Show matching bracets when text indicator is over them
" No sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=utf8
try
lang en_US
catch
endtry
set ffs=unix,mac,dos "Default file types
" tab, spacing, wrapping
set expandtab
set shiftwidth=4
set tabstop=4
set smarttab
set ai
set si
set nowrap
set autoread
" General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700
" Enable filetype plugin
filetype plugin on
filetype indent on
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","
" Fast saving
nnoremap <leader>w :w!<cr>
" Close buffer
nnoremap <leader>q :bdelete<cr>
" Fast buffer switching
nnoremap <leader>, :bprev<cr>
nnoremap <leader>. :bnext<cr>
nnoremap <leader>q :bwipeout<cr>
" Fast cargo run
nnoremap <leader>x :!clear && cargo run<cr>
nnoremap <leader>c :!cargo run<cr>
" Fast editing of the .vimrc
nnoremap <leader>e :e ~/.vimrc<cr>
" When vimrc is edited, reload it
autocmd! bufwritepost .vimrc source ~/.vimrc
" key mappings
nnoremap <silent> <CR> :noh<CR><CR>
" smarter moving around
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Statusline
""""""""""""""""""""""""""""""
" Always hide the statusline
set laststatus=2
" Format the statusline
" set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c
function! HasPaste()
if &paste
return 'PASTE MODE '
else
return ''
endif
endfunction
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
noremap <Leader>t :%s/\t/ /ge<cr>
" Remove any trailing whitespace that is in the file
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif
" Restore cursor position to where it was before
augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand("<afile>:p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ let JumpCursorOnEdit_foo = line("'\"") |
\ let b:doopenfold = 1 |
\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
\ let b:doopenfold = 2 |
\ endif |
\ exe JumpCursorOnEdit_foo |
\ endif |
\ endif
" Need to postpone using "zv" until after reading the modelines.
autocmd BufWinEnter *
\ if exists("b:doopenfold") |
\ exe "normal zv" |
\ if(b:doopenfold > 1) |
\ exe "+".1 |
\ endif |
\ unlet b:doopenfold |
\ endif
augroup END
" Misc Settings
" Necesary for lots of cool vim things
set nocompatible
" This shows what you are typing as a command. I love this!
set showcmd
" Folding Stuffs
set foldmethod=marker
" Needed for Syntax Highlighting and stuff
filetype on
filetype plugin on
syntax enable
set grepprg=grep\ -nH\ $*
" Cool tab completion stuff
set wildmenu
set wildmode=list:longest,full
" Line Numbers PWN!
set number
" This is totally awesome - remap jj to escape in insert mode. You'll never type jj anyway, so it's great!
inoremap jj <Esc>
nnoremap JJJJ <Nop>
"{{{ Paste Toggle
let paste_mode = 0 " 0 = normal, 1 = paste
func! Paste_on_off()
if g:paste_mode == 0
set paste
let g:paste_mode = 1
echo "Paste ON"
else
set nopaste
let g:paste_mode = 0
echo "Paste OFF"
endif
return
endfunc
"}}}
nnoremap <Leader>p :call Paste_on_off()<CR>
" Up and down are more logical with g..
inoremap <silent> <Up> <Esc>gka
inoremap <silent> <Down> <Esc>gja
" Create Blank Newlines and stay in Normal mode
nnoremap <silent> zj o<Esc>
nnoremap <silent> zk O<Esc>
" Space will toggle folds!
nnoremap <space> za
" 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.
map N Nzz
map n nzz
" Testing
set completeopt=longest,menuone,preview
" Swap ; and : Convenient.
nnoremap ; :
nnoremap : ;
vnoremap ; :
vnoremap : ;
" removing selectmode
set selectmode=
" colorscheme default
" easier copy/paste into system clipboard
set mouse= " to enable right-click paste
noremap <Leader>y "*y
noremap <Leader>p "*p
noremap <Leader>Y "+y
noremap <Leader>P "+p
vnoremap <Leader>$ c$$<Esc>Pll
nnoremap <Leader>$ cl$$<Esc>Pll
vnoremap <Leader>b c****<Esc>hPlll
nnoremap <Leader>b ce****<Esc>hPlll
vnoremap <Leader>i c**<Esc>Pll
nnoremap <Leader>i ce**<Esc>Pll
vnoremap <Leader>` c``<Esc>Pll
nnoremap <Leader>` ce``<Esc>Pll
nnoremap <Leader>s${ v$S{
nnoremap <Leader>s$" v$S"
nnoremap <Leader>s$' v$S'
nnoremap <Leader>sw{ ysiw{
nnoremap <Leader>sW{ ysiW{
nnoremap <Leader>ss{ yss{
nnoremap <Leader>s$} v$S}
nnoremap <Leader>sw} ysiw}
nnoremap <Leader>sW} ysiW}
nnoremap <Leader>ss} yss}
vnoremap <Leader>{ c{}<Esc>P
nnoremap <Leader>s$( v$S(
nnoremap <Leader>sw( ysiw(
nnoremap <Leader>sW( ysiW(
nnoremap <Leader>ss( yss(
nnoremap <Leader>s$) v$S)
nnoremap <Leader>sw) ysiw)
nnoremap <Leader>sW) ysiW)
nnoremap <Leader>ss) yss)
" darcula theme
set termguicolors
if v:version < 802
packadd! dracula
endif
syntax enable
colorscheme dracula
hi Normal guibg=NONE ctermbg=NONE
hi User1 guifg=#e0f0ff guibg=#2a1f5c " Light blueish indigo text on dark blueish indigo background
hi User2 guifg=#d0e7ff guibg=#34426f " Slightly lighter blueish indigo
hi User3 guifg=#c0deff guibg=#3d6482 " Midpoint between blue indigo and pastel
hi User4 guifg=#b0d6ef guibg=#478593 " Smooth transition towards pastel tones
hi User5 guifg=#a0cfcf guibg=#51989f " More pastel, slightly grayish
hi User6 guifg=#90c9c9 guibg=#5ca4a5 gui=bold " Light pastel, balanced mix
hi User7 guifg=#80c2c2 guibg=#67ada7 " Lighter pastel text on slightly darker pastel background
hi User8 guifg=#70bbbb guibg=#71b4a5 " Soft pastel teal transitioning to proper teal
hi User9 guifg=#60b3b3 guibg=#008180 " Light teal text on a proper teal background
set statusline=%l,%c\ [%b]\ %P
set statusline=
set statusline+=%1*\[%n] "buffernr
set statusline+=%1*\ %<%F\ "File+path
set statusline+=%2*\ %y\ "FileType
set statusline+=%3*\ %{''.(&fenc!=''?&fenc:&enc).''} "Encoding
set statusline+=%3*\ %{(&bomb?\",BOM\":\"\")}\ "Encoding2
set statusline+=%4*\ %{&ff}\ "FileFormat (dos/unix..)
set statusline+=%5*\ %{&spelllang}\%{HighlightSearch()}\ "Spellanguage & Highlight on?
set statusline+=%6*\ %=\ row:%l/%L\ "Rownumber/total
set statusline+=%7*\ (%{CharPos()})\ "Character position
set statusline+=%8*\ col:%03c\ "Colnr
set statusline+=%9*\ \ %m%r%w\ %P\ \ "Modified? Readonly? Top/bot.
function! HighlightSearch()
if &hls
return 'H'
else
return ''
endif
endfunction
function! CharPos()
" Subtract 1 because line2byte() returns the position just after the newline
return line2byte(line(".")) + col(".") - 1
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment