VIM笔记

自用的一些VIM基础配置

.vimrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
set nu
set autoread
set clipboard+=unnamed " 共享剪贴板
set ruler
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set mouse=a

syntax on " 打开语法高亮
colorschem gruvbox
filetype plugin indent on

" 自动补全括号引号大括号回车
" inoremap ' ''<ESC>i
" inoremap " ""<ESC>i
" inoremap ( ()<ESC>i
" inoremap [ []<ESC>i

inoremap { {}<ESC>i
" inoremap {<CR> {<CR>}<ESC>O

" function! ClosePair(char)
" if getline('.')[col('.') - 1] == a:char
" return "\<Right>"
" else
" return a:char
" endif
" endfunction

" 把快速按jj映射为Esc键
inoremap jj <Esc>


" Plugins will be downloaded under the specified directory.
call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')

" Declare the list of plugins.
Plug 'tpope/vim-sensible'
Plug 'junegunn/seoul256.vim'
Plug 'scrooloose/nerdtree'
Plug 'scrooloose/syntastic'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'valloric/youcompleteme'
Plug 'github/copilot.vim'
Plug 'rust-lang/rust.vim'

" List ends here. Plugins become visible to Vim after this call.
call plug#end()

" 文件导航 https://vimawesome.com/plugin/nerdtree-red
" NERDtree 键盘映射
nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
nnoremap <C-f> :NERDTreeFind<CR>
" NERDtree 自动关闭
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Close the tab if NERDTree is the only window remaining in it.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" 防止其他缓冲区替代NERDtree
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
\ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif

" 语法高亮 https://vimawesome.com/plugin/syntastic
" Syntastic 配置
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

" 底部状态栏 https://vimawesome.com/plugin/vim-airline-superman
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'default'

" 自动补全 https://vimawesome.com/plugin/youcompleteme
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_autoclose_preview_window_after_insertion=1
let g:ycm_confirm_extra_conf=0
set completeopt-=preview
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口
let g:ycm_seed_identifiers_with_syntax=1 " 语法关键字补全
let g:ycm_enable_diagnostic_signs = 1

" copilot插件配置
imap <silent><script><expr> <C-J> copilot#Accept("\<CR>")
let g:copilot_no_tab_map = v:true
" copilot选择下一个提示
imap <silent><script><expr> <C-]> copilot#Next()
" copilot选择上一个提示
imap <silent><script><expr> <C-[> copilot#Prev()

列删除

  1. 光标定位到要操作的地方。
  2. CTRL+v 进入“可视 块”模式,选取这一列操作多少行。
  3. d 删除。

列插入

插入操作的话稍有区别。例如我们在每一行前都插入”() “:

  1. 光标定位到要操作的地方。
  2. CTRL+v 进入“可视 块”模式,选取这一列操作多少行。
  3. SHIFT+i(I) 输入要插入的内容。
  4. ESC 按两次,会在每行的选定的区域出现插入的内容。

列替换

方法一:

  1. ctrl + v ,切换到块操作模式。
  2. 使用j. l等键进行上下左右操作,选中要替换的列。
  3. 选中之后,按下 c 键,输入要替换的内容。这个时候会看到只有第一行被键入。
  4. 按下 esc 键,退出块操作模式,这时所有列的字符都会被替换。

方法二:
选区,在 Visual 模式下选择区域后输入 : Vim 即可自动补全为 :'<,'>

1
:'<,'>s/foo/bar/g
Author

iN1t0

Posted on

2024-04-23

Updated on

2024-07-17

Licensed under