From 36bf8e01c5733ebad16a26199111c4f751f1884a Mon Sep 17 00:00:00 2001 From: Max Bucknell Date: Fri, 19 Apr 2019 22:07:58 +0100 Subject: [PATCH] Updating neovim config --- .../UltiSnips/typescript.snippets | 12 + nvim/nvim.symlink/coc-settings.json | 2 + nvim/nvim.symlink/init.vim | 376 +++++++++--------- 3 files changed, 202 insertions(+), 188 deletions(-) create mode 100644 nvim/nvim.symlink/UltiSnips/typescript.snippets create mode 100644 nvim/nvim.symlink/coc-settings.json diff --git a/nvim/nvim.symlink/UltiSnips/typescript.snippets b/nvim/nvim.symlink/UltiSnips/typescript.snippets new file mode 100644 index 0000000..8138d97 --- /dev/null +++ b/nvim/nvim.symlink/UltiSnips/typescript.snippets @@ -0,0 +1,12 @@ +snippet mochatest +import 'mocha'; +import { expect } from 'chai'; + +import $1 from '$2'; + +describe('$3', () => { + it('should $4', () => { + $0 + }); +}); +endsnippet diff --git a/nvim/nvim.symlink/coc-settings.json b/nvim/nvim.symlink/coc-settings.json new file mode 100644 index 0000000..2c63c08 --- /dev/null +++ b/nvim/nvim.symlink/coc-settings.json @@ -0,0 +1,2 @@ +{ +} diff --git a/nvim/nvim.symlink/init.vim b/nvim/nvim.symlink/init.vim index 246678b..46ebf74 100644 --- a/nvim/nvim.symlink/init.vim +++ b/nvim/nvim.symlink/init.vim @@ -1,98 +1,63 @@ -" Basic editing config - -" colorscheme maxbucknell -set termguicolors -set updatetime=100 - +" Let's get the plugins out of the way first, shall we? call plug#begin() + " Pane Navigation (Tmux integration) + " Colours + Plug 'morhetz/gruvbox' -" Pane Navigation (Tmux integration) -Plug 'christoomey/vim-tmux-navigator' + " Fuzzy finding + Plug '/usr/local/opt/fzf' + Plug 'junegunn/fzf.vim' -" Colours -Plug 'morhetz/gruvbox' + " Completion + Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install()}} -" Fuzzy finding -Plug '/usr/local/opt/fzf' + " Snippets + Plug 'SirVer/ultisnips' + Plug 'honza/vim-snippets' -" Snippets -Plug 'SirVer/ultisnips' -Plug 'honza/vim-snippets' + " Surround + Plug 'tpope/vim-surround' -" Git integration -Plug 'tpope/vim-fugitive' -Plug 'airblade/vim-gitgutter' + " Git integration + Plug 'tpope/vim-fugitive' + Plug 'airblade/vim-gitgutter' -" Linting -Plug 'neomake/neomake' -Plug 'w0rp/ale' + " Comments + Plug 'tpope/vim-commentary' -" Comments -Plug 'tpope/vim-commentary' + " Statusline + Plug 'vim-airline/vim-airline' -" File browsing -Plug 'francoiscabrol/ranger.vim' -Plug 'rbgrouleff/bclose.vim' + " TypeScript + Plug 'HerringtonDarkholme/yats.vim' -" Statusline -Plug 'vim-airline/vim-airline' + " Go + Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' } -" For async completion -Plug 'Shougo/deoplete.nvim' + " Rust + Plug 'rust-lang/rust.vim' -" TypeScript -Plug 'HerringtonDarkholme/yats.vim' -Plug 'mhartington/nvim-typescript', {'do': './install.sh'} + " CSV + Plug 'chrisbra/csv.vim' -" Go -Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' } -Plug 'deoplete-plugins/deoplete-go', { 'do': 'make'} - -" Rust -Plug 'rust-lang/rust.vim' -Plug 'sebastianmarkow/deoplete-rust' - -" CSV -Plug 'chrisbra/csv.vim' + " CSS Colour previews + " + " Working on changing this, making it use virtual text to render a swatch. + Plug 'chrisbra/Colorizer' call plug#end() -" Theme configuration -let g:gruvbox_italic = 1 -colorscheme gruvbox +" I have a true colour terminal, and I will have true colours in my Vim +set termguicolors -" Use ranger instead of netrw -let g:ranger_replace_netrw = 1 - -" Setting up autocomplete -let g:deoplete#enable_at_startup = 1 - -" Quick exit insert mode +" Disable creation of swap files. " -" Escape is at the far corner of my keyboard, and having it so far away -" was discouraging me from exiting insert mode. Qwerty users can remap -" jk to , which is a far better solution. The keys are next to each -" other, and it makes exiting insert mode a pleasant rolling motion. -" Moreover, when in normal mode, jk is a no-op. +" Swap files serve a purpose, but not to me. I write often, and so +" these just get in the way. " -" As a dvorak user, jk was too cumbersome, but there were no other -" suitable candidates. hh is inferior in that it is not a no-op in -" normal mode, but it is just as easy to type. The only caveat is when -" an edit ends with h, which is why hhh will expand to place an h in -" the buffer before exiting. -" -" To encourage me to adopt the new style, I disable escape. That one is -" sure to mess up someone not familiar with my setup. -inoremap hh -inoremap hhh h -" Terminal mode setting -tnoremap hh -tnoremap hhh h - -" Lead with the biggest button on the motherfucking keyboard -let mapleader = "\" - -" FUzzy finding -nnoremap o :FZF +" I'm toying with the idea of re-enabling these and ignoring them in Git. +set nobackup +set nowritebackup +set noswapfile " Don't wrap lines " @@ -137,17 +102,6 @@ set showcmd " have the memory to spare to keep them around. set hidden -" Enable highlighting for syntax -syntax on - -" Enable file type detection. -" -" Use the default filetype settings, so that mail gets 'tw' set to 72, -" 'cindent' is on in C files, etc. -" Also load indent files, to automatically do language-dependent -" indenting. -filetype plugin indent on - " Insert only one space when joining lines that contain " sentence-terminating punctuation like `.`. set nojoinspaces @@ -165,20 +119,13 @@ set listchars=tab:‣\ ,trail:· " of my text in it, no funny business. set foldmethod=manual set nofoldenable -let g:vim_markdown_folding_disabled=1 -let g:vimtex_fold_enabled=0 -"""""""""""""""""" -" Ultisnips, y'all -"""""""""""""""""" - -let g:UltiSnipsExpandTrigger="" -let g:UltiSnipsJumpForwardTrigger="" -let g:UltiSnipsJumpBackwardTrigger="" +" Scrolloff, because I'm allergic to the edges of my screen +set scrolloff=5 " Tab config options " -" In general, I prefer spaces to tabs, and 2-space indentation. These +" In general, I prefer spaces to tabs, and 4-space indentation. These " settings just make that consistent, so I rarely have to think about " it. set expandtab @@ -187,7 +134,99 @@ set shiftwidth=4 set softtabstop=4 set autoindent +" Enable highlighting for syntax +syntax on + +" Enable file type detection. +filetype plugin indent on + +" Theme configuration +let g:gruvbox_italic = 1 +colorscheme gruvbox + +" Lead with the biggest button on the motherfucking keyboard +let mapleader = "\" +let localmapleader = "\\" + +" Quick exit insert mode +" +" Escape is at the far corner of my keyboard, and having it so far away +" was discouraging me from exiting insert mode. Qwerty users can remap +" jk to , which is a far better solution. The keys are next to each +" other, and it makes exiting insert mode a pleasant rolling motion. +" Moreover, when in normal mode, jk is a no-op. +" +" As a dvorak user, jk was too cumbersome, but there were no other +" suitable candidates. hh is inferior in that it is not a no-op in +" normal mode, but it is just as easy to type. The only caveat is when +" an edit ends with h, which is why hhh will expand to place an h in +" the buffer before exiting. +" +" To encourage me to adopt the new style, I disable escape. That one is +" sure to mess up someone not familiar with my setup. +inoremap hh +inoremap hhh h + +" Terminal mode setting +tnoremap hh +tnoremap hhh h + +" Visual mode setting +vnoremap hh +vnoremap hhh h + +" Fuzzy finding +nnoremap o :Files +nnoremap b :Buffers + +" Go to most recently edited file +nnoremap + +" Ultisnips, y'all +let g:UltiSnipsExpandTrigger="" +let g:UltiSnipsJumpForwardTrigger="" +let g:UltiSnipsJumpBackwardTrigger="" + +" Remap semi-colon to colon. +" +" Colon is the starting point of a lot of actions in Vim. And I +" shouldn't have to hold a modifier key to access so much +" essential functionality. +noremap ; : +noremap ;; ; + +" Git blame +" +" I used to do this by just filling in my buffer, but this is nicer. +nnoremap a :Gblame + +" What the hell is ex mode +" +" Whatever it is, I don't like it. +nnoremap Q + +" Traversing lines +nnoremap - ddp +nnoremap _ :-1dpk + +" Updating Vimrc +" +" A little mapping to edit my vimrc. I'd like to do this with a function, and +" account for a few things: +" +" + Is a buffer already open and visible? +" + Open in a floating window over everything to not disturb my workflow +nnoremap ev :vsp $MYVIMRC + +" Second part, every time I write to $MYVIMRC, source it for me. +augroup updateVimrc + autocmd BufWritePost $MYVIMRC :source $MYVIMRC +augroup END + " Zoom the current split +" +" Tmux has a feature -z, that will zoom the current pane. I decided +" that this was a useful enough feature to have in Vim as well. Voila. function! ZoomOrUnzoom() if exists('g:is_zoomed') unlet g:is_zoomed @@ -199,6 +238,11 @@ function! ZoomOrUnzoom() endif endfunc +" Map it to z +nnoremap z :call ZoomOrUnzoom() + +" I had this running as an autocommand on resizes, but it was buggy so it's +" disabled at the moment. function! HandleResize() if exists('g:is_zoomed') execute "wincmd _" @@ -208,16 +252,17 @@ function! HandleResize() endif endfunc -nnoremap :call ZoomOrUnzoom() - +" A load of default file runners. These need to be refactored, so that they +" are in filetype plugins, and would probably be better served by being bound +" to the localleader. function! RunTypeScript() silent !clear - execute "!tsc % --outFile /dev/stdout | node" + execute "!$(findroot package.json)/node_modules/.bin/mocha -r ts-node/register -R dot %" endfunction function! RunJavaScript() silent !clear - execute "!node %" + execute "!$(findroot package.json)/node_modules/.bin/mocha -R dot %" endfunction function! RunPython() @@ -230,43 +275,54 @@ function! RunRust() execute "!cargo run" endfunction -augroup vimrcEx - " Clear all autocmds in the group - autocmd! +function! OpenInMarked() + silent !clear + execute '!open "x-marked://open?file=%:p"' +endfunction - " Language whitespace settings - autocmd FileType make setl noet sw=8 sts=8 ts=8 +augroup runFiles + autocmd! - autocmd FileType typescript nnoremap r :call RunTypeScript() - autocmd FileType javascript nnoremap r :call RunJavaScript() - autocmd FileType python nnoremap r :call RunPython() - autocmd FileType rust nnoremap r :call RunRust() + autocmd FileType typescript nnoremap r :call RunTypeScript() + autocmd FileType javascript nnoremap r :call RunJavaScript() + autocmd FileType python nnoremap r :call RunPython() + autocmd FileType rust nnoremap r :call RunRust() + autocmd FileType markdown nnoremap r :call OpenInMarked() +augroup END - " Hard wrap prose - " - " This will automatically insert a new line in insert mode when a - " line gets too long (above 80 characters). I can also run gqap - " in normal mode to reflow a paragraph. - autocmd FileType - \ markdown,text - \ setl tw=80 fo=t1 +" Text formatting rules for various files. +augroup textFormatting + autocmd! - " Automatically enter terminal mode when summoning a terminal - autocmd TermOpen term://* startinsert + " Make files really need tabs + autocmd FileType make setl noet sw=8 sts=8 ts=8 - " Lay out splits when Vim gets resized - autocmd VimResized * :call HandleResize() + " Hard wrap prose + " + " This will automatically insert a new line in insert mode when a + " line gets too long (above 80 characters). I can also run gqap + " in normal mode to reflow a paragraph. + autocmd FileType + \ markdown,text + \ setl tw=80 fo=t1 +augroup END +" I'm not interested in line numbers on terminal buffers. I hardly ever use +" terminal buffers anyway, but they are useful in a few cases. +" +" I never want line numbering. +augroup lineNumbering + autocmd! + + autocmd TermOpen * setl nonu nornu +augroup END + +augroup terminalInsert + " Automatically enter terminal mode when summoning a terminal + autocmd TermOpen term://* startinsert augroup END " Make directories in a filename if they don't exist. - -function! AskQuit (msg, options, quit_option) - if confirm(a:msg, a:options) == a:quit_option - exit - endif -endfunction - function! EnsureDirExists () let required_dir = expand("%:h") if !isdirectory(required_dir) @@ -281,48 +337,23 @@ endfunction augroup AutoMkdir autocmd! - autocmd BufNewFile * :call EnsureDirExists() + autocmd BufNewFile * :call EnsureDirExists() augroup END -" Ale -" -" An asynchronous linting engine. -let g:ale_lint_on_text_changed = 1 - -" Hallelujah! -let g:ale_set_signs = 1 -let g:ale_sign_column_always = 1 -let g:ale_sign_error = '--' -let g:ale_sign_warning = '--' - " Gitgutter let g:gitgutter_realtime = 1 let g:gitgutter_eager = 1 -" JSX in mah JavaScript -let g:jsx_ext_required = 0 - " Status line stuff let g:airline#extensions#ale#enabled = 1 let g:airline#extensions#tabline#enabled = 1 " Input supports patched fonts already \o/ let g:airline_powerline_fonts = 1 - -" Go to most recently edited file -nnoremap - -" Disable syntax hiding in JSON -" -" Vim JSON provides a fancy way of viewing, where it hides quotes and -" just shows you data. I don't want that. -let g:vim_json_syntax_conceal = 0 - " Show syntax highlighting groups for word under cursor " " This is useful for finding rogue elements I forgot in my colour " scheme. -nnoremap \ :call SynStack() function! SynStack() if !exists("*synstack") return @@ -330,35 +361,4 @@ function! SynStack() echo map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")') endfunc -" Remap semi-colon to colon. -" -" Colon is the starting point of a lot of actions in Vim. And I -" shouldn't have to hold a modifier key to access so much -" essential functionality. -noremap ; : -noremap ;; ; - -" Commenting aliases, because I hate change. -nnoremap / :.Commentary - -" Git blame -" -" I used to do this by just filling in my buffer, but this is nicer. -nnoremap a :Gblame - -" Disable creation of swap files. -" -" Swap files serve a purpose, but not to me. I write often, and so -" these just get in the way. -set nobackup -set nowritebackup -set noswapfile - -" What the hell is ex mode -" -" Whatever it is, I don't like it. -nnoremap Q - -" Summon a terminal -nnoremap k :bot sp term://zsh - +nnoremap \ :call SynStack()