Skip to content

Instantly share code, notes, and snippets.

@VonHeikemen
Created January 4, 2021 03:02
Show Gist options
  • Save VonHeikemen/fb4d6d5326a4b7c1ce9998955f6b148c to your computer and use it in GitHub Desktop.
Save VonHeikemen/fb4d6d5326a4b7c1ce9998955f6b148c to your computer and use it in GitHub Desktop.
simple vimrc
" ============================================================================ "
" === 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/
" If you don't like swap files, enable this
" set noswapfile
" 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
" Enable line numbers
set number
" Enable cursorline
set cursorline
" Better color support
if (has("termguicolors"))
set termguicolors
endif
" Enable syntax highlight
syntax enable
" Use spaces to indent
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
" Or just use tabs
" set tabstop=4
" 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
" ============================================================================ "
" === 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
noremap <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 === "
" ============================================================================ "
" 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment