1. Use the space bar as a leader (hot key) Leader is a very creative design. It can execute various commands by pressing different keys in sequence without using key combinations. Since using Leader, I rarely use key combinations such as ctrl-xxx. For a long time I used , as Leader, until I realized I could use a much better shortcut on the keyboard: the space bar (<Space>).
This completely changed my Vim operation efficiency. I can now use any thumb of both hands to operate, while the other fingers can stay on the main key area of the keyboard. Because Leader is very easy to use, I mapped various commonly used operations to Leader. 2. Map the most commonly used operations to Leader operations I first identified the most frequently used operations and mapped them to Leader operations, which I usually use: Use <Space>o to create a new file:
Use <Space>w to save the file (significantly faster than :w<Enter>):
Use <Space>p and <Space>y to copy and paste from the clipboard:
Use <Space><Space> to enter Vim editing mode:
I strongly recommend that you find the most common operations and map them to Leaders. 3. Use the region expansion function Make key mapping for the plugin terryma/vim-expand-region:
So I can:
Although vvv seems to be slower than vp, when using this method, I don’t need to think about what to select and which key combination to use. In this way, v replaces operations such as viw, vaw, vi", va", vi(, va(, vi[, va[, vi{, va{, vip, vap, vit,vat, …. Now you understand. 4. Find the text search operation tool I never really liked the search and replace operation in Vim until I found the following configuration on the Vim wiki:
This is a direct replacement for my usual sequence of operations:
PS: You can also consider using the cgn command provided by Vim 7.4. 5. Try more awesome keyboard mappings I use these shortcuts every day, and I've estimated that they've saved me months of time. Automatically jump to the end of the pasted text Use ppppp to paste multiple lines at once
Prevent buffer contents from being overwritten after pasting The following configuration can prevent the buffer content from being overwritten by the deleted text content (put it at the end of the ~/.vimrc file)
Translation note: There is no Title here, probably the author missed it, so I added one. Quickly jump within a file
Quickly select pasted text
Close boring window prompts
6. Improve unit test execution efficiency I used the vim-vroom plugin and the corresponding tmux configuration to perform my tests. By default, vim-room uses <Leader>r to execute tests. Since I have mapped Leader to <Space>, I use <Space>r to run the test tool. Since the tests are run in a separate tmux window, I can review my code while watching the tests progress. #p# 7. Use Ctrl-Z to return to Vim I often need to execute some commands in the shell. I suspend Vim through Ctrl-Z, and after completing the shell command execution, I return to Vim through <Enter>. Using fg to exit Vim was annoying, and I just wanted to be able to switch between Vim and the shell with Ctrl-Z , but I couldn't find a solution, so I wrote a script that works perfectly under ZSH:
If you put the above code in your ~/.zshrc file, you can quickly switch between shell and Vim, it is really worth trying it. 8. Configure Tmux Correctly Using Tmux and Vim tools on OS X is very inconvenient because:
I spent a lot of time to correct the above configuration, as shown below: Configure to use <C-Space> as tmux hotkey Some people are used to using <Ca> as a hotkey, but I use this hotkey to go back to the beginning of the line, so I won't go into details here. Using <C-Space> is more convenient, and I'll explain the reason later:
Use <Space> to enter copy mode Imagine how convenient it is to use <C-Space><Space> to directly enter Tmux's copy mode.
Use y and reattach-to-user-namespace (OSX based) Before using the system clipboard, you need to run brew install reattach-to-user-namespace
Using vim-tmux-navigator You need to use the shortcut keys <Ch>, <Cj>, <Ck>, <Cl> to quickly switch between various windows of vim and tmux. I also recommend using the <C-Space>l and <C-Space>j mappings for Tmux window splitting, which is definitely faster than using <C-Space>% and <C-Space>|:
See my tmux.conf file for more info. 9. Improve the efficiency of Ctrl-P in Git projects Add the following to your .vimrc file (configure using <Ctrl-P> to use git or silver finder for autocompletion):
I recommend using the vim-scripts/gitignore plugin. 10. Use a package manager neobundle.vim is a powerful tool for managing Vim plugins:
11. Take advantage of Vim plugins
I'm a Ruby programmer, so I also use some Ruby plugins:
12. Quickly configure Vim on the server I often need to use Vim for configuration on my servers, and unfortunately Vim's default configuration is pretty unreasonable. One solution is to use the vim-sensible plugin to generate a compressed package, but this is not good enough for me. I wrote a vimrc plugin to do a reasonable initialization of Vim (especially for Ruby developers). This plugin configures Vim to only use ~/.vimrc as the configuration file. It also includes optimized color matching, package management tools, and syntax coloring for multiple development languages. This means that I don't need to manually configure the ~/.vim directory on the server. Instead, I can easily configure the Vim environment on the server by doing the following:
I also wrote a dotfiles to quickly configure my development environment. think The key to using Vim well is to constantly discover Vim problems you encounter during the software development process and actively deal with them. The solution could be to add a keymap to your .vimrc, search for a solution on google, ask on IRC, or something else. How have you improved your Vim usage efficiency? |
<<: How I taught myself Android, sharing my experience
>>: Siri may be able to answer calls for you and convert them into text messages
These days, gamers may find that the female charac...
Finally, the United States made a decision - to i...
Recently, Apple released iOS 11.4 beta 2. Two wee...
In an information flow advertisement , the role o...
Under the premise of 0 fans and 0 investment, how...
Nowadays, more and more people use mobile applica...
I must be honest, this article is the most time-c...
After being suspended for several days, his Weibo...
Braking devices are essential for the safe drivin...
According to the XDA forum, Google may remove the...
Recently, several children in Shifang City, Sichu...
This article was reviewed by Liu Yong, space phys...
After reading this article, you will get the foll...
Real-time statistics released by Johns Hopkins Un...
Content is the core at all times. But a good cont...