2015-09-22 16 views

回答

1

我想這是你想要的,我們可以用我在下面的路徑描述相同的情況下兩個功能是什麼:https://stackoverflow.com/a/32478708/3146151

只是把你的.vimrc或.gvimrc裏這兩個函數和調用的函數作爲編輯器中的正常函數調用。

的功能我在這裏貼吧:https://github.com/imbichie/vim-vimrc-/blob/master/MCCB_MCCE.vim

我們需要調用在vim編輯器這個功能,給您想要移動字符或空格的發生次數和裏面的「」字和列號。

出現的次數可以從每行的開始(MCCB函數)開始,也可以在每行的末尾(MCCE函數)。

對於上述示例中提到的示例,我們可以使用MCCB函數和字符'=',所以在vim編輯器中的用法將會是這樣的。

:1,3call MCCB(1,'=',13) 

因此,這將第一等號(=)移動到與1號線第13列3

這些功能:

" MCCB - Move the Character to the Column from the Begin of line 
" This is a function for Moving the specified Character 
" in a given range of lines to a the specified Column from the Begin of the line 
" NOTE 1 :- If the specified character and the first character of the line are same 
"   then the number of Occurance (num_occr) will be one less than the actual 
" NOTE 2 :- Maximum space between the specified character with in the range 
"   of lines should be less than or equal to 80, if we need more than 80 
"   then we need to insert more spaces by increasing the value 80 in the 
"   "nmap s 80i <ESC>" line inside the function 
" Usage :- in command mode do it like below 
" Eg 1:- :5,11call MCCB(1, '=', 8) 
"   The above command will move the 1st Occurance from the begin of Character = 
"   to the 8th Column of the lines from 5 to 11 
" Eg 2 :- :7,10call MCCB(2, '+', 12) 
"   The above command will move the 2nd Occurance of Character = to the 12th 
"   Column of the lines from 7 to 10 
    function! MCCB (num_occr, mv_char, col_num) range 
     if (a:firstline <= a:lastline) 
      nmap s 80i <ESC> 
      let line_num = a:firstline 
      while line_num <= a:lastline 
       execute "normal " . line_num . "G0" . a:num_occr . "f" . a:mv_char . "s" . a:col_num . "|dw" 
       let line_num = line_num + 1 
      endwhile 
      nunmap s 
     else 
      execute printf('ERROR : Start line %d is higher thatn End line %d, a:firstline, a:lastline) 
     endif 
    endfunction 

" MCCE - Move the Character to the Column from the End of line 
" This is a function for Moving the specified Character 
" in a given range of lines to a the specified Column from the End of the line 
" NOTE 1 :- If the specified character and the last character of the line are same 
"   then the number of Occurance (num_occr) will be one less than the actual 
" NOTE 2 :- Maximum space between the specified character with in the range 
"   of lines should be less than or equal to 80, if we need more than 80 
"   then we need to insert more spaces by increasing the value 80 in the 
"   "nmap s 80i <ESC>" line inside the function 
" Usage :- in command mode do it like below 
" Eg 1:- :5,11call MCCE(1, ';', 20) 
"   The above command will move the 1st Occurance from the End of Character ; 
"   to the 20th Column of the lines from 5 to 11 
" Eg 2 :- :7,10call MCCE(5, 'i', 26) 
"   The above command will move the 5th Occurance from the End of Character i 
"   to the 26th Column of the lines from 7 to 10 
    function! MCCE (num_occr, mv_char, col_num) range 
     if (a:firstline <= a:lastline) 
      nmap s 80i <ESC> 
      let line_num = a:firstline 
      while line_num <= a:lastline 
       execute "normal " . line_num . "G$" . a:num_occr . "F" . a:mv_char . "s" . a:col_num . "|dw" 
       let line_num = line_num + 1 
      endwhile 
      nunmap s 
     else 
      execute printf('ERROR : Start line %d is higher thatn End line %d, a:firstline, a:lastline) 
     endif 
    endfunction 
2

如果你這樣做,很多時候,你可以使用vim插件Tabular來做到這一點。

在可視模式,選擇要縮進並鍵入:Tab /=

+0

如何在Windows上將該插件安裝到我的gVim上? –

+0

@SJain你可以在我的[dotvim頁面](https://github.com/LKI/dotvim)上看到我的gVim配置希望它有幫助 –

1
+0

我從未安裝過插件。我如何安裝一個? –

+0

使用一些插件管理器。我需要衝刺,如果9個小時內沒有人回答,我會回到你身邊。我認爲vim-easy-align在Windows上工作。 – ryuichiro

+1

好吧,我不知道我是否已經太晚了,但是你可以考慮開始閱讀[here](http://vi.stackexchange.com/questions/613/how-do-i-install-a -plugin-in-vim-vi),那麼我會推薦這個[論文](http://www.vim.org/ugrankar.pdf)。這很好(而且非常簡單)。選擇首選管理員並使其工作後,您可以選擇插件,例如[這裏](http://vimawesome.com/)。這些只是我的偏好,你不必跟隨他們,你總是可以使用谷歌找到你最適合的套房。享受和祝你好運! :-) – ryuichiro

相關問題