本贴持续更新~,用到时记录
模式
i
进入编辑模式,正常编辑模式- 选择模式
v
进入可视化选择模式ctrl+v
进入块选择模式
:
进入命令模式
基本操作
y
,全称为yank
表示拖拽的意思,实际为复制- 为:选择模式
- 复制/粘贴到剪贴板
MacOSX
:使用pbcopy/pbpaste
指令协助完成- 复制:
:%w !pbcopy
- 粘贴:
:r !pbpaste
- 复制:
Linux
:使用xclip
完成,若不存在则需要编译或使用apt、yum、pacman
等工具安装- 复制:
:%w !xclip -i -sel -c
或:%w !xsel -i -b
- 粘贴:
:%w !xclip -o -sel -c
或:%w !xclip -o -b
- 安装
xclip
:
- 复制:
d
,为delete
,表示删除dd
剪切整行
G
,为行首$
,表示文档结尾
键盘映射操作
:map <键盘按键> <执行的指令>
- 如
:map <F10>
- 如果键盘按键为
ctrl+p
,则^p
要连续打出!不是^和p,可以使用ctrl+v+p
打出:map <F10> <ESC>:s/^/#/g<CR>
则表示在行首加上#
注释
- 如
附加操作
:set nu
,为显示行号:set nonu
,为取消行号
Vundle的安装
vundle
为vim
的包管理器
我的.vimrc.bundles
内容为:
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
if &compatible
set nocompatible
end
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" Let Vundle manage Vundle
Bundle 'gmarik/vundle'
" Define bundles via Github repos
" 标签导航
Bundle 'majutsushi/tagbar'
Bundle 'vim-scripts/ctags.vim'
" 静态代码分析
Bundle 'scrooloose/syntastic'
" 文件搜索
Bundle 'kien/ctrlp.vim'
" 目录树导航
Bundle "scrooloose/nerdtree"
" 美化状态栏
Bundle "Lokaltog/vim-powerline"
" 主题风格
Bundle "altercation/vim-colors-solarized"
Bundle "sickill/vim-monokai"
" python自动补全
Bundle 'davidhalter/jedi-vim'
Bundle "klen/python-mode"
" 括号匹配高亮
Bundle 'kien/rainbow_parentheses.vim'
" 可视化缩进
Bundle 'nathanaelkane/vim-indent-guides'
if filereadable(expand("~/.vimrc.bundles.local"))
source ~/.vimrc.bundles.local
endif
filetype on
.vimrc配置
分享下我使用的vimrc文件,主要为Python IDE
- 支持代码类型提示
\tb
打开代码函数及变量显示\nt
打开目录结构\ff
文件搜索ctrl+w+w
切换窗口F5
直接运行Python
文件- …
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
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
set backspace=2
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
endif
" tagbar标签导航
nmap <Leader>tb :TagbarToggle<CR>
let g:tagbar_ctags_bin='/usr/local/bin/ctags'
let g:tagbar_width=30
autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.cxx call tagbar#autoopen()
let g:jedi#auto_initialization = 1
" 主题 solarized
let g:solarized_termtrans=1
let g:solarized_contrast="normal"
let g:solarized_visibility="normal"
" 配色方案
set background=dark
set t_Co=256
colorscheme monokai
" 目录文件导航NERD-Tree
" \nt 打开nerdree窗口,在左侧栏显示
nmap <leader>nt :NERDTree<CR>
let NERDTreeHighlightCursorline=1
let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.obj$', '\.o$', '\.so$', '\.egg$', '^\.git$', '^\.svn$', '^\.hg$' ]
let g:netrw_home='~/bak'
"close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | end
" ctrlp文件搜索
" 打开ctrlp搜索
let g:ctrlp_map = '<leader>ff'
let g:ctrlp_cmd = 'CtrlP'
" 相当于mru功能,show recently opened files
map <leader>fp :CtrlPMRU<CR>
" set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux"
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|rvm)$',
\ 'file': '\v\.(exe|so|dll|zip|tar|tar.gz)$',
\ }
"\ 'link': 'SOME_BAD_SYMBOLIC_LINKS',
let g:ctrlp_working_path_mode=0
let g:ctrlp_match_window_bottom=1
let g:ctrlp_max_height=15
let g:ctrlp_match_window_reversed=0
let g:ctrlp_mruf_max=500
let g:ctrlp_follow_symlinks=1
" vim-powerline美化状态
" let g:Powerline_symbols = 'fancy'
let g:Powerline_symbols = 'unicode'
" 括号匹配高亮
let g:rbpt_colorpairs = [
\ ['brown', 'RoyalBlue3'],
\ ['Darkblue', 'SeaGreen3'],
\ ['darkgray', 'DarkOrchid3'],
\ ['darkgreen', 'firebrick3'],
\ ['darkcyan', 'RoyalBlue3'],
\ ['darkred', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['brown', 'firebrick3'],
\ ['gray', 'RoyalBlue3'],
\ ['black', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['Darkblue', 'firebrick3'],
\ ['darkgreen', 'RoyalBlue3'],
\ ['darkcyan', 'SeaGreen3'],
\ ['darkred', 'DarkOrchid3'],
\ ['red', 'firebrick3'],
\ ]
let g:rbpt_max = 40
let g:rbpt_loadcmd_toggle = 0
" 可视化缩进
let g:indent_guides_enable_on_vim_startup = 0 " 默认关闭
let g:indent_guides_guide_size = 1 " 指定对齐线的尺寸
let g:indent_guides_start_level = 2 " 从第二层开始可视化显示缩进
filetype plugin on
autocmd FileType python set omnifunc=python3complete#Complete
let g:tagbar_ctags_bin = "/usr/local/bin/ctags"
syntax on
map <F5> :w<cr>:!python3 %<cr>