In vim’s command mode, how should complex commands that are frequently used be simplified? Is it enough to design shortcut keys?
I often use a replacement command: 0,$s/t/ /g is to replace the tab key with 4 spaces.
For newly-created files, I have already configured them in the configuration file. However, the tab key often appears in other people’s files.
I have to replace it every time.
I am not very familiar with vim shortcut keys. Can I use shortcut keys? How to set it up? Replace with shortcut keys: 0,$s/t/ /g common commands
Can you switch automatically when vim opens the file, so that you don’t have to set the shortcut keys?
First of all, I would like to thank the following respondents. I read the help documents on the explanations they gave and finally came up with a method that I think is reasonable.
Shortcut keys are certainly possible, but they need to be remembered. For my current problem, I prefer automatic conversion.
First of all
:help retLooking at the documents, what I want to say here is that when replacing,Be careful to replace the
:help autoLook at the documents, not much more.
Look at the. vimrc file. vimrc file already contains
if has("autocmd")Part, write the corresponding commands together.
autocmd BufRead *.cpp,*.h :retThis automatic replacement command, BufRead and BufReadPost, are the same. here you want toNote: For mode options, it is better not to replace any type of file with *, and write out the suffix to prevent erroneous replacement of files in other formats.
This replacement command only replaces the contents in Buf cache. If it is not modified and not saved, it will not be written. If it exits directly, vim will not prompt you to save and tab key still exists.This is not harmful.
Finally, thanks again to the following respondents. Happy New Year.
First of all, let’s throw bricks to attract jade:
Since you already have an operation, it is very simple to set a shortcut key for this operation, for example, this shortcut key is set to normal mode.
nnoremap <Leader>ts :0,$s/t/ /g<CR>, probably is
The mode shortcut key operation for which you want shortcut key mapping.
The second can be used
autocmd BufRead * :%ret! 4<CR>, converts the tab of the entire file into space, each tab is replaced by 4 spaces. ret refers to replace tab, and more content can be