我试图在vim中学习一些新的简洁快捷方式,我发现了g_.根据 http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
$ ? go to the end of line
g_ ? go to the last non-blank character of line
Run Code Online (Sandbox Code Playgroud)
我何时会使用g_而不是$?
我认为最重要的区别只是在帮助文件中说明:
:h $
In Visual mode the cursor goes to just after the last character in the line.
Run Code Online (Sandbox Code Playgroud)
因此,如果你这样做v$d,删除包括"在最后一个字符之后"的新行,这样它就会将它下面的行带到当前行.但如果你这样做vg_d,将保留换行符.
我实际上不知道g_,似乎有用.
编辑由于这个答案得到了回复,我已经使用g_(及其反向_)制作一个映射,用于阻止/删除当前行,不包括前导/尾随空格并排除换行符:
" delete/yank line, but only whitespace-trimmed version
nnoremap <Leader>dd _yg_"_dd
nnoremap <Leader>yy _yg_
Run Code Online (Sandbox Code Playgroud)