From 333524778e1f27c7b2e228ab5d1da563264f16a6 Mon Sep 17 00:00:00 2001 From: doyle Date: Fri, 17 Jun 2022 17:46:41 +1000 Subject: [PATCH] Switch completely to nvim --- Installer/os_nvim_init.vim | 157 +++++++++++++++++- ..._clang_merge_compilation_command_files.bat | 45 +++++ win_install.bat | 13 +- 3 files changed, 203 insertions(+), 12 deletions(-) create mode 100644 Installer/win_clang_merge_compilation_command_files.bat diff --git a/Installer/os_nvim_init.vim b/Installer/os_nvim_init.vim index f182e5b..a26739b 100644 --- a/Installer/os_nvim_init.vim +++ b/Installer/os_nvim_init.vim @@ -1,3 +1,154 @@ -set runtimepath^=~/.vim runtimepath+=~/.vim/after -let &packpath = &runtimepath -source ~/.vimrc +" Plugins +" ============================================================================== +call plug#begin(stdpath('config') . '/plugged') + Plug 'https://github.com/scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } + Plug 'https://github.com/junegunn/fzf' + Plug 'https://github.com/junegunn/fzf.vim' + Plug 'https://github.com/Tetralux/odin.vim' + Plug 'https://github.com/morhetz/gruvbox' +call plug#end() + +" Theme +" ============================================================================== +let g:gruvbox_contrast_dark='hard' +let g:gruvbox_italic=0 +let g:gruvbox_bold=0 +colorscheme gruvbox + +" Options +" ============================================================================== +set autowrite " Automatically save before commands like :next and :make +set nowrap " Don't wrap lines of text automatically +set ignorecase " Search isn't case sensitive +set splitright " Open new splits to the right of the current one +set visualbell " Flash the screen on error +set expandtab " Replace tabs with spaces +set noswapfile " Disable swapfile (stores the things changed in a file) +set colorcolumn=80,100 " Set a 80 and 100 char column ruler +set cpoptions+=$ " $ as end marker for the change operator +set cursorline " Highlight current line +set linebreak " On wrapped lines, break on the wrapping word intelligently +set list " Show the 'listchar' characters on trailing spaces, tabs e.t.c +set listchars+=tab:>-,trail:■,extends:»,precedes:« +set number " Show line numbers +set relativenumber " Show relative line numbers +set shiftwidth=4 " Number of spaces for each autoindent step +set textwidth=80 " On format, format to 80 char long lines +" Show EOL type and last modified timestamp, right after the filename +set statusline=%<%F%h%m%r\ [%{&ff}]\ (%{strftime(\"%H:%M\ %d/%m/%Y\",getftime(expand(\"%:p\")))})%=%l,%c%V\ %P +set guifont=JetBrains_Mono:h9,Consolas:h9,InputMonoCondensed:h9 + +" Resize splits when the window is resized +au VimResized * :wincmd = + +" File patterns to ignore in command line auto complete +set wildignore+=*.class,*.o +set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe,*.obj,*.vcxproj,*.pdb,*.idb + +" Setup undo file +set undofile +let &undodir=stdpath('config') . '/undo' + +" Enable mouse support +if has('mouse') + set mouse=a +endif + +" Functions +" ============================================================================== +" Don't show trailing spaces in insert mode +augroup trailing + au! + au InsertEnter * :set listchars-=trail:■ + au InsertLeave * :set listchars+=trail:■ +augroup END + +" Increase font size using (Ctrl+Up Arrow) or (Ctrl+Down Arrow) if we are using +" gvim Otherwise font size is determined in terminal +nnoremap :silent! let &guifont = substitute( + \ &guifont, + \ ':h\zs\d\+', + \ '\=eval(submatch(0)+1)', + \ 'g') +nnoremap :silent! let &guifont = substitute( + \ &guifont, + \ ':h\zs\d\+', + \ '\=eval(submatch(0)-1)', + \ 'g') + +" Formatting options (see :h fo-table) +augroup persistent_settings + au! + au bufenter * :set formatoptions=q1j +augroup end + +" Return to the same line when a file is reopened +augroup line_return + au! + au BufReadPost * + \ if line("'\"") > 0 && line("'\"") <= line("$") | + \ execute 'normal! g`"zvzz' | + \ endif +augroup end + +" General Key Bindings +" ============================================================================== +" Map Ctrl+HJKL to navigate buffer window +nmap :wincmd h +nmap :wincmd j +nmap :wincmd k +nmap :wincmd l + +" Move by wrapped lines instead of line numbers +nnoremap j gj +nnoremap k gk +nnoremap gj j +nnoremap gk k + +" Map NERDTree to Ctrl-N +map :NERDTreeToggle + +" Change to current buffer's directory +nmap cd :cd =expand("%:p:h") + +" Buffer Splitting +nnoremap s :vs + +" Go to next error +" Go to previous error +nnoremap :cn +nnoremap :cp + +" FZF +" ============================================================================== +nnoremap f :FzfFiles +nnoremap t :FzfTags +nnoremap r :FzfRg +nnoremap b :FzfBuffers +nnoremap l :FzfLines + +" Empty value to disable preview window altogether +let g:fzf_preview_window = [] + +" Prefix all commands with Fzf for discoverability +let g:fzf_command_prefix = 'Fzf' + +" - down / up / left / right +let g:fzf_layout = { 'down': '40%' } + +" Clang Format +" ============================================================================== +map :py3file ~/clang-format.py + +" Compiler Error Formats +" ============================================================================== +" Error message formats thanks to +" https://forums.handmadehero.org/index.php/forum?view=topic&catid=4&id=704#3982 +set errorformat+=\\\ %#%f(%l\\\,%c):\ %m " MSVC: MSBuild +set errorformat+=\\\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m " MSVC: cl.exe +set errorformat+=\\\ %#%t%nxx:\ %m " MSVC: cl.exe, fatal errors is crudely implemented +set errorformat+=\\\ %#LINK\ :\ %m " MSVC: link.exe, can't find link library badly implemented +set errorformat+=\\\ %#%s\ :\ error\ %m " MSVC: link.exe, errors is badly implemented +set errorformat+=\\\ %#%s\ :\ fatal\ error\ %m " MSVC: link.exe, fatal errors is badly implemented +set errorformat+=\\\ %#%f(%l\\\,%c-%*[0-9]):\ %#%t%[A-z]%#\ %m " MSVC: HLSL fxc.exe +set errorformat+=%\\%%(CTIME%\\)%\\@=%m " ctime.exe -stats diff --git a/Installer/win_clang_merge_compilation_command_files.bat b/Installer/win_clang_merge_compilation_command_files.bat new file mode 100644 index 0000000..6df5f5e --- /dev/null +++ b/Installer/win_clang_merge_compilation_command_files.bat @@ -0,0 +1,45 @@ +@echo off +REM Merge multiple compilation command files generated by clang -MJ and dump it +REM to standard output as a JSON array. +REM +REM An entry generated by clang -MJ, looks like this: +REM +REM { +REM "directory": "/home/user/dev/llvm/build", +REM "file": "/tmp/foo.cpp", +REM "output": "foo.o", +REM "arguments": ["/usr/bin/clang-5.0", "-xc++", "/tmp/foo.cpp", "--driver-mode=g++", "-Wall", "-I", "/home/user/dev/libcpp/libcpp/include", "-c", "--target=x86_64-unknown-linux-gnu"] +REM } +REM +REM See: https://sarcasm.github.io/notes/dev/compilation-database.html#clang + +setlocal EnableDelayedExpansion +if [%1]==[] ( + echo Usage: %0 [compilation command files...] + exit /b -1 +) + +REM Count the number of arguments we received +set arg_count=0 +for %%x in (%*) do ( set /A arg_count+=1 ) + +REM Open a JSON array to splat the JSON compile commands objects into +echo [ + +REM Append the compile commands in +set arg_next_index=0 +for %%x in (%*) do ( + set /A arg_next_index+=1 + set /P contents=<%%x + + REM On the last compile command to append to the array, remove the trailing + REM comma on the JSON object + if !arg_next_index! == !arg_count! ( + set contents=!contents:~0,-1! + ) + + echo !contents! +) + +REM Close the JSON array +echo ] diff --git a/win_install.bat b/win_install.bat index 4d979b8..a9c12c7 100644 --- a/win_install.bat +++ b/win_install.bat @@ -267,10 +267,8 @@ call :MakeBatchShortcutInBinDir "clang++-!llvm_version!" "!llvm_bin_dir!\clang++ call :MakeBatchShortcutInBinDir "clang-cl++-!llvm_version!" "!llvm_bin_dir!\clang-cl++.exe" REM Clang Format -set clang_format_py_sha256=36ba7aa047f8a8ac8fdc278aaa733de801cc84dea60a4210973fd3e4f0d2a330 -set vim_clang_format=!vim_dir!\clang-format.py -call :CopyAndAlwaysOverwriteFile "!llvm_dir!\share\clang\clang-format.py" "!vim_clang_format!" || exit /B -call :FileHashCheck sha256 "!vim_clang_format!" "!clang_format_py_sha256!" || exit /B +set clang_format=!home_dir!\clang-format.py +call :CopyAndAlwaysOverwriteFile "!llvm_dir!\share\clang\clang-format.py" "!clang_format!" || exit /B REM Terminal echo set PATH=!llvm_bin_dir!;%%PATH%%>> "!tmp_terminal_script!" @@ -655,16 +653,13 @@ call :MakeBatchShortcutInBinDir "neovide" "!neovide_exe!" REM ---------------------------------------------------------------------------- REM Vim Configuration REM ---------------------------------------------------------------------------- -REM Vim Config -call :CopyAndAlwaysOverwriteFile "!installer_dir!\os_vimrc" "!home_dir!\.vimrc" - -REM Vim -> Nvim Config +REM Nvim Config set nvim_init_dir=!home_dir!\AppData\Local\nvim if not exist "!nvim_init_dir!" mkdir "!nvim_init_dir!" call :CopyAndAlwaysOverwriteFile "!installer_dir!\os_nvim_init.vim" "!nvim_init_dir!\init.vim" REM Vim Package Manager -set vim_plug_dir=!vim_dir!\autoload +set vim_plug_dir=!nvim_init_dir!\autoload set vim_plug=!vim_plug_dir!\plug.vim if not exist "!vim_plug_dir!" mkdir "!vim_plug_dir!" call :DownloadFile "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" "!vim_plug!" || exit /B