.config/nvim: Modularize init.vim & fix some plugin config

Especially whitesdpace & firenvim plugins
This commit is contained in:
xerus2000 2020-06-26 23:23:12 +02:00
parent df4a2aa87f
commit 63079544d0
5 changed files with 226 additions and 188 deletions

View File

@ -1,188 +1,4 @@
""
"_____ ______ _____ _______ . _ _ _____ _________
" | | | | \ \ | | | | | | | | | | | | | | | \
" | | | | | | | | | | \ \ / / | | | | | | | |
"_|_|_ |_| |_| _|_|_ |_| [] \_\_/_/ _|_|_ |_| |_| |_|
""
" Plugins {{{
if empty(glob('~/.local/share/nvim/site/autoload/plug.vim'))
silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin()
" Editing
" text objects
Plug 'xerus2000/argtextobj.vim' " arguments in brackets as text objects
Plug 'bkad/CamelCaseMotion' "
Plug 'tpope/vim-surround' " edit surroundings - cs, ds, ys
" commands
Plug 'inkarkat/vim-ReplaceWithRegister' " gr to replace with register
Plug 'tpope/vim-commentary' " gc to comment out (gcap for paragraph)
Plug 'terryma/vim-multiple-cursors' " <C-n> new coursor+selection on match, <C-x> skip, <C-p> remove cursor & back
" libs
Plug 'tpope/vim-repeat'
Plug 'inkarkat/vim-ingo-library'
" Ex commands
Plug 'DataWraith/auto_mkdir' " mkdir parent dirs when saving
Plug 'AndrewRadev/bufferize.vim' " Command to buffer
Plug 'tpope/vim-eunuch' " OS helpers
Plug 'tpope/vim-fugitive' " Git commands in vim
Plug 'jreybert/vimagit' " Magit for vim - git stage individual changes
Plug 'doy/vim-diff-changes' " Commands for diffing - :DiffAgainstFilesystem :DiffAgainstVCS :DiffStop
Plug 'junegunn/fzf' " File selection with :FZF
" Browse
Plug 'tyru/open-browser.vim' " :OpenBrowser, :OpenBrowserSearch
let g:openbrowser_default_search="duckduckgo"
Plug 'tyru/open-browser-github.vim'
let g:netrw_nogx = 1 " disable netrw's gx mapping.
nmap gs <Plug>(openbrowser-smart-search)
vmap gs <Plug>(openbrowser-smart-search)
nmap gx yi':OpenGithubProject <C-R>"<CR>
command! S OpenBrowserSmartSearch <C-R>"<CR>
command! GH OpenGithubProject <C-R>"<CR>
" QOL
Plug 'farmergreg/vim-lastplace' " Automatically jump to last edit position
Plug 'chrisbra/Recover.vim' " Add Recover options for swap files
" Remove trailing whitespace on save
Plug 'ntpeters/vim-better-whitespace'
highlight ExtraWhitespace ctermbg=4
let g:strip_whitespace_on_save=1
let g:show_spaces_that_precede_tabs=1
let g:better_whitespace_skip_empty_lines=1
autocmd FileType taskedit if exists(":DisableWhitespace") | execute ":DisableWhitespace" | endif
autocmd BufRead $MYVIMRC DisableStripWhitespaceOnSave
" Aesthetic
Plug 'vim-airline/vim-airline' " Status bar on the bottom
Plug 'psliwka/vim-smoothie' " Smooth scrolling
Plug 'romainl/vim-cool' " Automatically stop highlighting search results when moving - https://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting
Plug 'airblade/vim-gitgutter' " Git info on the left
Plug 'norcalli/nvim-colorizer.lua' " Highlights color literals
" Visual indent guides
Plug 'nathanaelkane/vim-indent-guides'
let g:indent_guides_enable_on_vim_startup = 1
" Integrations
Plug 'neoclide/coc.nvim', {'branch': 'release' }
Plug 'udalov/kotlin-vim'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' }
Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } }
call plug#end()
" Colors
set termguicolors
lua require'colorizer'.setup()
command! PU PlugInstall | PlugUpdate | PlugUpgrade
" }}}
" Config {{{
" FILETYPES
syntax on
filetype plugin on
autocmd BufRead,BufNewFile $SHELL_CONFIG/* set filetype=zsh
autocmd FileType json syntax match Comment +\/\/.\+$+ " Comment highlighting in JSON
autocmd Filetype * set formatoptions-=o " Don't automatically comment on o
set number relativenumber " Relative line numbering on the left
set clipboard+=unnamedplus " Merge with system clipboard
set scrolloff=7 sidescrolloff=5 " Keep some context when scrolling
set tabstop=4 shiftwidth=4 " Indentation
set splitright " Vertical split to right by default
set cursorline cursorcolumn
set incsearch hlsearch " Handier search, even though nvim seems to enable it by default
set ignorecase smartcase " Only search case-sensitive when searching with uppercase
set wildmode=longest,list,full " Auto-completion
set mouse=a " Enable mouse in all modes
set showmatch " Highlight matching parenthesis
set mps+=<:> " More pairings for '%'
" Folding
set foldmethod=marker " Use triple curly braces for folds
set foldopen+=jump " Automatically open folds on jump
set noshowmode " Don't show current mode because airline already does and it inhibits echo in visual mode
set diffopt+=vertical
command! DiffSwap :diffsp % " Diff for swap - somewhat obsolete by 'chrisbra/Recover.vim'
set spelllang=en_us,de_de
autocmd FileType markdown setlocal spell " Spell checking in markdown
" Center on insert mode
autocmd InsertEnter * norm zz
" }}}
" Mappings {{{
" Allow saving of files as root when I forgot to use sudoedit
cnoremap w!! execute 'write !sudo tee % >/dev/null' <bar> edit!
command! WS write <bar> source $MYVIMRC
command! FormatJSON %!python -m json.tool
" Add shebang - https://www.reddit.com/r/vim/comments/4z7z7s/add_shebang_lines_to_your_vim_files_automatically/d6v7op8 and https://stackoverflow.com/a/52135425
inoreabbrev <expr> #!! "#!/usr/bin/env" . (empty(&filetype) ? '' : ' '.&filetype)
"autocmd BufNewFile * if !empty(&filetype) | execute 'silent! 1s/.*/#!\/usr\/bin\/' . &filetype . '\r\r'| :startinsert | endif
" Sane yanking
map Y y$
" Disable Ex mode - https://vi.stackexchange.com/q/457
nnoremap Q <nop>
let mapleader=" "
" Alias write and quit to leader
nnoremap <leader>q :wq<CR>
nnoremap <leader>w :w<CR>
" Easy split navigation
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Shortcut split opening
nnoremap <leader>h :split<Space>
nnoremap <leader>v :vsplit<Space>
" Alias replace all to S
nnoremap S :%s//gI<Left><Left><Left>
" Jump around without shift
nnoremap gl $
nnoremap gh 0
nnoremap gk H
nnoremap gj L
nnoremap gt gg
nnoremap gb G
" Enable and disable auto comment
map <leader>c :setlocal formatoptions-=cro<CR>
map <leader>C :setlocal formatoptions=cro<CR>
map <leader>i :setlocal autoindent!<CR>
map <leader>s :setlocal spell!<CR>
function! ShowPosition()
return ":\<c-u>echo 'start=" . string(getpos("v")) . " end=" . string(getpos(".")) . "'\<cr>gv"
endfunction
vmap <expr> ;j ShowPosition()
function! MoveTest()
exe 'silent! normal! ^va"'
normal! :\<ESC>\<CR>
echo getpos('.') getpos("'<") getpos("'>")
endfunction
" }}}
source $XDG_CONFIG_HOME/nvim/init/plug.vim
source $XDG_CONFIG_HOME/nvim/init/general.vim
source $XDG_CONFIG_HOME/nvim/init/pluginConfig.vim
source $XDG_CONFIG_HOME/nvim/init/keys.vim

