Created
November 7, 2019 19:28
-
-
Save davidnash/3e8007e66912ebf94d62b9c565e589c3 to your computer and use it in GitHub Desktop.
David Nash vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ------------ | |
" Vim settings | |
" ------------ | |
" Always use long form options, so it's more obvious what they do | |
set nocompatible " Use Vim defaults (better than Vi defaults) | |
filetype plugin indent on | |
set encoding=utf8 " Set encoding | |
scriptencoding utf-8 | |
set backspace=indent,eol,start " Allow backspacing over everything in insert mode | |
set scrolloff=5 " Show 5 lines at bottom/top of window | |
set autoindent " Set autoindenting on | |
set smartindent " Indents on line after { etc | |
set copyindent " Make 'autoindent' use existing indent structure | |
set ruler " Show the cursor position all the time | |
set visualbell " Set visual bell, turn off beep | |
set ignorecase " Ignore case for search | |
set smartcase " Unless caps are used | |
set nolinebreak " Wrap long lines | |
set autoread " Auto read when a file is changed externally to vim | |
set hidden " Has something to do with buffers, use it | |
set hlsearch " Highlight all instances of search term | |
set incsearch " Incremental search | |
set cursorline " Highlights current line | |
set autochdir " Make current working directory the current one | |
set mouse=a " Enable mouse in terminal | |
set timeoutlen=500 " Reduce timeout from 1 second | |
set clipboard=unnamedplus " Yank/delete to system clipboard | |
set number " Show line numbers | |
set relativenumber " Show relative | |
set tabstop=4 " Number of spaces a <tab> is displayed as | |
set softtabstop=4 " Number of spaces inserted when <tab> is pressed | |
set shiftwidth=0 " 0 sets indent amount to tabstop value | |
set expandtab " Use spaces instead of a tab character in insert mode | |
set nobackup " Turn off backup | |
set nowritebackup " Don't make backup before writing file, backup is removed | |
set noswapfile " Don't create a swap file | |
set iskeyword=@,48-57,_,-,192-255 " add dash to keywords for autocomplete | |
" Persistent undo - undo across file open/close (may need to create this directory) | |
set undodir=~/.vim_runtime/undodir | |
set undofile | |
" gVim only options (so we don't need a .gvimrc) | |
if has('gui_running') | |
set guifont=Hack\ 14 | |
" set termencoding=utf-8 | |
set linespace=10 " Increase line height | |
set go=agirLt " GUI options | |
set mousehide " Hide the mouse when typing text | |
set lines=38 | |
set columns=124 | |
autocmd BufRead *.scss,*.css let &columns=80 " Use less columns for CSS | |
else | |
" Change the cursor to bar in insert mode | |
let &t_SI = "\e[6 q" | |
let &t_EI = "\e[2 q" | |
set novisualbell | |
if has ('termguicolors') | |
set termguicolors | |
endif | |
end | |
" HTML syntax highlighting inside php strings | |
let php_htmlInStrings = 1 | |
" Save view - folds, settings, etc (requires ~/.vim/view chmod 755) | |
autocmd BufWinLeave * silent! mkview | |
autocmd BufWinEnter * silent! loadview | |
" Hide cursorline in insert more | |
autocmd InsertLeave,WinEnter * set cursorline | |
autocmd InsertEnter,WinLeave * set nocursorline | |
" Turn off search highlight when in insert mode | |
autocmd InsertEnter * :set nohlsearch | |
autocmd InsertLeave * :set hlsearch | |
" PHP and WordPress syntax | |
autocmd BufEnter *.php :set syn=wordpress | |
" Show tabs as · | |
set list | |
set listchars=tab:!· | |
" Show autocomplete in command mode | |
set wildmenu | |
" Don't redraw during macros | |
set lazyredraw | |
" Open splits to the right and below | |
set splitright | |
set splitbelow | |
" Enable spellchecking in natural language files | |
augroup NaturalLanguage | |
autocmd! | |
autocmd BufRead,BufNewFile *.md,*.rst,*.txt setlocal spell spelllang=en_au | |
autocmd FileType gitcommit setlocal spell spelllang=en_au | |
augroup END | |
" Python | |
autocmd BufNewFile,BufRead *.py :set textwidth=79 fileformat=unix | |
autocmd Filetype python nnoremap <buffer> <F5> exec '!python2' shellescape(@%, 1)<cr> | |
autocmd Filetype python nnoremap <buffer> <F6> exec '!python3' shellescape(@%, 1)<cr> | |
" Go to first line/char for git commit messages | |
autocmd FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0]) | |
" ------------ | |
" Experimental | |
" ------------ | |
" ------------ | |
" Key mappings | |
" ------------ | |
" Set map leader | |
let mapleader = ";" | |
let g:mapleader = ";" " Global map leader | |
" Use ;; to repeat search in normal mode for f, t | |
nnoremap ;; ; | |
" Clear search term | |
nnoremap <leader>h :noh<CR> | |
" Don't lose selection after indent change | |
xnoremap < <gv | |
xnoremap > >gv | |
nnoremap > >> | |
nnoremap < << | |
" 0 will go to first non-whitepsace character on line | |
noremap 0 ^ | |
noremap - $ | |
" Remove windows ^M | |
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm | |
" Close HTML/XML tags with ;/ | |
inoremap <leader>/ </<C-x><C-o> | |
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags | |
" Save file with ;w | |
noremap <leader>w :update<CR> | |
" Easier quit without save | |
nnoremap Q :quit!<CR> | |
" Delete line without saving to register | |
nnoremap D "_dd | |
" Reload .vimrc | |
nnoremap <leader>sv :source ~/.vim/vimrc<cr> | |
" Toggle gui menubar | |
nnoremap <F3> :if &go=~#'m'<Bar>set go-=m<Bar>else<Bar>set go+=m<Bar>endif<CR> | |
" Disable arrow keys | |
inoremap <Up> <NOP> | |
inoremap <Down> <NOP> | |
inoremap <Left> <NOP> | |
inoremap <Right> <NOP> | |
" PHP/HTML | |
inoremap <leader>pre echo '<pre style="white-space: pre">debug: '.print_r($, true).'</pre>';<ESC>Bhhi | |
inoremap <leader>die die('here');<ESC> | |
inoremap <leader>ph <?php?><esc>hi | |
inoremap <leader>hp ?><?php<esc>4hi | |
inoremap <leader>- -> | |
inoremap <leader>= => | |
inoremap <leader>id id=""<esc>i | |
inoremap <leader>cl class=""<esc>i | |
inoremap <leader>na name=""<esc>i | |
inoremap <leader>ty type=""<esc>i | |
inoremap <leader>val value=""<esc>i | |
inoremap <leader>log console.log();<ESC>hi | |
inoremap <leader>b1 border: 1px solid red; | |
imap <leader>lor Lorem ipsum dolor sit amet, consectetur adipiscing elit. In leo odio, varius ac ante a, mollis. | |
" Append semicolon or comma to end of line | |
nnoremap <leader>l A;<esc> | |
nnoremap <leader>k A,<esc> | |
imap <S-Return> <br> | |
imap <C-Return> \n | |
iabbrev shrug ¯\_(ツ)_/¯ | |
" ------- | |
" Plugins | |
" ------- | |
call plug#begin('~/.vim/plugged') | |
Plug 'https://github.com/ntpeters/vim-better-whitespace.git' | |
Plug 'https://github.com/scrooloose/syntastic.git' | |
Plug 'https://github.com/itchyny/lightline.vim' | |
Plug 'https://github.com/tmsvg/pear-tree' " Auto-pair plugin | |
Plug 'https://github.com/lilydjwg/colorizer' | |
" Plug 'https://github.com/Lokaltog/vim-easymotion' | |
" Plug 'https://github.com/justinmk/vim-sneak' | |
Plug 'https://github.com/mattn/emmet-vim.git' | |
Plug 'https://github.com/mattn/webapi-vim.git' | |
Plug 'https://github.com/matze/vim-move' | |
Plug 'https://github.com/tpope/vim-commentary' | |
Plug 'https://github.com/zxqfl/tabnine-vim' | |
" Plug 'https://github.com/RRethy/vim-illuminate' " Highlight all word under cursor | |
" Plug 'https://github.com/elbeardmorez/vim-loclist-follow' | |
Plug 'https://github.com/srcery-colors/srcery-vim' | |
" PHP | |
Plug 'https://github.com/captbaritone/better-indent-support-for-php-with-html' | |
Plug 'https://github.com/kloppster/Wordpress-Vim-Syntax.git' | |
" Plug 'https://github.com/jwalton512/vim-blade.git' | |
" HTML/PHP | |
Plug 'https://github.com/othree/html5.vim' | |
" Plug 'https://github.com/AndrewRadev/tagalong.vim' | |
Plug 'https://github.com/haya14busa/endtagcomment.vim' | |
" CSS/Sass | |
Plug 'https://github.com/JulesWang/css.vim' | |
Plug 'https://github.com/cakebaker/scss-syntax.vim' | |
" Javascript | |
Plug 'https://github.com/pangloss/vim-javascript' | |
" Plug 'https://github.com/posva/vim-vue' | |
call plug#end() | |
colorscheme srcery | |
" Transparent background in terminal - must come after colorscheme | |
if !has('gui_running') | |
hi Normal guibg=NONE ctermbg=NONE | |
endif | |
" Lightline | |
let g:lightline = { 'colorscheme': 'srcery', 'component_expand': {'syntastic': 'SyntasticStatuslineFlag',}, 'component_type': { 'syntastic': 'error',}, } | |
set noshowmode | |
set cmdheight=1 | |
set laststatus=2 | |
" Easymotion | |
" let g:EasyMotion_smartcase = 1 | |
" map s <Plug>(easymotion-prefix) | |
" nmap <C-f> <Plug>(easymotion-s) | |
" Sneak | |
" let g:sneak#label = 1 | |
" Emmet-vim | |
let g:user_emmet_mode='i' | |
let g:user_emmet_leader_key=';;' | |
let g:user_emmet_settings = webapi#json#decode(join(readfile(expand('~/.vim/emmet_snippets.json')), "\n")) | |
" Endtagcomment-vim | |
let g:endtagcommentFormat = '<!-- {%id}{%class} -->' | |
nmap <leader>t <Plug>(endtagcomment) | |
" Vim-commentary | |
map <leader>c gc | |
autocmd FileType php setlocal commentstring=//\ %s | |
" Vim-move | |
let g:move_key_modifier = 'C' | |
" Vim-better-whitespace | |
let g:strip_whitespace_on_save = 1 | |
let g:strip_whitelines_at_eof = 1 | |
let g:better_whitespace_guicolor = 'Grey23' " http://vim.wikia.com/wiki/Xterm256_color_names_for_console_Vim | |
let g:strip_whitespace_confirm = 0 | |
let g:strip_only_modified_lines = 1 | |
let g:current_line_whitespace_disabled_soft = 1 | |
" Syntastic | |
let g:syntastic_always_populate_loc_list = 0 | |
let g:syntastic_auto_jump = 0 | |
let g:syntastic_auto_loc_list = 1 | |
let g:syntastic_check_on_open = 0 | |
let g:syntastic_check_on_wq = 0 | |
let g:syntastic_loc_list_height = 5 | |
let g:syntastic_javascript_checkers = ['eslint'] | |
let g:syntastic_python_pylint_exec = 'pylint3' | |
let g:syntastic_python_checkers = ['python'] | |
" Close/open location list (errors) | |
noremap <Up> :lprev<CR> | |
noremap <Down> :lnext<CR> | |
noremap <Left> :lcl<CR> | |
noremap <Right> :Errors<CR> :lw<CR> | |
" Pear tree (auto close pairs) | |
let g:pear_tree_repeatable_expand = 0 | |
let g:pear_tree_smart_openers = 1 | |
let g:pear_tree_smart_closers = 1 | |
let g:pear_tree_smart_backspace = 1 | |
" TabNine / YouCompleteMe | |
let g:ycm_complete_in_comments = 1 | |
set completeopt-=preview | |
let g:ycm_add_preview_to_completeopt = 0 | |
let g:ycm_min_num_of_chars_for_completion = 3 | |
let g:ycm_max_num_candidates = 10 | |
" Illuminate - Highlight all instances of a word | |
let g:Illuminate_highlightUnderCursor = 0 | |
" vim-loclist-follow - update location list for Syntastic | |
let g:loclist_follow = 1 | |
let g:loclist_follow_modes = 'n' "default: 'ni' | |
" -------------- | |
" Hints and Tips | |
" -------------- | |
" When vim thinks a file is read only but it's not -- :set noro | |
" Split window vertically -- ctrl-w v | |
" Reload syntax highlighting -- :syntax sync fromstart | |
" To increment numbers in a block: | |
" 1. First copy and paste the number of items you need | |
" 2. Ctrl-v to select the block | |
" 3. g Ctrl-a to increment the numbers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment