Skip to content

Instantly share code, notes, and snippets.

@Jakobuz
Created March 18, 2019 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jakobuz/d37d374c905c726c71fbcbf5ed16fc41 to your computer and use it in GitHub Desktop.
Save Jakobuz/d37d374c905c726c71fbcbf5ed16fc41 to your computer and use it in GitHub Desktop.
My Vim rc file.
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
syntax on
filetype on
filetype plugin on
filetype indent on
behave mswin
runtime macros/matchit.vim
runtime macros/editexisting.vim
colorscheme wombat
" Set various options.
set backspace=indent,eol,start whichwrap+=<,>,[,] " Intuitive backspacing in insert mode.
set nobackup " Do not use backup files.
set history=1000 " Make a very large history.
set showcmd " Display incomplete commands.
set guioptions=e
set showtabline=2
set guifont=consolas
set number
set cursorline
set wrap
set nowritebackup
set numberwidth=6
set tabstop=5
set shiftwidth=5
set expandtab
set hidden
set wildmenu
set wildmode=list:longest
set scrolloff=3
set shortmess=atI
" Search options.
set hlsearch
set incsearch
set ignorecase
set smartcase
" Turn off the audible and visual bell.
autocmd GUIEnter * set visualbell t_vb=
" Start the application in fullscreen.
autocmd GUIEnter * simalt ~x
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo, so that I can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" Backspace in Visual mode deletes selection.
vnoremap <BS> d
" CTRL-X and SHIFT-Del are Cut.
vnoremap <C-X> "+x
vnoremap <S-Del> "+x
" CTRL-C and CTRL-Insert are Copy.
vnoremap <C-C> "+y
vnoremap <C-Insert> "+y
" CTRL-V and SHIFT-Insert are Paste.
map <C-V> "+gP
map <S-Insert> "+gP
cmap <C-V> <C-R>+
cmap <S-Insert> <C-R>+
" Pasting blockwise and linewise selections is not possible in Insert and Visual mode without the +virtualedit feature. They are pasted as if they were characterwise instead. Uses the paste.vim autoload script.
exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']
imap <S-Insert> <C-V>
vmap <S-Insert> <C-V>
" Use CTRL-Q to do what CTRL-V used to do.
noremap <C-Q> <C-V>
" Use CTRL-S for saving, also in Insert mode.
noremap <C-S> :update<CR>
vnoremap <C-S> <C-C>:update<CR>
inoremap <C-S> <C-O>:update<CR>
" CTRL-Z is Undo; not in cmdline though.
noremap <C-Z> u
inoremap <C-Z> <C-O>u
" Tab management keys.
nmap <C-p> :tabprevious<cr>
imap <C-p> <ESC>:tabprevious<cr>i
nmap <C-n> :tabnext<cr>
imap <C-n> <ESC>:tabnext<cr>i
nmap <C-t> :tabnew<cr>
imap <C-t> <ESC>:tabnew<cr>i
" :noh remapping.
nnoremap <esc> :noh<cr><esc>
" Remap the tic mark so it jumps to the exact column and line when going back.
nnoremap ' `
nnoremap ` '
" Make the scrolling a little faster.
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" Ctrl-Space is System menu.
if has("gui")
noremap <C-Space> :simalt ~<CR>
inoremap <C-Space> <C-O>:simalt ~<CR>
cnoremap <C-Space> <C-C>:simalt ~<CR>
endif
" CTRL-A is Select all.
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G
xnoremap <C-A> <C-C>ggVG
" CTRL-Tab is Next window.
noremap <C-Tab> <C-W>w
inoremap <C-Tab> <C-O><C-W>w
cnoremap <C-Tab> <C-C><C-W>w
onoremap <C-Tab> <C-C><C-W>w
" CTRL-F4 is Close window.
noremap <C-F4> <C-W>c
inoremap <C-F4> <C-O><C-W>c
cnoremap <C-F4> <C-C><C-W>c
onoremap <C-F4> <C-C><C-W>c
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
" Set the gui to look great.
map <silent> <M-m> :if &guioptions =~# 'T' <Bar>
\set guioptions-=T <Bar>
\set guioptions-=m <bar>
\else <Bar>
\set guioptions+=T <Bar>
\set guioptions+=m <Bar>
\endif<CR>
" Map the leader key to a comma.
let mapleader = ","
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment