我不想用vim自动对齐行尾注释。
我有以下代码段:
" This is a block
" with some comments
require 'some important lib' " important lib
require 'another lib' " another lib
require 'lib' "lib
这太丑了。所以我有以下功能(在.vimrc中)
inoremap <silent> " "<Esc>:call <SID>ealigneolcomment()<CR>a
function! s:ealigneolcomment()
let p = '^.\+"\s.*$'
if exists(':Tabularize') && getline('.') =~# '^.\+"' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^"]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*"\s*\zs.*'))
Tabularize/"/l1
normal! 0
call search(repeat('[^"]*"',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
当我点击:Tabularize/"/l1
时,它只在当前光标位置运行"
。结果如下:
" This is a block
" with some comments
require 'some important lib' " important lib
require 'another lib' " another lib
require 'lib' " lib
相反,我希望得到这样的结果:
" This is a block
" with some comments
require 'some important lib' " important lib
require 'another lib' " another lib
require 'lib' " lib
基本上我只想对齐行尾注释。块注释应保持不变。有没有办法调用Tabular来获得所需的结果?或者只是另一个vim插件?