vimrc
vim的配置文件为.vimrc
系统范围的初始化配置
/etc/vimrc
个人的vim初始化配置
~/.vimrc
"设置前导符
let mapleader = "\<space>"
"显示行号
set number
"设置支持鼠标,光标定位,滚轮上下移动
"设置支持鼠标,光标定位,滚轮上下移动
set mouse=a
"全选
" 将全选ggvG映射为<C-A>,原本<C-A>是将一个数字加1,或字母加一,没啥用
map <C-A> ggVG "全选
"括号匹配(不建议使用,会使粘贴其他文字时产生错误)
inoremap ( ()<LEFT>
inoremap [ []<LEFT>
inoremap { {}<LEFT>
inoremap " ""<LEFT>
inoremap ' ''<LEFT>
"切换缓冲区,关闭缓冲区
"切换缓冲区,关闭缓冲区
nnoremap <C-i> :bp<CR>
nnoremap <C-o> :bn<CR>
nnoremap <C-d> :bd<CR>
" 选中当前单词
"选中当前单词
nnoremap <leader><C-w> viw
" 搜索当前选中的东西
"搜索当前选中的东西
noremap <leader><C-f> y/<C-r>"<CR>
"强制使用hjkl
"强制使用hjkl
noremap <Up> <Nop>
noremap <Down> <Nop>
noremap <Left> <Nop>
noremap <Right> <Nop>
"设置 使用复制的单词覆盖当前单词
"设置 使用复制的单词覆盖当前单词
noremap viwpyiw
"设定 tab 长度为 2
"设定 tab 长度为 2
set tabstop=2
"切换缓冲区,关闭缓冲区
"切换缓冲区,关闭缓冲区
nnoremap <leader>h :bp<CR>
nnoremap <leader>l :bn<CR>
nnoremap <leader>d :bd<CR>
"设置 自动缩进的 tab 长度 为2
"设置 自动缩进的 tab 长度 为2
set shiftwidth=2
"设置vim撤销永久化
"设置vim撤销永久化
set undofile
if !isdirectory($HOME ."/.vim/undodir")
call mkdir($HOME ."/.vim/undodir","p")
endif
set undodir=~/.vim/undodir
set number relativenumber 的四种变化说明
It's the expected behavior. From :help number_relativenumber
The 'relativenumber' option changes the displayed number to be relative to the cursor. Together with 'number' there are these four combinations (cursor in line 3):
'nonu' 'nu' 'nonu' 'nu'
'nornu' 'nornu' 'rnu' 'rnu'
|apple | 1 apple | 2 apple | 2 apple
|pear | 2 pear | 1 pear | 1 pear
|nobody | 3 nobody | 0 nobody |3 nobody
|there | 4 there | 1 there | 1 there
"切换行号模式(四种组合循环1)
"Relative with start point or with line number or absolute number lines
nnoremap <C-n> :call NumberToggle()<CR>
function! NumberToggle()
if(&number==0)
set number
else
set number!
if(&relativenumber==0)
set relativenumber
else
set relativenumber!
endif
endif
endfunction
"切换行号模式(四种组合循环2)
"Relative with start point or with line number or absolute number lines
nnoremap <C-n> :call NumberToggle()<CR>
function! NumberToggle()
if(&number == 1)
set number!
set relativenumber!
elseif(&relativenumber==1)
set relativenumber
set number
else
set norelativenumber
set number
endif
endfunction
"切换行号模式(两种组合循环)
"Relative with start point or with line number or absolute number lines
nnoremap <C-n> :call NumberToggle()<CR>
function! NumberToggle()
if(&relativenumber==1)
set norelativenumber
else
set relativenumber
endif
endfunction
"运行快捷键(linux)
nnoremap <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec '!g++ % -o %<'
exec '!time ./%<'
elseif &filetype == 'cpp'
exec '!g++ % -o %<'
exec '!time ./%<'
elseif &filetype == 'python'
exec '!time python %'
elseif &filetype == 'sh'
:!time bash %
endif
endfunc
"运行快捷键(windows)
"运行代码:
nnoremap <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec '!g++ % -o %<'
exec '!%<'
elseif &filetype == 'cpp'
exec '!g++ % -o %<'
exec '!%<'
elseif &filetype == 'python'
exec '!python %'
elseif &filetype == 'sh'
:!bash %
endif
endfunc
linux样例:
let mapleader = "\<space>"
syntax on " 语法高亮
set number "显示行号
set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set backspace=indent,eol,start "打开退格建<Backspace>的退格功能
"设置支持鼠标,光标定位,滚轮上下移动
set mouse=a
" 自动缩进
set autoindent
set cindent
"设置 自动缩进的 tab 长度 为2
set shiftwidth=2
" 缩进长度
set tabstop=4
"强制使用hjkl
noremap <Up> <Nop>
noremap <Down> <Nop>
noremap <Left> <Nop>
noremap <Right> <Nop>
"将全选ggvG映射为<C-A>,原本<C-A>是将一个数字加1,或字母加一,没啥用
map <C-A> ggVG "全选
"切换缓冲区,关闭缓冲区
nnoremap <leader>h :bp<CR>
nnoremap <leader>l :bn<CR>
nnoremap <leader>d :bd<CR>
"选中当前单词
nnoremap <leader><C-w> viw
"搜索当前选中的东西
noremap <leader><C-f> y/<C-r>"<CR>
"设置vim撤销永久化
set undofile
if !isdirectory($HOME ."/.vim/undodir")
call mkdir($HOME ."/.vim/undodir","p")
endif
set undodir=~/.vim/undodir
"运行代码:
nnoremap <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec '!g++ % -o %<'
exec '!time ./%<'
elseif &filetype == 'cpp'
exec '!g++ % -o %<'
exec '!time ./%<'
elseif &filetype == 'python'
exec '!time python %'
elseif &filetype == 'sh'
:!time bash %
endif
endfunc
"Relative with start point or with line number or absolute number lines
nnoremap <C-n> :call NumberToggle()<CR>
function! NumberToggle()
if(&number==0)
set number
else
set number!
if(&relativenumber==0)
set relativenumber
else
set relativenumber!
endif
endif
endfunction
let mapleader="\<space>"
syntax on " 语法高亮
set number "显示行号
set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set backspace=indent,eol,start "打开退格建<Backspace>的退格功能
" 设置支持鼠标,光标定位,滚轮上下移动
let &t_ti.="\e[1 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"
" set mouse=a
" copy cross vim
set clipboard=unnamedplus
" 自动缩进
set autoindent
set cindent
"设置 自动缩进的 tab 长度 为2
set shiftwidth=4
" 缩进长度
set tabstop=4
"强制使用hjkl
"noremap <Up> <Nop>
"noremap <Down> <Nop>
"noremap <Left> <Nop>
"noremap <Right> <Nop>
"将全选ggvG映射为<C-A>,原本<C-A>是将一个数字加1,或字母加一,没啥用
map <C-A> ggVG "全选
"切换缓冲区,关闭缓冲区
nnoremap <leader>h :bp<CR>
nnoremap <leader>l :bn<CR>
nnoremap <leader>d :bd<CR>
" 打开explorer
nnoremap <leader>e :E<CR>
"<C-d> 向上翻页并将光标居中,<C-f>向下翻页并将光标居中
nnoremap <C-b> <C-b>M
nnoremap <C-f> <C-f>M
" 选中当前单词
nnoremap <leader><C-w> viw
" 搜索当前选中的东西
noremap <leader><C-f> y/<C-r>"<CR>
"设置 使用复制的单词覆盖当前单词
noremap pw viwpyiw
" 设置水平分割和竖直分割
"nnoremap <leader>hh <C-w><C-s>
"nnoremap <leader>vv <C-w><C-v>
:command -nargs=0 Q :q
:command -nargs=0 W :w
" not support little letter start user command
":command -nargs=0 wQ :wq
:command -nargs=0 Wq :wq
:command -nargs=0 WQ :wq
"运行代码:
nnoremap <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec '!g++ % -o %<'
exec '!time ./%<'
elseif &filetype == 'cpp'
exec '!g++ --std=c++20 % -o %<'
exec '!time ./%<'
elseif &filetype == 'python'
exec '!time python %'
elseif &filetype == 'sh'
:!time bash %
endif
endfunc
"Relative with start point or with line number or absolute number lines
nnoremap <C-n> :call NumberToggle()<CR>
function! NumberToggle()
if(&number==0)
set number
else
set number!
if(&relativenumber==0)
set relativenumber
else
set relativenumber!
endif
endif
endfunction
xnoremap * :<C-u>call <SID>VSetSearch()<CR>/<C-R>=@/<CR><CR>N
xnoremap # :<C-u>call <SID>VSetSearch()<CR>?<C-R>=@/<CR><CR>
function! s:VSetSearch()
let temp = @s
norm! gv"sy
let @/ = '\V' . substitute(escape(@s, '/\'), '\n', '\\n', 'g')
let @s = temp
endfunction