View File

@ -0,0 +1,47 @@
set termguicolors
set mouse=a " Enable mouse in all modes
set undofile
set wildmode=longest,list,full " Auto-completion
set clipboard+=unnamedplus " Merge with system clipboard
set tabstop=4 shiftwidth=4 " Indentation
" visuals
set number relativenumber " Relative line numbering on the left
set wrap linebreak
set cursorline cursorcolumn
set scrolloff=7 sidescrolloff=20 " Keep some context when scrolling
set colorcolumn=81,121
highlight ColorColumn ctermbg=grey guibg=#888888
" call matchadd('ColorColumn', '\%81v', 100)
" search
set incsearch hlsearch " Handier search, even though nvim seems to enable it by default
set ignorecase smartcase " Only search case-sensitive when searching with uppercase
" matching
set showmatch " Highlight matching parenthesis
set matchpairs+=<:> " More pairings for '%'
set splitright " Vertical split to right by default
set diffopt+=vertical
" Folding
set foldmethod=marker " Use triple curly braces for folds
set foldopen+=jump " Automatically open folds on jump
" FILETYPES
syntax on
filetype plugin on
autocmd FileType json syntax match Comment +\/\/.\+$+ " Comment highlighting in JSON
autocmd Filetype * set formatoptions-=o " Don't automatically comment on o
" custom hardcoded types
autocmd BufRead,BufNewFile $SHELL_CONFIG/* set filetype=zsh
autocmd BufRead,BufNewFile www.mixxx.org_wiki* set filetype=dokuwiki scrolloff=1
set spelllang=en_us,de_de
autocmd FileType markdown setlocal spell " Spell checking in markdown
" Center on insert mode
autocmd InsertEnter * norm zz

View File

@ -0,0 +1,52 @@
" Save file as root when I forgot to use sudoedit
cnoremap w!! execute 'write !sudo tee % >/dev/null' <bar> edit!
" Write file & source vimrc (really only makes sense from within vimrc to quickly test changes)
command! WS write <bar> source $MYVIMRC
command! FormatJSON %!python -m json.tool
command! DiffSwap :diffsp % " Diff for swap - replaced by 'chrisbra/Recover.vim'
" shebang shortcut - https://www.reddit.com/r/vim/comments/4z7z7s/add_shebang_lines_to_your_vim_files_automatically/d6v7op8 and https://stackoverflow.com/a/52135425
inoreabbrev <expr> #!! "#!/usr/bin/env" . (empty(&filetype) ? '' : ' '.&filetype)
autocmd BufNewFile *.sh execute 'silent! 1s/.*/#!\/bin\/sh\r\r'| :startinsert
"autocmd BufNewFile * if !empty(&filetype) | execute 'silent! 1s/.*/#!\/usr\/bin\/' . &filetype . '\r\r'| :startinsert | endif
" Sane yanking
map Y y$
" Disable Ex mode - https://vi.stackexchange.com/q/457
nnoremap Q <nop>
let mapleader=" "
" Alias write and quit to leader
nnoremap <leader>q :wq<CR>
nnoremap <leader>w :w<CR>
" Easy split navigation
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Shortcut split opening
nnoremap <leader>h :split<Space>
nnoremap <leader>v :vsplit<Space>
" Alias replace all to S
nnoremap S :%s//gI<Left><Left><Left>
" Jump around without shift
nnoremap gl $
nnoremap gh 0
nnoremap gk H
nnoremap gj L
nnoremap gt gg
nnoremap gb G
" Enable and disable auto comment
map <leader>c :setlocal formatoptions-=cro<CR>
map <leader>C :setlocal formatoptions=cro<CR>
map <leader>i :setlocal autoindent!<CR>
map <leader>s :setlocal spell!<CR>
" }}}

