vim 配置——manjaro xfce4环境

本文详细介绍了在Manjaro XFCE4环境下配置vim的过程,包括添加系统剪贴板支持、映射Caps Lock为Ctrl、修改光标样式、安装与配置vundle、插件、主题和字体,以及YouCompleteMe的C++和Python配置。此外,还涵盖了ctags、tagbar、EasyMotion、fzf的安装、tmux和tmuxinator的使用,vim中文文档、UltiSnips、nerdcommenter、vim-autoformat等插件的配置,以及 Vim 的其他高级功能设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为vim添加系统剪贴板

https://vi.stackexchange.com/questions/3076/how-do-i-use-the-system-clipboard-with-vim-in-arch-linux
总结:删除vim安装gvim但不使用gvim。只是让vim建立与libx的连接

sudo pacman -S gvim

capslock映射为ctrl

参考:https://blog.yxwang.me/2009/05/caps-lock-to-ctrl/
总结:使用xmodmap这个工具
修改前记得先备份当前的键位映射,

xmodmap -pke > xmodmap.backup

接下来运行

xmodmap -e 'keycode 66 = Control_L'
xmodmap -e 'clear Lock'
xmodmap -e 'add Control = Control_L'

这样就修改了Caps Lock的键位映射而不需要重启x,如果要在每次启动时自动修改Caps Lock键的映射,可以新建/修改一个.Xmodmap或者.xmodmap的文件,

vim .xmodmap

在里面加入

keycode 66 = Control_L
clear Lock
add Control = Control_L

在.zshrc中加入:

xmodmap /home/yszc/.xmodmap 

