Customizing your own vim configuration file will bring you future convenience and fluency. Writing into ~/.vimrc
, it will take effect next time you enter Vim editor. If you want your config file to apply to all users, edit /etc/vim/vimrc
with sudo
privilige. For some specific purposes like ACM contest, you can also create a config file. When using it, source
this command.
If you want to specify different settings for different file types, for example, C++ files, you should first add filetype plugin indent on
to the .vimrc
file. and then create .vim/after/ftplugin/cpp.vim
, and write
setlocal expandtab
setlocal shiftwidth=2
setlocal softtabstop=2
backup file, swap file and undo file
‘.filename~’ is a backup file, it stores the file before you start to edit it.
‘.filename.swp’ is a swap file, containing the unsaved changes.
‘.filename.un~’ is an undo file that stores the undo trees of the file edited.
Key mappings
Default
<C-^> change active window panel
Self define
Finally I will give the sample code that I set for my personal computer. Before that, let’s clarify a braces auto-completing algorithm. When the left brace is typed, only when there is no right char near it can the right brace be completed. When the right brace is typed, only when the right char near it is the same right char can the cursor be jumped.
Response for typing ‘(‘
1 | get the line and column positions of current cursor as lnum, cnum |
Reponse for typing ‘)’
1 | if the right next char is ')': |
To get the current line text, use getline('.')
1 | "~/.vimrc |
1 | "~/.vim/after/ftplugin/cpp.vim |
(copy from vim ggVG
then "+y
)
paste to remote vim
ssh -Y user@server or permanently added in .ssh/config
Ctrl+Insert for copy, Shift+Insert for paste
Tweak vim as C/C++ IDE
Plugin manager
vim-plug: https://github.com/junegunn/vim-plug
Debugging
vimspector: https://github.com/puremourning/vimspector#quick-start
After putting Plug 'puremourning/vimspector'
into .vimrc
. Go to gadget home to execute
1 | ./install_gadget.py --all |
Close a tab
:tabclose
References
How do I set up different tab settings for different languages in Vim: https://stackoverflow.com/a/1743255
Vim: Remove swap, backup and undo Files from Working Directory: https://medium.com/@Aenon/vim-swap-backup-undo-git-2bf353caa02f
How to close a tab in vim? : https://stackoverflow.com/questions/32714834/how-to-close-a-tab-in-vim
评论
shortname
for Disqus. Please set it in_config.yml
.