My first .vimrc

1 Point

Jeff Rose Jeff Rose

1 month ago

This is my .vimrc as I first wrote it at the beginning of October 2017.

syntax on

filetype indent plugin on

"
" Package management (vim-plug)
"

call plug#begin('~/.vim/plugged')
Plug 'airblade/vim-gitgutter'
Plug 'ap/vim-buftabline'
Plug 'joshdick/onedark.vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'kudabux/vim-srcery-drk'
" Plug 'shawncplus/phpcomplete.vim'
Plug 't9md/vim-choosewin'
" Plug 'Valloric/YouCompleteMe'
Plug 'vim-airline/vim-airline'
Plug 'w0rp/ale'
call plug#end()

"
" Basics
"

" Colour scheme
colorscheme srcery-drk
" set background=dark " Comment this out for some schemes

" Editor
set number      " Show line numbers
set ruler       " Show the ruler

" Splits
" Note: Check the leader key shortcuts below for some commands that might
" conflict with these if you need to change these around...
set splitright  " Make vertical splits appear to the right
set splitbelow  " Make horizontal splits appear to the bottom

" Search
set hlsearch    " Highlight searched pattern 
set ignorecase  " Ignore case when pattern searching
set incsearch   " Refine search as each character is typed

" Backspace
set backspace=2 " Make backspace delete past where insert mode began

" Tab completion
set wildmode=longest,list,full
set wildmenu

" Indentation
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab   " Expand tabs into several spaces
set smarttab    " Tab to implied indentation depth automatically (I think?)
set nowrap      " Don't wrap text

"
" Filetype-specific settings
" 

autocmd Filetype html set wrap
autocmd Filetype log set wrap

"
" Key mapping
"

" Leader key
" let mapleader = "\<space>"

" Insert mode
imap jk <Esc>
imap kj <Esc>

" Visual-select mode
vmap <leader>y "+y

" Normal mode
nmap <leader>f :FZF<cr>
nmap <leader>a :Ag!<cr>
nmap <leader>s :Lines!<cr>
nmap <leader>d :BLines<cr>
nmap <leader>b :Buffers<cr>
nmap <leader>m :Marks<cr>
nmap <leader>g :GFiles?<cr>

" Clear search pattern
nmap <leader><cr> :nohl<cr>

" Buffers
nmap <leader>w :w<cr>
nmap <leader>q :bd<cr>
nmap <leader><Esc> :bd!<cr>
nmap <leader><BS><BS> :bufdo bd<cr>
nmap <leader><BS><BS><BS> :bufdo bd!<cr>
nmap <leader>1 <Plug>BufTabLine.Go(1)
nmap <leader>2 <Plug>BufTabLine.Go(2)
nmap <leader>3 <Plug>BufTabLine.Go(3)
nmap <leader>4 <Plug>BufTabLine.Go(4)
nmap <leader>5 <Plug>BufTabLine.Go(5)
nmap <leader>6 <Plug>BufTabLine.Go(6)
nmap <leader>7 <Plug>BufTabLine.Go(7)
nmap <leader>8 <Plug>BufTabLine.Go(8)
nmap <leader>9 <Plug>BufTabLine.Go(9)
nmap <leader>0 <Plug>BufTabLine.Go(0)

" Sessions
nmap <leader>,,, :mksession! ~/.vim/sessions/default<cr>
nmap <leader>... :source ~/.vim/sessions/default<cr>
nmap <leader>,, :mksession! ~/.vim/sessions/
nmap <leader>.. :source ~/.vim/sessions/

" Windows
nmap <leader>/ <Plug>(choosewin)
nmap <leader><right><right> :set splitright<cr> :vsplit<cr>
nmap <leader><down><down> :set splitbelow<cr> :split<cr>
nmap <leader><left><left> :set splitright&<cr> :vsplit<cr> :set splitright<cr>
nmap <leader><up><up> :set splitbelow&<cr> :split<cr> :set splitbelow<cr>

"
" ap/vim-buftabline
"

let g:buftabline_show = 2       " Always show
let g:buftabline_numbers = 2    " Ordinal from left-to-right

"
" junegunn/fzf
"

let g:fzf_layout = {
  \ 'down': '~40%'
  \ }

let g:fzf_colors = {
  \ 'fg':      ['fg', 'Normal'],
  \ 'bg':      ['bg', 'Normal'],
  \ 'hl':      ['fg', 'Comment'],
  \ 'fg+':     ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
  \ 'bg+':     ['bg', 'CursorLine', 'CursorColumn'],
  \ 'hl+':     ['fg', 'Statement'],
  \ 'info':    ['fg', 'PreProc'],
  \ 'border':  ['fg', 'Ignore'],
  \ 'prompt':  ['fg', 'Conditional'],
  \ 'pointer': ['fg', 'Exception'],
  \ 'marker':  ['fg', 'Keyword'],
  \ 'spinner': ['fg', 'Label'],
  \ 'header':  ['fg', 'Comment']
  \ }

"
" shauncplus/phpcomplete.vim
"

let g:phpcomplete_mappings = {
  \ 'jump_to_def': '<leader>z',
  \ }

"
" Valloric/YouCompleteMe
"

highlight Pmenu ctermfg=10 ctermbg=8

"
" vim-airline/vim-airline
"

let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
let g:airline_theme = 'onedark'
let g:airline#extensions#tabline#buffer_nr_show = 1

"
" w0rg/ale
"

" General
let g:ale_completion_enabled = 1
let g:ale_lint_on_text_changed = 1
let g:ale_set_highlights = 1

" phpcs
let g:ale_php_phpcs_executable = './bin/phpcs'
let g:ale_php_phpcs_standard = "psr4"
let g:ale_php_phpmd_ruleset = 'cleancode,codesize,controversial,design,unusedcode'

"
" netrw
"

let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 2
let g:netrw_altv = 0
let g:netrw_winsize = 20

"
" Functions
"

" Clear every register.
function! ClearRegisters()
    let regs='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-="*+'
    let i=0
    while (i<strlen(regs))
        exec 'let @'.regs[i].'=""'
        let i=i+1
    endwhile
endfunction
command! ClearRegisters call ClearRegisters()