Skip to content

Instantly share code, notes, and snippets.

@VonHeikemen
Last active March 21, 2024 11:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VonHeikemen/b4b07c77995b52bfb22793df58a44ce3 to your computer and use it in GitHub Desktop.
Save VonHeikemen/b4b07c77995b52bfb22793df58a44ce3 to your computer and use it in GitHub Desktop.
make vim into a nice editor with this completely pluginless rc
" ============================================================================ "
" === EDITING OPTIONS === "
" ============================================================================ "
" Don't include vi compatibility
set nocompatible
" Sensible backspace
set backspace=indent,eol,start
" Temp files directory
set backupdir=~/.vim/tmp/
set directory=~/.vim/tmp/
" Autosave when navigating between buffers
set autowrite
" Automatically re-read file if a change was detected outside of vim
set autoread
" Preserve state (undo, marks, etc) in non visible buffers
set hidden
" Enable incremental search
set incsearch
" Ignore the case when the search pattern is all lowercase
set ignorecase
set smartcase
" Mouse support
set mouse=a
" Better color support
if (has("termguicolors"))
set termguicolors
endif
" Use spaces to indent
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
" When opening a window put it right or below the current one
set splitright
set splitbelow
" Keep lines below cursor when scrolling
set scrolloff=2
set sidescrolloff=5
" Disable line wrapping
set nowrap
" Disable cursorline
set nocursorline
" Enable relative numbers
set relativenumber
" Disable search highlight
set nohlsearch
" ============================================================================ "
" === KEY MAPPINGS === "
" ============================================================================ "
" Leader key
let mapleader = "\<Space>"
" Escape to normal mode
noremap <C-L> <Esc>
inoremap <C-L> <Esc>
" Go to normal mode from terminal mode
tnoremap <C-L> <C-\><C-n>
" Select all text in current buffer
nnoremap <Leader>a ggvGg_
" Go to matching pair
nmap <Leader>e %
xmap <Leader>e %
" Go to first character in line
noremap <Leader>h ^
" Go to last character in line
noremap <Leader>l g_
" Scroll half page and center
noremap <C-u> <C-u>M
noremap <C-d> <C-d>M
" Search will center on the line it's found in.
nnoremap n nzzzv
nnoremap N Nzzzv
nnoremap # #zz
nnoremap * *zz
" ============================================================================ "
" === COMMAND MAPPINGS === "
" ============================================================================ "
" Safe quit
nnoremap <Leader>qq :quitall<CR>
" Force quit
nnoremap <Leader>Q :quitall!<CR>
" Write file
nnoremap <Leader>w :write<CR>
" Close buffer
nnoremap <Leader>bq :bdelete<CR>
" Move to last active buffer
nnoremap <Leader>bl :buffer #<CR>
" Navigate between buffers
nnoremap [b :bprevious<CR>
nnoremap ]b :bnext<CR>
" Open new tabpage
nnoremap <Leader>tn :tabnew<CR>
" Navigate between tabpages
nnoremap [t :tabprevious<CR>
nnoremap ]t :tabnext<CR>
" Clear messages
nnoremap <Leader><space> :echo ''<CR>
" Begin search & replace
nnoremap <Leader>r :%s///gc<Left><Left><Left><Left>
xnoremap <Leader>r :s///gc<Left><Left><Left><Left>
" Moving lines and preserving indentation
nnoremap <C-j> :move .+1<CR>==
nnoremap <C-k> :move .-2<CR>==
vnoremap <C-j> :move '>+1<CR>gv=gv
vnoremap <C-k> :move '<-2<CR>gv=gv
" ============================================================================ "
" === QUICKFIX LIST === "
" ============================================================================ "
" Add errorformat to update quickfix list
set errorformat+=%f\|%l\ col\ %c\|%m
" Go to previous location
nnoremap [q :cprev<CR>
" Go to next location
nnoremap ]q :cnext<CR>
" Manage the quickfix window
nnoremap <Leader>cc :cclose<CR>
nnoremap <Leader>co :copen<CR>
function! QuickfixMapping()
" Go to next location and stay in the quickfix window
nnoremap <buffer> K :cprev<CR>zz<C-w>w
" Go to previous location and stay in the quickfix window
nnoremap <buffer> J :cnext<CR>zz<C-w>w
" Make the quickfix list modifiable
nnoremap <buffer> <Leader>u :set modifiable<CR>
" Update quickfix window
nnoremap <buffer> <Leader>w :cgetbuffer<CR>:cclose<CR>:copen<CR>
endfunction
augroup quickfix_mapping
autocmd!
" Setup keymaps
autocmd filetype netrw call QuickfixMapping()
augroup END
" ============================================================================ "
" === NETRW === "
" ============================================================================ "
" Open Netrw in directory of the current buffer
nnoremap <leader>dd :Lexplore %:p:h<CR>
" Toggle Netrw
nnoremap <leader>da :Lexplore<CR>
" Take 30% of the screen
let g:netrw_winsize = 30
" Sync current directory and browsing directory
" This solves the problem with the 'move' command
let g:netrw_keepdir = 0
" Hide banner
let g:netrw_banner = 0
" Hide dotfiles
let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'
" A better copy command
let g:netrw_localcopydircmd = 'cp -r'
" Delete a non-empty directory
function! NetrwRemoveRecursive()
if &filetype ==# 'netrw'
" Prepare the delete command.
" Make it so that is triggered by just pressing Enter
cnoremap <buffer> <CR> rm -r<CR>
" Unmark all files (don't want to delete anything by accident)
normal mu
" Mark the file/directory under the cursor
normal mf
" Show the prompt to enter the command
" In here you either press Enter to confirm
" or press ctrl + c to abort.
" Don't do anything else!
try
normal mx
catch
echo "Canceled"
endtry
" Undo the Enter keymap
cunmap <buffer> <CR>
endif
endfunction
" Better keymaps for Netrw
function! NetrwMapping()
" Close Netrw window
nmap <buffer> <leader>dd :Lexplore<CR>
nmap <buffer> <leader>[ :let g:netrw_winsize = 30<CR><C-w>q:Lexplore<CR>
nmap <buffer> <leader>] :let g:netrw_winsize = 50<CR><C-w>q:Lexplore<CR>
" Go to file and close Netrw window
nmap <buffer> L <CR>:Lexplore<CR>
" Go back in history
nmap <buffer> H u
" Go up a directory
nmap <buffer> h -^
" Go down a directory / open file
nmap <buffer> l <CR>
" Toggle dotfiles
nmap <buffer> . gh
" Toggle the mark on a file
nmap <buffer> <TAB> mf
" Unmark all files in the buffer
nmap <buffer> <S-TAB> mF
" Unmark all files
nmap <buffer> <Leader><TAB> mu
" 'Bookmark' a directory
nmap <buffer> bb mb
" Delete the most recent directory bookmark
nmap <buffer> bd mB
" Got to a directory on the most recent bookmark
nmap <buffer> bl gb
" Create a file
nmap <buffer> ff %:w<CR>:buffer #<CR>
" Rename a file
nmap <buffer> fe R
" Copy marked files
nmap <buffer> fc mc
" Copy marked files in the directory under cursor
nmap <buffer> fC mtmc
" Move marked files
nmap <buffer> fx mm
" Move marked files in the directory under cursor
nmap <buffer> fX mtmm
" Execute a command on marked files
nmap <buffer> f; mx
" Show the list of marked files
nmap <buffer> fl :echo join(netrw#Expose("netrwmarkfilelist"), "\n")<CR>
" Show the current target directory
nmap <buffer> fq :echo 'Target:' . netrw#Expose("netrwmftgt")<CR>
" Set the directory under the cursor as the current target
nmap <buffer> fd mtfq
" Delete a file
nmap <buffer> FF :call NetrwRemoveRecursive()<CR>
" Close the preview window
nmap <buffer> P <C-w>z
endfunction
augroup netrw_mapping
autocmd!
autocmd filetype netrw call NetrwMapping()
augroup END
" ============================================================================ "
" === COLORSCHEME === "
" ============================================================================ "
" rubber-enhanced colorscheme taken from:
" https://github.com/VonHeikemen/rubber-themes.vim
syntax enable
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
let s:black = {"gui": "#2F343F", "cterm": "236"}
let s:white = {"gui": "#DCE0DD", "cterm": "253"}
let s:red = {"gui": "#FC8680", "cterm": "210"}
let s:magenta = {"gui": "#DDA0DD", "cterm": "182"}
let s:blue = {"gui": "#89C4F4", "cterm": "117"}
let s:cyan = {"gui": "#50C6D8", "cterm": "80" }
let s:green = {"gui": "#87D37C", "cterm": "114"}
let s:yellow = {"gui": "#F2CA27", "cterm": "220"}
let s:gray = {"gui": "#8893A6", "cterm": "103"}
let s:dark_gray = {"gui": "#939393", "cterm": "246"}
let s:wild_red = {"gui": "#DF334A", "cterm": "167"}
let s:bright_black = {"gui": "#5F6672", "cterm": "242"}
let s:bright_white = {"gui": "#DADFE1", "cterm": "253"}
" Constants
let s:none = {"gui": "NONE", "cterm": "NONE"}
let s:foreground = s:white
let s:comment = s:red
let s:constant = s:magenta
let s:storage = s:blue
let s:string = s:green
let s:special = s:dark_gray
let s:error = s:wild_red
" Highlight utility function
" https://github.com/noahfrederick/vim-hemisu/
" Usage: call s:h("", {"fg": s:none, "bg": s:none})
function! s:h(group, style)
execute "highlight" a:group
\ "guifg=" (has_key(a:style, "fg") ? a:style.fg.gui : "NONE")
\ "guibg=" (has_key(a:style, "bg") ? a:style.bg.gui : "NONE")
\ "guisp=" (has_key(a:style, "sp") ? a:style.sp.gui : "NONE")
\ "gui=" (has_key(a:style, "gui") ? a:style.gui : "NONE")
\ "ctermfg=" (has_key(a:style, "fg") ? a:style.fg.cterm : "NONE")
\ "ctermbg=" (has_key(a:style, "bg") ? a:style.bg.cterm : "NONE")
\ "cterm=" (has_key(a:style, "cterm") ? a:style.cterm : "NONE")
endfunction
call s:h("NonText", {"fg": s:dark_gray, "bg": s:none })
call s:h("CursorLineNr", {"fg": s:none, "bg": s:none })
call s:h("LineNr", {"fg": s:dark_gray, "bg": s:none })
call s:h("WildMenu", {"fg": s:black, "bg": s:yellow })
call s:h("PMenu", {"fg": s:black, "bg": s:gray })
call s:h("PMenuSel", {"fg": s:none, "bg": s:black })
call s:h("Visual", {"fg": s:black, "bg": s:gray })
call s:h("Search", {"fg": s:black, "bg": s:yellow })
call s:h("IncSearch", {"fg": s:black, "bg": s:yellow })
call s:h("Comment", {"fg": s:comment, "bg": s:none })
call s:h("String", {"fg": s:string, "bg": s:none })
call s:h("Character", {"fg": s:constant, "bg": s:none })
call s:h("Number", {"fg": s:constant, "bg": s:none })
call s:h("Boolean", {"fg": s:constant, "bg": s:none })
call s:h("Float", {"fg": s:constant, "bg": s:none })
call s:h("Function", {"fg": s:storage, "bg": s:none })
call s:h("Special", {"fg": s:special, "bg": s:none })
call s:h("SpecialChar", {"fg": s:special, "bg": s:none })
call s:h("Error", {"fg": s:none, "bg": s:error})
call s:h("Constant", {"fg": s:none, "bg": s:none })
call s:h("Statement", {"fg": s:none, "bg": s:none })
call s:h("Conditional", {"fg": s:none, "bg": s:none })
call s:h("Exception", {"fg": s:none, "bg": s:none })
call s:h("Identifier", {"fg": s:none, "bg": s:none })
call s:h("Type", {"fg": s:none, "bg": s:none })
call s:h("Repeat", {"fg": s:none, "bg": s:none })
call s:h("Label", {"fg": s:none, "bg": s:none })
call s:h("Operator", {"fg": s:none, "bg": s:none })
call s:h("Keyword", {"fg": s:none, "bg": s:none })
call s:h("Delimiter", {"fg": s:none, "bg": s:none })
call s:h("Tag", {"fg": s:none, "bg": s:none })
call s:h("SpecialComment", {"fg": s:none, "bg": s:none })
call s:h("Debug", {"fg": s:none, "bg": s:none })
call s:h("PreProc", {"fg": s:none, "bg": s:none })
call s:h("Include", {"fg": s:none, "bg": s:none })
call s:h("Define", {"fg": s:none, "bg": s:none })
call s:h("Macro", {"fg": s:none, "bg": s:none })
call s:h("PreCondit", {"fg": s:none, "bg": s:none })
call s:h("StorageClass", {"fg": s:none, "bg": s:none })
call s:h("Structure", {"fg": s:none, "bg": s:none })
call s:h("Typedef", {"fg": s:none, "bg": s:none })
call s:h("Title", {"fg": s:none, "bg": s:none })
call s:h("Todo", {"fg": s:none, "bg": s:none })
if has("nvim")
let g:terminal_color_foreground = s:foreground.gui
let g:terminal_color_background = s:black.gui
" black
let g:terminal_color_0 = s:black.gui
let g:terminal_color_8 = s:bright_black.gui
" red
let g:terminal_color_1 = s:red.gui
let g:terminal_color_9 = s:red.gui
" green
let g:terminal_color_2 = s:green.gui
let g:terminal_color_10 = s:green.gui
" yellow
let g:terminal_color_3 = s:yellow.gui
let g:terminal_color_11 = s:yellow.gui
" blue
let g:terminal_color_4 = s:blue.gui
let g:terminal_color_12 = s:blue.gui
" magenta
let g:terminal_color_5 = s:magenta.gui
let g:terminal_color_13 = s:magenta.gui
" cyan
let g:terminal_color_6 = s:cyan.gui
let g:terminal_color_14 = s:cyan.gui
" white
let g:terminal_color_7 = s:white.gui
let g:terminal_color_15 = s:bright_white.gui
else
let g:terminal_ansi_colors = [
\ s:black.gui, s:red.gui, s:green.gui, s:yellow.gui,
\ s:blue.gui, s:magenta.gui, s:cyan.gui, s:white.gui,
\ s:bright_black.gui, s:red.gui, s:green.gui, s:yellow.gui,
\ s:blue.gui, s:magenta.gui, s:cyan.gui, s:bright_white.gui
\ ]
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment