vim: make nvim/init.vim great again

This commit is contained in:
2025-08-04 11:33:10 +08:00
parent 855434df21
commit 292e6f0f0b
3 changed files with 135 additions and 2 deletions

133
nvim_init.vim Normal file
View File

@@ -0,0 +1,133 @@
if exists('g:vscode')
" VSCode extension.
" This is all the config for VSCode-Neovim.
" normal Nvim uses ~/.vimrc.
set backspace=2
set showmatch
set ruler
set mouse=a
set ts=4
set sw=4
set cindent
set cinoptions=:0,l1,g0
set nohlsearch
set ignorecase
set smartcase
set autochdir
set timeout timeoutlen=1000 ttimeoutlen=15
set title
set guicursor=a:blinkon0-Cursor
let g:netrw_mousemaps=0
set nu
set signcolumn=no
set updatetime=1000
"""""""""" Plugins """"""""""
set nocp
filetype plugin on
call plug#begin('~/.local/share/plugged')
let g:plug_url_format='git@github.com:%s.git'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'elkowar/yuck.vim'
Plug 'skywind3000/asyncrun.vim'
call plug#end()
"""""""""" Remaps """"""""""
command W w
map Q ZZ
func Semicolon()
let line = getline('.')
if match(line, "for") == -1 && match(line, "if") == -1
return "\<End>;"
else
return ';'
endif
endfunc
au BufNewFile,BufRead *.frag,*.vert,*.geom,*.fp,*.vp,*.glsl setf glsl
augroup vimrc_cmaps
autocmd FileType c,cpp,rust,typescript inoremap <buffer><expr> ; Semicolon()
autocmd FileType vim,c,cpp,go,rust,python,typescript,tex inoremap <buffer> ( ()<Left>
autocmd FileType vim,c,cpp,go,rust,python,typescript,tex inoremap <buffer> [ []<Left>
autocmd FileType vim,c,cpp,go,rust,python,typescript inoremap <buffer> " ""<Left>
autocmd FileType vim,c,cpp,go,rust,python,typescript inoremap <buffer> ' ''<Left>
autocmd FileType c,cpp,go,rust,typescript inoremap <buffer> { <End>{<CR>}<Up><End><CR>
autocmd FileType c,cpp,go,rust,typescript inoremap <buffer> <C-]> {}<Left>
autocmd FileType vim,tex,python inoremap <buffer> { {}<Left>
autocmd FileType vim,tex,python inoremap <buffer> <C-]> <End>{<CR>}<Up><End><CR>
augroup END
" Guess what? Despite Neovim being smart enough to distinguish
" <Ctrl-I> from <Tab>, it treats <Ctrl-I> as <Tab> anyways if
" you have a normal mode mapping for <Tab>. Screw me I guess.
" Edit: My bad - Please refer to :h <Tab> or :h CTRL-I. Maybe
" learn to read sometime this century.
"
" https://vi.stackexchange.com/a/46704
" https://github.com/neovim/neovim/pull/17932
"
" This magical line tricks Nvim into being smart again.
nnoremap <C-I> <C-I>
" Use Meta-HJKL for Left/Down/Up/Right.
imap <M-H> <Left>
imap <M-J> <Down>
imap <M-K> <Up>
imap <M-L> <Right>
"""""""""" AsyncRun """"""""""
let g:asyncrun_open = 1
" Deactivate IME when leaving Insert mode.
au InsertLeavePre * AsyncRun -silent which fcitx5-remote >/dev/null && fcitx5-remote -c
"""""""""" Misc """"""""""
set tags+=~/.cache/ctags
lang zh_CN.UTF-8
" Uncomment the following to have Vim jump to the last position when
" reopening a file
au BufReadPost * exe "normal! g'\""
set showmode
else
" ordinary Neovim
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vimrc
endif

View File

@@ -9,7 +9,7 @@ mkdir -pv ../.config/nvim
ln -sriv vimrc ../.vimrc
ln -sriv vimrc ../.config/nvim/init.vim
ln -sriv nvim_init.vim ../.config/nvim/init.vim
ln -sriv zshrc.minimal ../.zshrc
ln -sriv coc-settings.json ../.config/nvim/coc-settings.json
ln -sriv _clang-format ../.clang-format

View File

@@ -10,7 +10,7 @@ mkdir -pv ../.oh-my-zsh/themes
ln -sriv vimrc ../.vimrc
ln -sriv vimrc ../.config/nvim/init.vim
ln -sriv nvim_init.vim ../.config/nvim/init.vim
ln -sriv oh.my.zshrc ../.zshrc
ln -sriv coc-settings.json ../.config/nvim/coc-settings.json
ln -sriv _clang-format ../.clang-format