Skip to content

Instantly share code, notes, and snippets.

@niko niko/vimrc
Created Mar 12, 2018

What would you like to do?
set nocompatible
set number
" show invisible characters:
set list
set listchars=tab:▸\ ,eol
set listchars+=trail:˙
" allow buffer changes without saving:
set hidden
syntax enable
filetype plugin indent on
set path+=** " :find … and :b …
set wildmenu
set wildmode=longest:full,full
set wildignore=*.swp,*.bak,*.pyc,*.class
set wildcharm=<C-z>
set history=10000 " remember more commands and search history
set undolevels=10000 " use many muchos levels of undo
set copyindent " copy the previous indentation on autoindenting
set scrolloff=1
" set cursorline " Highlight current line
" remember to autocomplete:
" everything: CTRL-n / CTRL-p
" filenames: CTRL-x CTRL-f
" file browsing:
let g:netrw_banner=0 " disable annoying banner
let g:netrw_browse_split=3 " open in prior window
let g:netrw_liststyle=3 " tree view
let g:netrw_list_hide=netrw_gitignore#Hide() " hide stuff in gitignore
let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+' " hide stuff in gitignore
let g:netrw_sort_sequence = '[\/]$,*' " sort directories on the top, files below
" let g:netrw_altv = 1
" absolute width of netrw window
let g:netrw_winsize = -28
" open file in a new tab
" Tab navigation like Firefox.
nnoremap <C-h> :tabprevious<CR>
nnoremap <C-l> :tabnext<CR>
nnoremap <C-t> :tabnew<CR>
inoremap <C-h> <Esc>:tabprevious<CR>i
inoremap <C-l> <Esc>:tabnext<CR>i
inoremap <C-t> <Esc>:tabnew<CR>
" jump to last position when opening a file:
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" no visual selection with mouse in normal/insert mode
set mouse=c
set showcmd
" search settings:
set incsearch " search as you type
set hlsearch " highligh search
set ignorecase " case insensitive search
set smartcase " case sensitive when uc present
set whichwrap=b,s,<,>,[,] " backspace and cursor keys wrap
nnoremap Y y$ " Yank from the cursor to the end of the line, to be consistent with C and D.
" visual shifting (does not exit Visual mode)
vnoremap < <gv
vnoremap > >gv
hi WarningMsg ctermfg=white ctermbg=red guifg=White guibg=Red gui=None
hi statusline guibg=DarkGrey ctermfg=8 guifg=White ctermbg=15
if has('statusline')
set laststatus=2
" Broken down into easily includeable segments:
set statusline=%{getcwd()}/%f\ " Path and filename
set statusline+=%w%h%m%r " Options
set statusline+=\ [%{&ff}/%Y] " Filetype
set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info
" persisted undos:
set undofile
set undodir=~/.vimtmp
set undolevels=1000
let mapleader = ","
" toggle *n*umbers, invisible chars and cursorline. good for mouse copy/paste:
nnoremap <Leader>n :set number! list! cursorline!<CR>
" switch buffer with ,b:
nnoremap <Leader>b :buffer <C-z><S-Tab>
nnoremap ;; :e#<cr>
" use the systems C-c/C-v clipboard in vim with y/p: (may not work on server)
set clipboard=unnamedplus
" prepend/del_first to/from selected lines:
vnoremap <Leader>> <C-v>0I
vnoremap <Leader>< <C-v>0x
" own filetype settings:
autocmd FileType * setlocal shiftwidth=2 tabstop=2
autocmd FileType html setlocal shiftwidth=2 tabstop=2
autocmd FileType javascript setlocal shiftwidth=4 tabstop=4
autocmd FileType ruby setlocal shiftwidth=2 tabstop=2 expandtab
" to avoid vim trying to "write" the netrw buffer:
autocmd FileType netrw setl bufhidden=delete
" qq - record macro
" q - stop recording macro
" Q - replay macro
nnoremap Q @q
vnoremap Q :norm @q<cr>
autocmd FileType go set noexpandtab
autocmd FileType go set shiftwidth=4
autocmd FileType go set softtabstop=4
autocmd FileType go set tabstop=4
" don't wrap emails:
" au BufRead /tmp/mutt-* set filetype=mail " this is done by default anyway
au BufRead *tmp/neomutt-* set filetype=mail
autocmd FileType mail set textwidth=0
autocmd FileType mail inoremap --<Space><CR> -- <CR><C-o>:read ~/.mutt/signatures/laut<CR>
augroup filetypedetect
" elixir is close enough to ruby:
au BufRead,BufNewFile *.exs set filetype=ruby
au BufRead,BufNewFile *.ex set filetype=ruby
augroup END
" incremental substitution
" try :%s/foo/bar/g
if has("nvim")
set inccommand=nosplit
if has("nvim")
" Terminal Mode
" Make escape work in the Neovim terminal.
tnoremap <Esc> <C-\><C-n>
" Make navigation into and out of Neovim terminal splits nicer.
tnoremap <C-h> <C-\><C-N><C-w>h
tnoremap <C-j> <C-\><C-N><C-w>j
tnoremap <C-k> <C-\><C-N><C-w>k
tnoremap <C-l> <C-\><C-N><C-w>l
" I like relative numbering when in normal mode.
" autocmd TermOpen * setlocal conceallevel=0 colorcolumn=0 relativenumber
" Prefer Neovim terminal insert mode to normal mode.
autocmd BufEnter term://* startinsert
if has('nvim-0.1.5') " True color in neovim wasn't added until 0.1.5
set termguicolors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.