# vim **Repository Path**: emmix/vim ## Basic Information - **Project Name**: vim - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-13 - **Last Updated**: 2023-04-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Vim for Programmers ================== [toc] # Basics ## fold/unfold zf 折叠选中的文本 zfa{ 折叠括号(比如()、[]、{}、><等)包围的区域 za 打开/关闭当前的折叠 zi unfold all folding :mkview # 保存当前的折叠状态 :loadview # 载入记忆的折叠信息 ## show current file's direcotry :f ## open directory of current file http://vimcasts.org/episodes/the-file-explorer lazy mnemonic open file explorer :e. :edit . at current working directory :sp. :split . in split at current working directory :vs. :vsplit . in vertical split at current working directory :E :Explore at directory of current file :Se :Sexplore in split at directory of current file :Vex :Vexplore in vertical split at directory of current file ## line mode Stand on the beginning of the column Press Ctrl+V, then mark across the column you want to edit. Press I to insert text at the beginning of the column, A to append text, r to replace highlighted text, d to delete, c to change... etc. Hit ESC twice when done. # Plugins ## NerdTree http://www.jianshu.com/p/eXMxGx http://yang3wei.github.io/blog/2013/01/29/nerdtree-kuai-jie-jian-ji-lu/ http://www.jianshu.com/p/eXMxGx o 打开关闭文件或者目录 t 在标签页中打开 gt , gT 可以直接在tab之间切换 T 在后台标签页中打开 ! 执行此文件 p 到上层目录 P 到根目录 K 到第一个节点 J 到最后一个节点 u 打开上层目录 m 显示文件系统菜单(添加、删除、移动操作) ? 帮助 q 关闭 i Open selected file in a split window gi Same as i, but leave the cursor on the NERDTree s Open selected file in a new vsplit gs ame as s, but leave the cursor on the NERDTree https://github.com/scrooloose/nerdtree ? help o open/close file/dir t/T open in the (background)tab, use "gt/gT" switch between tabs i/gi open selected file in a split window, 'gi' same as 'i', but leave the cursor on the NERDTree s/gs open selected file in a new vsplit, 'gs' same as 's', but leave the cursor on the NERDTree u open upper folder K jump to first node J jump to last node p/P jump upper/root folder m delete/add file/directory ## ctag gd jump to local definition ctrl+] jump to definition ctrl+t return ctrl+o ## cscope see '~/.vim/plugged/cscope_maps.vim/plugin/cscope_maps.vim' for shor-keys cscope and auto load cscope.out ### ~/.vim/vimrc Plug 'diabloneo/cscope_maps.vim' Plug 'vim-scripts/autoload_cscope.vim' ### Support cpp change vim-scripts/autoload_cscope.vim for .hpp and .cpp file ```bash jfeng@jfeng-HP-ProBook-640-G1:autoload_cscope.vim$ git diff diff --git a/plugin/autoload_cscope.vim b/plugin/autoload_cscope.vim index 6e8d96d..749fa2f 100644 --- a/plugin/autoload_cscope.vim +++ b/plugin/autoload_cscope.vim @@ -176,8 +176,12 @@ augroup autoload_cscope au! au BufEnter *.[chly] call Cycle_csdb() | call Cycle_macros_menus() au BufEnter *.cc call Cycle_csdb() | call Cycle_macros_menus() + au BufEnter *.hpp call Cycle_csdb() | call Cycle_macros_menus() + au BufEnter *.cpp call Cycle_csdb() | call Cycle_macros_menus() au BufUnload *.[chly] call Unload_csdb() | call Cycle_macros_menus() au BufUnload *.cc call Unload_csdb() | call Cycle_macros_menus() + au BufUnload *.hpp call Unload_csdb() | call Cycle_macros_menus() + au BufUnload *.cpp call Unload_csdb() | call Cycle_macros_menus() augroup END ``` ## Ctrlp.vim https://kien.github.io/ctrlp.vim/ https://github.com/kien/ctrlp.vim Use , or the arrow keys to navigate the result list. Use or , to open the selected entry in a new tab or in a new split. ## vim-plugin https://github.com/junegunn/vim-plug http://www.d0u9.xyz/geng-wei-qiang-de-vimcha-jian-guan-li-qi-vim-plug/ ## YouCompleteMe http://blog.jobbole.com/58978/ https://linux.cn/article-6312-1.html ## vim-go https://github.com/fatih/vim-go-tutorial ## vim-plugin https://github.com/junegunn/vim-plug http://www.d0u9.xyz/geng-wei-qiang-de-vimcha-jian-guan-li-qi-vim-plug/ http://gsnippet.googlecode.com/svn/blog/html/vim/managerplugins.html http://www.vim.org/scripts/script.php?script_id=2905 ## markdonw https://zhuanlan.zhihu.com/p/84773275 # Miscs ## switch between .cpp and .h :e %:r.cpp % is shorthand for current filename. :r removes the extension .cpp simply appends that string at the end. http://vimawesome.com/ ## 快速文件切换 ctrl+^ 快速在最近打开的两个文件间切换 ## search * [n/shfit-n] # [n/shfit-n set hlsearch ## ctags gd : jump to local definition ctrl+] : jump to definition ctrl+t : return ctrl+o ## replace (ctrl+v enter) :%s/ / /g :%s/ /\r/g ## edit last one !vi ## copy current word yaw ## pop slect ctrl + p ## line mode stand on the beginning of the column press Ctrl+V, then mark across the column you want to edit. Press I to insert text at the beginning of the column, A to append text, r to replace highlighted text, d to delete, c to change... etc. Hit ESC twice when done. ## copy between files "f4yy open another file (must be in the same terminal) "fp ## open the .h file in .c move cursor to .h file, use "gf" or "ctrl_w + f" to jump into .h file and use "ctrl_^" to return :e %:r.cpp :vsplit %:r.cpp ## Open two files side by side using vim vim -O Compositor.h Compositor.cpp ## undo and redo u CTRL-R ## edit binary > open with "vim -b filename" > ":%!xxd" > edit file and use ":%!xxd -r" > ":wq" exit xxd -r -p ascill_hex.dat > real_hex.dat ## resize the window Ctrl+w > widens the viewpoint by 1 line Ctrl+w < narrows the viewpoint by 1 line Ctrl+w 10 > widens the viewpoint by 10 line Ctrl+w 10 < narrows the viewpoint by 10 line Ctrl+w + increase the height of viewpoint by 1 row Ctrl+w - decrease the height of viewpoint by 1 row 10 Ctrl+w + increase the height of viewpoint by 10 row 10 Ctrl+w - decrease the height of viewpoint by 10 row Ctrl+w _ Make a viewpoint as high as it can be 10 Ctrl+w _ Set the veiwpoint height to specified number of rows ## jump between windows Ctrl+w w jump to next window Ctrl+w h jump to left window Ctrl+w l jump to right window Ctrl+w j jump to up window Ctrl+w k jump to down window ## Read .json file using folding skill ## Read .xml file using xml.vim plugin ## delete The command dw will delete from the current cursor position to the beginning of the next word character The command d $ will delete from the current cursor position to the end of the current line. D is a synonym for d $ daw dw ## Go to definition using g gd will take you to the local declaration. gD will take you to the global declaration. g* search for the word under the cursor (like *, but g* on 'rain' will find words like 'rainbow'). g# same as g* but in backward direction. gg goes to the first line in the buffer (or provide a count before the command for a specific line). G goes to the last line (or provide a count before the command for a specific line). gf will go to the file under the cursor g] and other commands will jump to a tag definition ## copy & paste between different vim instances select contents in instance A "+y switch to instance B "+p # Trouble Shooting ## paste disorde http://www.netingcn.com/tag/vim # References http://blog.csdn.net/lhf_tiger/article/details/7216500 https://vimawesome.com/ http://easwy.com/blog/archives/advanced-vim-skills-quickfix-mode/ https://tuckerchapman.com/2018/06/16/how-to-use-the-vim-leader-key/