顯示具有 Vim 標籤的文章。 顯示所有文章
顯示具有 Vim 標籤的文章。 顯示所有文章

2022年8月14日 星期日

Modify multiple lines after matching lines in Vim

Just note down issues i faced in vim.

Problem: (How to add prefix "#" before ever lines between "#For testing" and " ; ?)

Command: 
 insert # prefix      :g/^# For testing/+1,/^"/ norm! I#
 remove # prefix   :g/^# For testing/+1,/#^"/ norm! ^x

power g: :g/Pattern/cmd
pattern here is "^# For testing"

cmd here is +1, /^"/ norm! I#,  where +1, /^"/ is a ranges command which means that from next line of current line to line of matching pattern (which is ^" here).
norm! I# means that insert "#" at each lines in normal mode.
norm! ^x means that remove first character at each lines in normal mode . (^: begin of a line,  x: delete character)

2022年7月15日 星期五

Search selected text in vim

 Just note down issues i faced in vim.

Search word under the cursor - * or # for backward/forward, respectively.

Search selected text in visual mode - 

    y (yank the selected text into " register by default)

    /  (enter search mode)

    (\ V) (can skill, it's optional. enter "very no magic" mode*)

    Ctrl + r " (paste text from " register)

    Enter (go!)


Reference: https://superuser.com/questions/41378/how-to-search-for-selected-text-in-vim