终端启动时出现问题:xmodmap: please release the following keys within 2 seconds: Control_L (...
参考:https://bbs.deepin.org/forum.php?mod=viewthread&tid=43109&extra=page%3D1
错误出现原因:
你是不是在你的rc文件加入了xmodmap的操作?,比如.bashrc如果是bash的话,可能你在里面加了xmodmap ~/.Xmodmap? 如果你加了的话,你每次在开启一个bash的时候,xmodmap的命令都会被执行,好的做法是加到profile文件中去,如.bash_profile等。

再参考:https://blog.csdn.net/thisishenryzhang/article/details/77892630 删除.zshrc中的xmodmap… 在/etc/zsh/zprofile 中加入xmodmap /home/yszc/.xmodmap 效果待检验。失败。 再再参考:https://forum.manjaro.org/t/how-to-execute-a-command-at-the-system-startup/1972 将该命令加入到 /etc/profile 中,检验效果:失败 再来:选项->会话和启动->应用程序自启动 添加 xmodmap /home/yszc/.xmodmap 再再再参考:https://blog.csdn.net/u014717036/article/details/57082204 失败 再参考:https://bbs.archlinux.org/viewtopic.php?id=67363 再参考:https://askubuntu.com/questions/1083637/file-xmodmap-is-not-sourced-on-startup-in-18-04 再来:https://wiki.archlinux.org/index.php/Xmodmap_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87) 受不了:https://askubuntu.com/questions/54157/how-do-i-set-xmodmap-on-login 终于解决:
解决方法:参考(https://askubuntu.com/questions/54157/how-do-i-set-xmodmap-on-login )

Please note: if you are on Xfce, it is noted on the official Xfce FAQ
that you may have to create a startup item instead of using
~/.xinitrc, and that you might have to delay the execution so the
xmodmap changes are not overwritten by setxkbmap. You can use a delay
to achieve this in your startup entry:

/bin/bash -c "sleep 20; /usr/bin/xmodmap /home/$USER/.Xmodmap"

选项->会话和启动->应用程序自启动
添加 /bin/bash -c “sleep 20; /usr/bin/xmodmap /home/$USER/.Xmodmap”

3.新建.vimrc输入下面的代码: (暂时不用鼠标功能,翻页用n模式下c-j c-k,具体定位用EasyMotion)

" 基本设置----------------{
  
  {
  
  {
" 不兼容vi模式 必须放在第一行
set nocompatible
" 开启语法高亮
syntax on
" 高亮当前行
set cursorline
" 开启搜索高亮
set incsearch
" 设定历史记录数
set history =50
" 设定为系统剪贴板
set clipboard=unnamedplus
" 消除~后缀备份文件
set nobackup
" 消除un后缀备份文件
set noundofile
" 显示行号
set number
" 高亮搜索项
set hlsearch
" 用空格代替tab键
" 设置tab宽度,为了符合google c++标准将4空格换位2空格节省横向空间
set tabstop=2
" 设置缩进宽度
set shiftwidth=2
" 用空格代替tab,问题:用空格代替tab会导致一些快捷键无法使用
" 可以尝试用 c-j/k 来选择
set expandtab
" 设置mapleader为逗号
let mapleader=","
" 设置编码
set encoding=utf-8
language messages zh_CN.utf-8
"}}}

" 全局变量------------------{
  
  {
  
  {
let g:author="yszc"
" }}}

 " 映射-------------------{
  
  {
  
  {
" C-W +j/k/l/h可以移动窗口光标,不用按多次w
" CTRL-A 是全选
nnoremap <c-a> ggvG
" 高亮开关
nnoremap <leader>hl :set hlsearch!<cr>
" 定义快速打开加载.vimrc和.vimrc.vundle文件
nnoremap <leader>ev :split $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
nnoremap <leader>ep :split $HOME/.vimrc.vundle<cr>
" nnoremap <c-e> :echo "hi"<cr>
" insert 模式括号匹配
" inoremap < <><esc>i
inoremap [ []<esc>i
inoremap { {}<esc>i
inoremap ( ()<esc>i
inoremap ' ''<esc>i
inoremap " ""<esc>i

" c-j/k映射成翻页键
nnoremap <c-j> <c-f>
nnoremap <c-k> <c-b>

" H映射为0,L映射为$
nnoremap 0 <nop>
nnoremap $ <nop>
nnoremap H 0
nnoremap L $
vnoremap H 0
vnoremap L $
" 操作符号重映射
onoremap H 0
onoremap L $

" J/K向上/下移动一段?一页?还是easymotion
" 方向键习惯改掉
nnoremap <Left> <nop>
nnoremap <Up> <nop>
nnoremap <Right> <nop>
nnoremap <Down> <nop>
inoremap <Left> <nop>
inoremap <Up> <nop>
inoremap <Right> <nop>
inoremap <Down> <nop>
" insert模式下方向键
inoremap <C-H> <Left>
inoremap <C-L> <Right>
inoremap <C-J> <Down>
inoremap <C-K> <Up>
" insert模式jk代替<esc>
" 将inoremap模式下的<esc>映射为空导致了方向键和翻页键乱码的情况
inoremap <esc> <nop>
inoremap jk <esc>
" 快速保存,退出
nnoremap <C-S> :w<cr>
nnoremap <C-Q> :q<cr>
" 不能映射normal模式下的esc键,因为方向键和翻页键的前缀是esc
" 这会导致在键入方向键或翻页键时退出,并且失灵
" nnoremap <esc> :q
"}}}

修改zsh和vim光标样式(zsh改为竖线,vim改为方块竖线切换):

参考:
https://blog.csdn.net/xiaohui5319/article/details/7507042
https://unix.stackexchange.com/questions/433273/changing-cursor-style-based-on-mode-in-both-zsh-and-vim
总结:
.zshrc中加入:

# 改变光标样式为竖线
echo -ne '\e[5 q'

.vimrc中加入:

" 自动命令组----------------{
  
  {
  
  {
" 光标切换
augroup cursor_switch
    autocmd!
    au InsertLeave * silent exec "! echo -ne '\e[1 q'"
    au InsertEnter * silent exec "! echo -ne '\e[5 q'" 
    au VimLeave * silent exec "! echo -ne '\e[1 q'"
    au VimEnter * silent exec "! echo -ne '\e[1 q'"
augroup END
" }}}

安装并配置vundle(插件配置见下文)

新建.vimrc.vundle,粘贴下面的文本:(注意set rtp += 要包含正确的目录)

   set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
set rtp+=~/.fzf/
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
" 删除或添加插件后要重新加载vimrc后执行vundle才有效果
Plugin 'VundleVim/Vundle.vim'

Plugin 'morhetz/gruvbox'

Plugin 'scrooloose/nerdtree'

Plugin 'vim-airline/vim-airline'

Plugin 'Valloric/YouCompleteMe'

Plugin 'majutsushi/tagbar'

Plugin 'easymotion/vim-easymotion'

Plugin 'junegunn/fzf.vim'

Plugin 'yianwillis/vimcdoc'

Plugin 'SirVer/ultisnips'

Plugin 'scrooloose/nerdcommenter'

Plugin 'Chiel92/vim-autoformat'

Plugin 'Yggdroot/indentLine'
" Plugin 'haya14busa/incsearch.vim'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

在.vimrc开头加入下面代码:

" 加载vundle配置文件
source $HOME/.vimrc.vundle

在vim执行

:PluginInstall

初步配置一些插件、主题和字体

下载DejaVu字体,将下载下来的ttf文件放入/usr/share/fonts中

字体下载参考:https://blog.csdn.net/devil_pull/article/details/17206377
vimrc写法参考:https://stackoverflow.com/questions/20015138/how-to-set-font-to-be-dejavu-sans-mono-in-vim-for-xp

.vimrc中加入:

" 插件配置---------------{
  
  {
  
  {

" 主题字体----------------------------{
  
  {
  
  {
colorscheme gruvbox
set background=dark
set guifont=DejaVu\ Sans\ Mono:h12
" }}}


" nerdtree-------------------{
  
  {
  
  {
" q是退出
" F1触发
nnoremap <F1> :NERDTreeToggle<cr>
" 打开文件时退出
let g:NERDTreeQuitOnOpen = 1
" }}}


"}}}

安装youcompleteme

先用vundle安装youcompleteme

Plugin 'Valloric/YouCompleteMe'

安装过程参考官方教程 https://github.com/Valloric/YouCompleteMe#linux-64-bit ,

安装过程总结:
我安装了cmake llvm clang

sudo pacman -S cmake llvm clang

但是build-essential和python3-dev manjaro没有,装不了,(但没发现有什么影响)。
然后进入ycm目录

   cd .vim/bundle/YouCompleteMe  

执行(我需要c++补全):

python3 install.py --clangd-completer

打开vim没有出现ycm报错信息,安装成功

问题: 在vim中:PluginInstall 发现错误:no module named future 解决:
子模块未安装完整导致。进入YouCompleteMe目录

cd .vim/bundle/YouCompleteMe   

使用以下命令可以更新所有子模块。

git submodule update --init --recursive 

见文章http://www.jianshu.com/p/d908ce81017a?nomobile=yes

ycm C++配置(重点是.ycm_extra_config)

参考:
先完整阅读官方user’s guide:https://github.com/Valloric/YouCompleteMe#option-2-provide-the-flags-manually
整体参考:https://blog.csdn.net/yangcs2009/article/details/45506749
整体参考:https://www.hahack.com/codes/cmake/
.ycm_extra_conf配置参考:https://www.jianshu.com/p/5aaae8f036c1
输出编译器默认包含目录:https://blog.csdn.net/jing35030401/article/details/17303971
默认包含目录的读法:https://blog.csdn.net/yasi_xi/article/details/8833094

总结:
先配置ycm_conf文件以及vimrc,后期熟悉cmake再用cmake生成的database补全。
参考上文ycm.conf配置参考,将clang的默认包含目录放到ycm.conf中,

具体步骤:
1.复制官网的.ycm_extra_conf示例文件到家目录中,修改.ycm_extra_conf,添加 clang++的基本包含路径(clang++的路径与clang一样)
修改后的.ycm_extra_conf:

from distutils.sysconfig import get_python_inc
import platform
import os
import subprocess
import ycm_core

DIR_OF_THIS_SCRIPT = os.path.abspath( os.path.dirname( __file__ ) )
# 注意为了用vim打开.py文件时读取到家目录中的此
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值