vim-plug installation
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
if the command above can not work, you can just copy plug.vim into .vim/autoload
cd ~
git clone https://github.com/junegunn/vim-plug
mkdir .vim/autoload
cp vim-plug/plug.vim ~/.vim/autoload
vimrc example:
let mapleader=" " syntax on filetype on
set nocompatible
"set backspace=2 " when using MSYS2, it should add this command into .vimrc file
set mouse=a set scrolloff=5 set encoding=utf-8 colorscheme desert set nu set nocursorline set wrap set showcmd set wildmenu map S :w<CR> map s <nop> map Q :q<CR> map R :source ~/.vimrc<CR> noremap J 5j noremap K 5k "<operation> <motion>" set hlsearch exec "nohl" set incsearch set ignorecase set smartcase
set smartindent
set cindent
set autoread
set history=1000
set tabstop=4
set expandtab
set sw=4 noremap <LEADER>n :nohl<CR> nnoremap sl :set splitright<CR>:vsplit<CR> nnoremap sh :set nosplitright<CR>:vs<CR> nnoremap sj :set splitbelow<CR>:split<CR> nnoremap sk :set nosplitbelow<CR>:split<CR> nnoremap <LEADER>h <C-w>h nnoremap <LEADER>j <C-w>j nnoremap <LEADER>k <C-w>k nnoremap <LEADER>l <C-w>l
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
"resize the window nnoremap <up> :res +5<CR> nnoremap <down> :res -5<CR> nnoremap <left> :vertical resize+5<CR> nnoremap <right> :vertical resize-5<CR> "create the new file, after that name this file through command ':w<filename>' nnoremap tn :tabnew nnoremap tr :w nnoremap th :tabp<CR> nnoremap tl :tabn<CR> nnoremap of :edit "Comment: "+ is system register vnoremap P "+p call plug#begin('~/.vim/autoload')
Plug 'junegunn/fzf' Plug 'Shougo/defx.nvim'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
"Plug 'vim-scripts/autoload_cscope.vim'
Plug 'vim-scripts/taglist.vim'
" python
Plug 'vim-scripts/indentpython.vim'
call plug#end()
" ==============
" === cscope ===
" ==============
" 把autoload_cscope.vim放到~/.vim/plugin/目录中,然后修改autoload_cscope.vim
" "au BufEnter *.[chly] call <SID>Cycle_csdb() | call <SID>Cycle_macros_menus()
" "au BufEnter *.cc call <SID>Cycle_csdb() | call <SID>Cycle_macros_menus()
" "au BufUnload *.[chly] call <SID>Unload_csdb() | call <SID>Cycle_macros_menus()
" "au BufUnload *.cc call <SID>Unload_csdb() | call <SID>Cycle_macros_menus()
" au BufEnter * call <SID>Cycle_csdb() | call <SID>Cycle_macros_menus()
" au BufUnload * call <SID>Unload_csdb() | call <SID>Cycle_macros_menus()
" cscope -Rbkq × 生成3个文件,这样就能自动load cscope.out了
set cspc=6 "cscope的查找结果在格式上最多显示6层目录cscope
let g:autocscope_menus=0 "关闭autoscope插件的快捷键映射,防止和我们定义的快捷键冲突
nmap fc :cs find c <C-R>=expand("<cword>")<CR><CR> " function call 查找光标下函数被调用的地方
nmap fd :cs find d <C-R>=expand("<cword>")<CR><CR> " 查找当前函数所调用的函数
nmap fg :cs find g <C-R>=expand("<cword>")<CR><CR> " 查找函数,宏,枚举等定义的位置
nmap ft :cs find g <C-R>=expand("<cword>")<CR><CR> " 查找指定的字符串出现的地方
" ===
" === NERDTree
" ===
map tt :NERDTreeToggle<CR>
let NERDTreeMapOpenExpl = ""
let NERDTreeMapUpdir = ""
let NERDTreeMapUpdirKeepOpen = "l"
let NERDTreeMapOpenSplit = ""
let NERDTreeOpenVSplit = ""
let NERDTreeMapActivateNode = "i"
let NERDTreeMapOpenInTab = "o"
let NERDTreeMapPreview = ""
let NERDTreeMapCloseDir = "n"
let NERDTreeMapChangeRoot = "y"
" ===
" === Python-syntax
" ===
let g:python_highlight_all = 1
" let g:python_slow_sync = 0
" ===
" === ctags
" ===
" in the source directory, execute "ctags -R *"
set tags=tags;
set autochdir
nnoremap ff <c-]> "function forward
nnoremap fb <c-t> "function backward
" ===============
" === taglist ===
" ===============
let Tlist_Use_Right_Window = 1 "taglist窗口在右侧
let Tlist_Ctags_Cmd = '/usr/bin/ctags' "将taglist和ctags关联起来
let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,仅显示一个
let Tlist_Exit_OnlyWindow = 1 "taglist为最后一个窗口时,退出vim
"let Tlist_WinHeight = 100
"let Tlist_WinWidth = 40
nnoremap <F8> :TlistToggle<CR> "设置taglist打开关闭的shortcut为F8
nnoremap <F5> :!ctags -R *<CR> "在源代码的根目录下执行更新
vim usage
查看vim版本
1. 在shell下键入 vim --version
2. 在打开的vim编辑器内键入 :version
支持系统剪贴板
1. vim --version | grep clipboard 来查看xtem_clipboard前面是+还是-,如果是+,说明可用,如果是-,则不可用
2. 如果不可用,sudo apt-get install vim vim-scripts vim-gtk vim-gnome 来安装,安装完成后再次查看,应该能看到xterm_clipboard前是+
3. 在vim中使用shift+v来选择文本,"+y 来复制, 这样就复制到系统剪贴板上了,然后再在text或者网页端使用ctrl+v来粘贴了
同时打开多个文本文件, 而这些文本文件分别在不同的tab里, 可以使用tabn或tabp来switch
vim -p <file1> <file2> <file3> ...