View File

@ -0,0 +1,62 @@
" Plug
if empty(glob('~/.local/share/nvim/site/autoload/plug.vim'))
silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin()
" Editing
" text objects
Plug 'xerus2000/argtextobj.vim' " arguments in brackets as text objects
Plug 'tpope/vim-surround' " edit surroundings - cs, ds, ys
Plug 'bkad/CamelCaseMotion' " move through camel case words
" commands
Plug 'inkarkat/vim-ReplaceWithRegister' " gr to replace with register
Plug 'tpope/vim-commentary' " gc to comment out (gcap for paragraph)
Plug 'terryma/vim-multiple-cursors' " <C-n> new coursor+selection on match, <C-x> skip, <C-p> remove cursor & back
Plug 'junegunn/vim-easy-align' " ga to align stuff
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)
" libs
Plug 'tpope/vim-repeat'
Plug 'inkarkat/vim-ingo-library'
" Ex commands
Plug 'DataWraith/auto_mkdir' " mkdir parent dirs when saving
Plug 'AndrewRadev/bufferize.vim' " Command to buffer
Plug 'tpope/vim-eunuch' " OS helpers
Plug 'tpope/vim-fugitive' " Git commands in vim
Plug 'jreybert/vimagit' " Magit for vim - git stage individual changes
Plug 'doy/vim-diff-changes' " Commands for diffing - :DiffAgainstFilesystem :DiffAgainstVCS :DiffStop
Plug 'junegunn/fzf' " File selection with :FZF
" Browse
Plug 'tyru/open-browser.vim' " :OpenBrowser, :OpenBrowserSearch
Plug 'tyru/open-browser-github.vim'
" QOL
Plug 'farmergreg/vim-lastplace' " Automatically jump to last edit position
Plug 'chrisbra/Recover.vim' " Add Recover options for swap files
Plug 'ntpeters/vim-better-whitespace' " Tools for trailing whitespace & mixed indents
" Aesthetic
Plug 'vim-airline/vim-airline' " Status bar on the bottom
Plug 'psliwka/vim-smoothie' " Smooth scrolling
Plug 'romainl/vim-cool' " Automatically stop highlighting search results when moving - https://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting
Plug 'airblade/vim-gitgutter' " Git info on the left
Plug 'norcalli/nvim-colorizer.lua' " Highlights color literals
" Visual indent guides
Plug 'nathanaelkane/vim-indent-guides'
let g:indent_guides_enable_on_vim_startup = 1
" Integrations
Plug 'xerus2000/vim-dokuwiki'
Plug 'neoclide/coc.nvim', {'branch': 'release' }
Plug 'udalov/kotlin-vim'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' }
Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } }
call plug#end()

