From 4ad4ee81f847bea552e632cc816d60c237078933 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Thu, 11 Nov 2021 08:56:57 +0100 Subject: [PATCH] vim: split up init to ease porting --- install.sh | 6 ++ nvim/init.vim | 224 +---------------------------------------- nvim/viml/autocmds.vim | 17 ++++ nvim/viml/keymaps.vim | 57 +++++++++++ nvim/viml/options.vim | 74 ++++++++++++++ nvim/viml/plugins.vim | 60 +++++++++++ 6 files changed, 218 insertions(+), 220 deletions(-) create mode 100644 nvim/viml/autocmds.vim create mode 100644 nvim/viml/keymaps.vim create mode 100644 nvim/viml/options.vim create mode 100644 nvim/viml/plugins.vim diff --git a/install.sh b/install.sh index ec4672b..c85ca39 100755 --- a/install.sh +++ b/install.sh @@ -216,6 +216,12 @@ deploy_nvim() { link "$DOTFILES/nvim/init.vim" "$XDG_CONFIG_HOME/nvim/old.vim" link "$DOTFILES/nvim/init.lua" "$XDG_CONFIG_HOME/nvim/init.lua" + ensure_directory "$XDG_CONFIG_HOME/nvim/viml" + for f in nvim/viml/*; do + link "$DOTFILES/$f" "$XDG_CONFIG_HOME/$f" + done + unset f + if command -v nvim >/dev/null 2>&1; then warn "installing neovim plugins..." dry_run || nvim -nes -u "$XDG_CONFIG_HOME/nvim/init.vim" -c 'PlugInstall | qall!' diff --git a/nvim/init.vim b/nvim/init.vim index ff4a6e6..635ddf5 100644 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -1,221 +1,5 @@ -if $XDG_CONFIG_HOME == "" | let $XDG_CONFIG_HOME="~/.config" | endif -if $XDG_CACHE_HOME == "" | let $XDG_CACHE_HOME="~/.cache" | endif -if $XDG_DATA_HOME == "" | let $XDG_DATA_HOME="~/.local/share" | endif - -" Options {{{ -set backspace=indent,eol,start " sane backspace behavior -set background=dark " always use dark background -set belloff=all " never ring bells -set nobackup " don't keep backup file after overwriting a file -set clipboard=unnamedplus " synchronize with system clipboard -set colorcolumn=+1 " highlight column after 'textwidth' -set cursorline " highlight the line of the cursor -set diffopt=filler,vertical " make side-by-side diffs better -set noequalalways " don't resize all windows when splitting -set expandtab " use spaces whe is inserted -set fileformats=unix,mac,dos " prioritize unix format -set foldenable " enable folding -set foldlevelstart=100 " start with all folds open -set foldmethod=syntax " fold based on syntax by default -set foldnestmax=10 " limit nested folds to 10 levels -let &formatlistpat='^\s*\(\d\+[\]:.)}\t ]\|[-+*]\|[\[(][ x][\])]\)\s*' -set formatoptions-=t " don't auto-wrap on 'textwidth'... -set formatoptions+=c " ... but do it within comnment blocks. -set formatoptions+=r " insert comment leader when pressing Enter... -set formatoptions-=o " but not when openine a new line with o & O. -set formatoptions+=q " allow formatting of comments with gq -set formatoptions-=a " don't auto-format every time text is inserted -set formatoptions+=n " recognize and indent lists automatically -set formatoptions+=j " remove comment leader when joining lines -set hidden " hide abandoned buffers -set ignorecase " ignore case when searching (see 'smartcase' below) -let &inccommand='split' " show command partial results -set nojoinspaces " use one space after a period whe joining lines -set lazyredraw " don't redraw screen when executing macros -set list " show invisible characters -set listchars=tab:>~,extends:>,precedes:<,trail:- " invisible chars -set modelines=0 " never use modelines -set number " show line numbers -set nrformats-=octal " number formats for CTRL-A & CTRL-X commands -set relativenumber " start off with realtive line numbers -set scrolloff=3 " minimum number of lines above and below cursor -set shiftwidth=0 " use 'tabstop' spaces for (auto)indent step -set shortmess+=I " don't show the intro message when starting Vim -set showbreak="-> " " prefix for wrapped lines -set showmatch " briefly jump to matching bracket if insert one -set noshowmode " don't show mode (shown in statusline instead) -set sidescrolloff=3 " min. number of columns to left and right of cursor -set smartcase " case sensitive search if pattern has uppercase chars -set smartindent " use smart autoindenting -set splitbelow " new window from split is below the current one -set splitright " new window is put right of the current one -set noswapfile " don't use swap files -set tabstop=4 " tabs are 4 spaces -set textwidth=79 " maximum width for text being inserted -set virtualedit=block " position the cursor anywhere in Visual Block mode -set wildignore=*.o,*.obj,*.pyc,*.exe,*.so,*.dll -set wildignorecase " ignore case when completing file names -set wildmode=longest,list,full " complete longest common, then list, then wildmenu -set wrap " wrap long lines -set writebackup " make a backup before overwriting a file - - " +--Disable hlsearch while loading viminfo - " | +--Remember marks for last 100 files - " | | +--Remember up to 1000 lines in each register - " | | | +--Remember up to 1MB in each register - " | | | | +--Remember last 1000 search patterns - " | | | | | +---Remember last 1000 commands - " | | | | | | +-- name of shared data file - " | | | | | | | - " v v v v v v v -set shada=h,'100,<1000,s1000,/1000,:1000,n$XDG_DATA_HOME/nvim/shada/main.shada - -" Overrides when UTF-8 is available -if has('multi_byte') && &encoding ==? 'utf-8' -set fillchars=vert:┃,fold:· -set showbreak=⤷ " prefix for wrapped lines -set listchars=tab:»\ ,extends:…,precedes:…,trail:·,conceal:┊,eol:↲ -endif -" }}} - -" Plugins {{{ -call plug#begin('$XDG_DATA_HOME/nvim/plugged') - Plug 'altercation/vim-colors-solarized' - Plug 'bronson/vim-trailing-whitespace' - Plug 'elzr/vim-json' - " Disable quote concealling. - let g:vim_json_syntax_conceal = 0 - " Make numbers and booleans stand out. - highlight link jsonBraces Text - highlight link jsonNumber Identifier - highlight link jsonBoolean Identifier - highlight link jsonNull Identifier - Plug 'godlygeek/tabular' | Plug 'plasticboy/vim-markdown' - let g:vim_markdown_conceal_code_blocks = 0 - Plug 'junegunn/rainbow_parentheses.vim' - let g:rainbow#pairs = [['(',')'], ['[',']'], ['{','}']] - Plug 'ctrlpvim/ctrlp.vim' - let g:ctrlp_match_window = 'bottom,order:ttb' - let g:ctrlp_switch_buffer = 0 " open files in new buffer - let g:ctrlp_show_hidden = 1 " show hidden files - Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } - Plug 'tpope/vim-commentary' - Plug 'itchyny/lightline.vim' - let g:lightline = { - \ 'colorscheme': 'solarized', - \ 'active': { - \ 'left': [['mode','paste'],[],['ro','modified','path']], - \ 'right': [['percent'],['lineinfo'],['ft','fenc','ff']], - \ }, - \ 'inactive': { - \ 'left': [['paste'],['ro','modified','path']], - \ 'right': [['percent'],['lineinfo']], - \ }, - \ 'component': { - \ 'fenc': '%{&fenc!=#""?&fenc:&enc}', - \ 'ff': '%{&ff}', - \ 'ft': '%{&ft!=#""?&ft:"?"}', - \ 'modified': '%M', - \ 'paste': '%{&paste?"PASTE":""}', - \ 'path': '%f', - \ 'percent': '%3p%%×%L', - \ 'ro': '%R', - \ }, - \ 'subseparator': { 'left': '', 'right': '' }, - \ } - Plug 'vim-scripts/srec.vim' - highlight link srecStart Comment - highlight link srecType Comment - highlight link srecLength WarningMsg - highlight link srec16BitAddress Constant - highlight link srec24BitAddress Constant - highlight link srec32BitAddress Constant - highlight link srecChecksum Type - Plug 'keith/swift.vim' - Plug 'chr4/nginx.vim' -call plug#end() - -silent! colorscheme solarized -highlight NonText cterm=NONE ctermfg=10 " subtle EOL symbols -highlight Whitespace cterm=NONE ctermfg=9 " orange listchars - -" }}} - -" Mappings {{{ -let mapleader = "\" -let maplocalleader = "," - -" better navigation for wrapped lines -noremap j gj -noremap k gk - -" retain selection when indenting/unindenting in visual mode -vnoremap > >gv -vnoremap < <gv - -" window resizing similar to the way I have tmux set up -nnoremap 5+ -nnoremap 5- -nnoremap 5< -nnoremap 5> - -" easier window navigation -nnoremap j -nnoremap k -nnoremap h -nnoremap l - -" easier tab navigation -nnoremap :tabprevious -nnoremap :tabnext - -" show list of buffers and prepare to switch -nnoremap bf :ls:b - -" quickly change background -nnoremap bg - \ :let &background = &background ==? 'light' ? 'dark' : 'light' - -" toggle search highlight -nnoremap h :set hlsearch! - -" toggle NERDTree -nnoremap n :NERDTreeToggle - -" toggle rainbow parens -nnoremap p :RainbowParentheses!! - -" fix whitespace -nnoremap w :FixWhitespace - -" cycle through line numbering modes -nnoremap ln :set nonumber norelativenumber -nnoremap ll :set number norelativenumber -nnoremap lr :set number relativenumber - -" move lines up and down -nnoremap :move .+1 -nnoremap :move .-2 -vnoremap :move '>+1gv -vnoremap :move '<-2gv -" }}}" - -augroup vimrc " {{{ - autocmd! - - autocmd BufNewFile,BufRead bash_profile,bashrc,profile set filetype=sh - autocmd BufNewFile,BufRead gitconfig set filetype=gitconfig - autocmd BufNewFile,BufRead *.sx,*.s19 set filetype=srec - autocmd BufNewFile,BufRead Vagrantfile set filetype=ruby - autocmd BufNewFile,BufRead init.vim set foldmethod=marker - - autocmd FileType python setlocal foldmethod=indent foldignore= - autocmd FileType markdown,text,gitcommit setlocal formatoptions+=t spell - autocmd FileType gitcommit setlocal textwidth=72 - - " Disable cursorline in INSERT mode. - autocmd InsertEnter,InsertLeave * set cursorline! - - autocmd BufWritePost init.vim source % -augroup END " }}} +source ~/.config/nvim/viml/options.vim +source ~/.config/nvim/viml/plugins.vim +source ~/.config/nvim/viml/keymaps.vim +source ~/.config/nvim/viml/autocmds.vim diff --git a/nvim/viml/autocmds.vim b/nvim/viml/autocmds.vim new file mode 100644 index 0000000..1e067ef --- /dev/null +++ b/nvim/viml/autocmds.vim @@ -0,0 +1,17 @@ +augroup vimrc " {{{ + autocmd! + + autocmd BufNewFile,BufRead bash_profile,bashrc,profile set filetype=sh + autocmd BufNewFile,BufRead gitconfig set filetype=gitconfig + autocmd BufNewFile,BufRead *.sx,*.s19 set filetype=srec + autocmd BufNewFile,BufRead Vagrantfile set filetype=ruby + autocmd BufNewFile,BufRead init.vim set foldmethod=marker + + autocmd FileType python setlocal foldmethod=indent foldignore= + autocmd FileType markdown,text,gitcommit setlocal formatoptions+=t spell + autocmd FileType gitcommit setlocal textwidth=72 + + " Disable cursorline in INSERT mode. + autocmd InsertEnter,InsertLeave * set cursorline! +augroup END " }}} + diff --git a/nvim/viml/keymaps.vim b/nvim/viml/keymaps.vim new file mode 100644 index 0000000..8a39084 --- /dev/null +++ b/nvim/viml/keymaps.vim @@ -0,0 +1,57 @@ +let mapleader = "\" +let maplocalleader = "," + +" better navigation for wrapped lines +noremap j gj +noremap k gk + +" retain selection when indenting/unindenting in visual mode +vnoremap > >gv +vnoremap < <gv + +" window resizing similar to the way I have tmux set up +nnoremap 5+ +nnoremap 5- +nnoremap 5< +nnoremap 5> + +" easier window navigation +nnoremap j +nnoremap k +nnoremap h +nnoremap l + +" easier tab navigation +nnoremap :tabprevious +nnoremap :tabnext + +" show list of buffers and prepare to switch +nnoremap bf :ls:b + +" quickly change background +nnoremap bg + \ :let &background = &background ==? 'light' ? 'dark' : 'light' + +" toggle search highlight +nnoremap h :set hlsearch! + +" toggle NERDTree +nnoremap n :NERDTreeToggle + +" toggle rainbow parens +nnoremap p :RainbowParentheses!! + +" fix whitespace +nnoremap w :FixWhitespace + +" cycle through line numbering modes +nnoremap ln :set nonumber norelativenumber +nnoremap ll :set number norelativenumber +nnoremap lr :set number relativenumber + +" move lines up and down +nnoremap :move .+1 +nnoremap :move .-2 +vnoremap :move '>+1gv +vnoremap :move '<-2gv + diff --git a/nvim/viml/options.vim b/nvim/viml/options.vim new file mode 100644 index 0000000..1bc1afe --- /dev/null +++ b/nvim/viml/options.vim @@ -0,0 +1,74 @@ +set backspace=indent,eol,start " sane backspace behavior +set background=dark " always use dark background +set belloff=all " never ring bells +set nobackup " don't keep backup file after overwriting a file +set clipboard=unnamedplus " synchronize with system clipboard +set colorcolumn=+1 " highlight column after 'textwidth' +set cursorline " highlight the line of the cursor +set diffopt=filler,vertical " make side-by-side diffs better +set noequalalways " don't resize all windows when splitting +set expandtab " use spaces whe is inserted +set fileformats=unix,mac,dos " prioritize unix format +set foldenable " enable folding +set foldlevelstart=100 " start with all folds open +set foldmethod=syntax " fold based on syntax by default +set foldnestmax=10 " limit nested folds to 10 levels +let &formatlistpat='^\s*\(\d\+[\]:.)}\t ]\|[-+*]\|[\[(][ x][\])]\)\s*' +set formatoptions-=t " don't auto-wrap on 'textwidth'... +set formatoptions+=c " ... but do it within comnment blocks. +set formatoptions+=r " insert comment leader when pressing Enter... +set formatoptions-=o " but not when openine a new line with o & O. +set formatoptions+=q " allow formatting of comments with gq +set formatoptions-=a " don't auto-format every time text is inserted +set formatoptions+=n " recognize and indent lists automatically +set formatoptions+=j " remove comment leader when joining lines +set hidden " hide abandoned buffers +set ignorecase " ignore case when searching (see 'smartcase' below) +let &inccommand='split' " show command partial results +set nojoinspaces " use one space after a period whe joining lines +set lazyredraw " don't redraw screen when executing macros +set list " show invisible characters +set listchars=tab:>~,extends:>,precedes:<,trail:- " invisible chars +set modelines=0 " never use modelines +set number " show line numbers +set nrformats-=octal " number formats for CTRL-A & CTRL-X commands +set relativenumber " start off with realtive line numbers +set scrolloff=3 " minimum number of lines above and below cursor +set shiftwidth=0 " use 'tabstop' spaces for (auto)indent step +set shortmess+=I " don't show the intro message when starting Vim +set showbreak="-> " " prefix for wrapped lines +set showmatch " briefly jump to matching bracket if insert one +set noshowmode " don't show mode (shown in statusline instead) +set sidescrolloff=3 " min. number of columns to left and right of cursor +set smartcase " case sensitive search if pattern has uppercase chars +set smartindent " use smart autoindenting +set splitbelow " new window from split is below the current one +set splitright " new window is put right of the current one +set noswapfile " don't use swap files +set tabstop=4 " tabs are 4 spaces +set textwidth=79 " maximum width for text being inserted +set virtualedit=block " position the cursor anywhere in Visual Block mode +set wildignore=*.o,*.obj,*.pyc,*.exe,*.so,*.dll +set wildignorecase " ignore case when completing file names +set wildmode=longest,list,full " complete longest common, then list, then wildmenu +set wrap " wrap long lines +set writebackup " make a backup before overwriting a file + + " +--Disable hlsearch while loading viminfo + " | +--Remember marks for last 100 files + " | | +--Remember up to 1000 lines in each register + " | | | +--Remember up to 1MB in each register + " | | | | +--Remember last 1000 search patterns + " | | | | | +---Remember last 1000 commands + " | | | | | | +-- name of shared data file + " | | | | | | | + " v v v v v v v +set shada=h,'100,<1000,s1000,/1000,:1000,n$XDG_DATA_HOME/nvim/shada/main.shada + +" Overrides when UTF-8 is available +if has('multi_byte') && &encoding ==? 'utf-8' +set fillchars=vert:┃,fold:· +set showbreak=⤷ " prefix for wrapped lines +set listchars=tab:»\ ,extends:…,precedes:…,trail:·,conceal:┊,eol:↲ +endif + diff --git a/nvim/viml/plugins.vim b/nvim/viml/plugins.vim new file mode 100644 index 0000000..c6fe5f9 --- /dev/null +++ b/nvim/viml/plugins.vim @@ -0,0 +1,60 @@ +call plug#begin('~/.local/share/nvim/plugged') + Plug 'altercation/vim-colors-solarized' + Plug 'bronson/vim-trailing-whitespace' + Plug 'elzr/vim-json' + " Disable quote concealling. + let g:vim_json_syntax_conceal = 0 + " Make numbers and booleans stand out. + highlight link jsonBraces Text + highlight link jsonNumber Identifier + highlight link jsonBoolean Identifier + highlight link jsonNull Identifier + Plug 'godlygeek/tabular' | Plug 'plasticboy/vim-markdown' + let g:vim_markdown_conceal_code_blocks = 0 + Plug 'junegunn/rainbow_parentheses.vim' + let g:rainbow#pairs = [['(',')'], ['[',']'], ['{','}']] + Plug 'ctrlpvim/ctrlp.vim' + let g:ctrlp_match_window = 'bottom,order:ttb' + let g:ctrlp_switch_buffer = 0 " open files in new buffer + let g:ctrlp_show_hidden = 1 " show hidden files + Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } + Plug 'tpope/vim-commentary' + Plug 'itchyny/lightline.vim' + let g:lightline = { + \ 'colorscheme': 'solarized', + \ 'active': { + \ 'left': [['mode','paste'],[],['ro','modified','path']], + \ 'right': [['percent'],['lineinfo'],['ft','fenc','ff']], + \ }, + \ 'inactive': { + \ 'left': [['paste'],['ro','modified','path']], + \ 'right': [['percent'],['lineinfo']], + \ }, + \ 'component': { + \ 'fenc': '%{&fenc!=#""?&fenc:&enc}', + \ 'ff': '%{&ff}', + \ 'ft': '%{&ft!=#""?&ft:"?"}', + \ 'modified': '%M', + \ 'paste': '%{&paste?"PASTE":""}', + \ 'path': '%f', + \ 'percent': '%3p%%×%L', + \ 'ro': '%R', + \ }, + \ 'subseparator': { 'left': '', 'right': '' }, + \ } + Plug 'vim-scripts/srec.vim' + highlight link srecStart Comment + highlight link srecType Comment + highlight link srecLength WarningMsg + highlight link srec16BitAddress Constant + highlight link srec24BitAddress Constant + highlight link srec32BitAddress Constant + highlight link srecChecksum Type + Plug 'keith/swift.vim' + Plug 'chr4/nginx.vim' +call plug#end() + +silent! colorscheme solarized +highlight NonText cterm=NONE ctermfg=10 " subtle EOL symbols +highlight Whitespace cterm=NONE ctermfg=9 " orange listchars +