set encoding=utf-8 fileencodings=utf-8
set tabstop=4
set number
set shiftwidth=4
set expandtab
set viminfo^=% " 记录上次编辑的位置
set viminfo='100,f1 " 保存最近 100 个文件的光标位置
set paste
set softtabstop=4
syntax on
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | execute "normal! g`\"" | endif
" 初始化插件管理器
call plug#begin('~/.local/share/nvim/plugged')
" 示例插件
Plug 'tpope/vim-surround' " 操作括号的插件
" Plug 'junegunn/fzf', { 'do': './install --all' } " 模糊查找
Plug 'neovim/nvim-lspconfig' " LSP 配置插件
Plug 'hrsh7th/nvim-cmp' " 自动补全插件
Plug 'hrsh7th/cmp-nvim-lsp' " LSP 的补全源
Plug 'lervag/vimtex' " 专为 LaTeX 设计的增强插件
Plug 'hrsh7th/vim-vsnip' " 代码片段插件
Plug 'hrsh7th/cmp-vsnip' " 代码片段补全源
call plug#end()
" 配置 vimtex
let g:vimtex_view_method = 'general'
let g:vimtex_view_general_viewer = 'open -a Preview'
let g:vimtex_compiler_progname = 'nvr' " 确保 Neovim 远程调用支持
let g:vimtex_quickfix_mode = 0 " 禁用 quickfix 窗口(可选)
" 使用 pdflatex 作为编译器
" let g:vimtex_compiler_pdflatex = {
" \ 'executable' : 'pdflatex',
" \ 'options' : [
" \ '-interaction=nonstopmode',
" \ '-synctex=1',
" \ ],
" \ }
" let g:vimtex_compiler_xelatex = {
" \ 'executable' : 'xelatex',
" \ 'options' : [
" \ '-interaction=nonstopmode',
" \ '-synctex=1',
" \ ],
" \ }
set number " 显示行号
" set relativenumber " 显示相对行号
set expandtab " 将 Tab 转换为空格
set shiftwidth=4 " 缩进宽度为 4
set tabstop=4 " Tab 显示宽度为 4
set clipboard=unnamedplus " 使用系统剪贴板
set list
set spell " 检查拼写
set listchars=space:␣,tab:→\ ,eol:¬
" 运行时自动保存并编译
autocmd FileType tex nnoremap c :w:VimtexClean
" 快捷键绑定:\x 使用 xelatex 编译
autocmd FileType tex nnoremap x :let g:vimtex_compiler_method='exlatex':VimtexCompile
" 快捷键绑定:\p 使用 pdflatex 编译
autocmd FileType tex nnoremap p :let g:vimtex_compiler_method='pdflatex':VimtexCompile
" 快捷键绑定:\s 切换连续模式
autocmd FileType tex nnoremap s :call ToggleCompileMode()
" 定义切换连续模式的函数
function! ToggleCompileMode()
if g:vimtex_compiler_pdflatex['options'][0] == '-interaction=nonstopmode'
let g:vimtex_compiler_pdflatex['options'][0] = '-interaction=errorstopmode'
let g:vimtex_compiler_xelatex['options'][0] = '-interaction=errorstopmode'
echo "Switched to interactive mode"
else
let g:vimtex_compiler_pdflatex['options'][0] = '-interaction=nonstopmode'
let g:vimtex_compiler_xelatex['options'][0] = '-interaction=nonstopmode'
echo "Switched to nonstop mode"
endif
endfunction
lua << EOF
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
[''] = cmp.mapping.select_next_item(), -- 下一个补全项
[''] = cmp.mapping.select_prev_item(), -- 上一个补全项
[''] = cmp.mapping.confirm({ select = true }), -- 确认补全
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' }, -- LSP 补全
{ name = 'vsnip' }, -- 代码片段补全
}, {
{ name = 'buffer' }, -- 当前缓冲区补全
{ name = 'path' }, -- 文件路径补全
})
})
EOF
" ---------------------------------------
" 配置 LSP(nvim-lspconfig)
" ---------------------------------------
lua << EOF
local lspconfig = require('lspconfig')
-- Python LSP
lspconfig.pyright.setup{}
-- LaTeX LSP
lspconfig.texlab.setup{
settings = {
texlab = {
build = {
executable = "latexmk", -- 编译工具
args = { "-pdf", "-interaction=nonstopmode", "-synctex=1" },
onSave = true, -- 保存时触发编译
},
forwardSearch = {
executable = "zathura", -- PDF 查看器,macOS 用户可换成 Preview
args = { "--synctex-forward", "%l:1:%f", "%p" },
},
lint = {
onChange = true, -- 文档修改时检查
},
},
},
}
EOF
这是一个简易网站,用于放置学习VIM的相关链接。