View File

@ -0,0 +1,61 @@
" Don't show current mode because airline already does and it inhibits echo in visual mode
set noshowmode
command! PU PlugUpdate | PlugUpgrade
lua require 'colorizer'.setup({ '*'; markdown = { names = false; }; })
let g:strip_whitespace_on_save=1
let g:show_spaces_that_precede_tabs=1
let g:better_whitespace_skip_empty_lines=1
let g:better_whitespace_guicolor=$THEME == 'light' ? 'LightGrey' : 'DarkGrey'
autocmd FileType taskedit,markdown DisableWhitespace
" see https://github.com/ntpeters/vim-better-whitespace/issues/134 - autocmd OptionSet background let g:better_whitespace_guicolor=&background == 'light' ? 'LightYellow' : 'Brown'
map <silent> w <Plug>CamelCaseMotion_w
map <silent> b <Plug>CamelCaseMotion_b
map <silent> e <Plug>CamelCaseMotion_e
map <silent> ge <Plug>CamelCaseMotion_ge
omap <silent> iw <Plug>CamelCaseMotion_iw
xmap <silent> iw <Plug>CamelCaseMotion_iw
omap <silent> ib <Plug>CamelCaseMotion_ib
xmap <silent> ib <Plug>CamelCaseMotion_ib
omap <silent> ie <Plug>CamelCaseMotion_ie
xmap <silent> ie <Plug>CamelCaseMotion_ie
" open-browser
let g:openbrowser_default_search="duckduckgo"
let g:netrw_nogx = 1 " disable netrw's gx mapping.
nmap gs <Plug>(openbrowser-smart-search)
vmap gs <Plug>(openbrowser-smart-search)
nmap gx yi':OpenGithubProject <C-R>"<CR>
command! S OpenBrowserSmartSearch <C-R>"<CR>
command! GH OpenGithubProject <C-R>"<CR>
" firenvim
let g:firenvim_config = {
\ 'globalSettings': {
\ 'alt': 'all',
\ },
\ 'localSettings': {
\ '.*': {
\ 'cmdline': 'neovim',
\ 'priority': 0,
\ 'selector': 'textarea:not([readonly]):not([class="handsontableInput"]), div[role="textbox"]',
\ 'takeover': 'always',
\ },
\ '.*notion\.so.*': { 'priority': 1, 'takeover': 'never', },
\ '.*openstreetmap\.org.*': { 'priority': 1, 'takeover': 'never', },
\ }
\ }
if exists('g:started_by_firenvim')
autocmd FocusLost,InsertLeave,BufLeave * ++nested call WriteSilent()
function WriteSilent()
let tmp=b:better_whitespace_enabled
let b:better_whitespace_enabled=0
write
let b:better_whitespace_enabled=tmp
endfunction
nnoremap <Esc><Esc> :call firenvim#focus_page()<CR>
let g:strip_whitespace_on_save=0
endif