vimrc

set nocompatible
syntax on
filetype on
""set background=dark
set autoindent
set smartindent
set showmatch
set number
set tabstop=4
set vb t_vb=
set nowrap
set hlsearch
set incsearch
set backspace=indent,eol,start whichwrap+=<,>,[,]

:colorscheme asmanian2

map <F4> :silent! NERDTree<CR>

map <F3> :silent! Tlist<CR>
let Tlist_Ctags_Cmd='ctags'
let Tlist_Use_Right_Window=1
let Tlist_Show_One_File=0
let Tlist_File_Fold_Auto_Close=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Process_File_Always=0
let Tlist_Inc_Winwidth=0

map <F12> :call Do_CsTag()<CR>
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
function Do_CsTag()
    let dir = getcwd()
	    if filereadable("tags")
			let tagsdeleted=delete("./"."tags")
			if(tagsdeleted!=0)
	       		 echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
	       		 return
		    endif
	    endif


	    if has("cscope")
	        silent! execute "cs kill -1"
	    endif


	    if filereadable("cscope.files")
	        let csfilesdeleted=delete("./"."cscope.files")
	        if(csfilesdeleted!=0)
	          echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" |    echohl None
           return
	        endif
																																				    endif
	    if filereadable("cscope.out")
            let csoutdeleted=delete("./"."cscope.out")
	        if(csoutdeleted!=0)
           echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" |    echohl None
           return
																																        endif
	    endif

	    if(executable('ctags'))
	        "silent! execute "!ctags -R --c-types=+p --fields=+S *"
	        silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
	    endif
	    if(executable('cscope') && has("cscope") )
	    silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
	    silent! execute "!cscope -b"
	    execute "normal :"
		if filereadable("cscope.out")
	     execute "cs add cscope.out"
	    endif
	    endif
		redraw!
	endfunction


<think>好的,用户想知道如何正确保存vimrc文件或配置以确保生效。首先,我需要回忆一下vimrc的基本知识。记得vimrc文件通常位于用户的主目录下,文件名是.vimrc,对吧?用户可能需要先确认这个文件是否存在,如果不存在的话,可能需要新建一个。 然后,保存的位置是否正确很重要。比如在Linux或macOS下,路径应该是~/.vimrc,而Windows可能是用户的home目录下的_vimrc文件。有时候用户可能不小心保存到了错误的位置,导致配置没生效,所以需要提醒他们检查路径。 接下来,保存文件的步骤。用户可能使用vim编辑器来编辑vimrc,这时候需要知道如何保存并退出。比如在vim中按Esc,然后输入:wq。或者使用其他文本编辑器,保存时要注意文件名和位置。这时候可能需要分步骤说明,尤其是针对不同操作系统的用户。 另外,权限问题也可能导致配置不生效。比如文件权限不正确,可能需要用chmod修改。或者用户可能忘记让vim重新加载配置文件,可以建议他们执行:source ~/.vimrc或者在vim里运行:so %如果正在编辑的话。 还有可能用户修改了vimrc但没看到效果,这时候需要检查是否有语法错误。比如打开vim时如果有错误提示,可能需要排查配置中的问题。此外,可能提到使用:verbose命令来查看某个设置是否被覆盖,或者使用插件管理器时是否需要重新加载插件。 最后,可能需要提醒用户关于不同版本的vim可能有不同的配置方式,比如Neovim的init.vim位置不同。这些细节可以帮助用户避免常见的问题,确保他们的配置正确保存并生效。</think>要正确保存并应用 Vim 配置,需按以下步骤操作: ### 一、定位文件路径 1. **Linux/macOS**:`$HOME/.vimrc` 2. **Windows**:`$HOME/_vimrc` 或 `$HOME/vimfiles/vimrc` 使用命令验证路径:`vim --version | grep vimrc`[^1] ### 二、保存配置流程 1. **Vim 编辑器保存**: ```bash # 新建/编辑配置文件 vim ~/.vimrc # 编辑后按 Esc -> :wq 保存退出 ``` 2. **文本编辑器保存**: 确保文件: - 使用 UTF-8 编码 - 无扩展名(Windows 需注意隐藏扩展名) ### 三、配置生效方式 | 生效方式 | 命令/操作 | |--------------------------|------------------------------| | 重启 Vim | 关闭后重新打开编辑器 | | 即时重载 | `:source ~/.vimrc` | | 当前窗口重载 | `:so %`(在vimrc编辑窗口使用)| ### 四、故障排查 1. **权限验证**: ```bash chmod 644 ~/.vimrc # 设置正确权限 ``` 2. **语法检查**: ```vim :syntax on # 启用语法高亮辅助排查 :scriptnames # 查看加载的配置文件路径 ``` 3. **典型错误**: ```vim " 错误示例(缺少引号) set nocompatible syntax enable " 正确写法 colorscheme desert " 需要先安装主题 ``` ### 五、版本适配注意 - **Neovim**:使用 `~/.config/nvim/init.vim` - **多版本共存**:通过 `alias vim='/usr/local/bin/vim'` 指定路径
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值