Warning: Cannot modify header information - headers already sent by (output started at /data/web/virtuals/85063/virtual/www/domains/waldauf.org/lib/plugins/color/syntax.php:1) in /data/web/virtuals/85063/virtual/www/domains/waldauf.org/inc/actions.php on line 180
linux:arch:shell:vim - WiKi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

linux:arch:shell:vim [2015/03/31 22:47]
127.0.0.1 external edit
linux:arch:shell:vim [2018/02/27 12:56] (current)
waldauf
Line 1: Line 1:
-====== VIm - smart tips ======  +====== VIm - smart tips ====== 
-  + 
-===== Insert TAB instead spaces =====  + 
-  + 
-Many times in VIm you have turn on tab extension - that means if you press TAB button into text will be inserted predefined space instead TAB. But sometimes you need to insert TAB char instead spaces.\\  +===== Insert TAB instead spaces ===== 
-You can use **<CTRL-V><Tab>** in //insert mode//. In insert mode **<CTRL-V>** inserts a literal copy of your next character. On windows you may need to press **<CTRL-Q>** rather than **<CTRL-V>**. + 
 +[[https://vi.stackexchange.com/questions/5613/search-and-highlight-two-different-strings-in-different-colors?newreg=720d59effa7143d1b69d40dc09ab2e19|Source]] 
 + 
 + 
 +Many times in VIm you have turn on tab extension - that means if you press TAB button into text will be inserted predefined space instead TAB. But sometimes you need to insert TAB char instead spaces.\\ 
 + 
 +You can use **<CTRL-V><Tab>** in //insert mode//. In insert mode **<CTRL-V>** inserts a literal copy of your next character. On windows you may need to press **<CTRL-Q>** rather than **<CTRL-V>**. 
 + 
 + 
 +===== Multistring search ===== 
 + 
 +First you need to define two highlight groups to set up the colors you want. Let's say, one with green background and the other one with blue background : 
 +<code> 
 +:highlight MyGroup1 ctermbg=green guibg=green 
 +:highlight MyGroup2 ctermbg=blue guibg=blue 
 +</code> 
 + 
 +Next you need to define your two matches with the ''matchadd()'' function. 
 +For example, you could apply the green background defined in the highlight group ''MyGroup1'' to the pattern ''foo'' and the blue background defined in ''MyGroup2'' to the pattern ''bar'' : 
 +<code> 
 +:call matchadd("MyGroup1", "foo") 
 +:call matchadd("MyGroup2", "bar") 
 +</code> 
 + 
 +You can access all the information (highlight group, pattern, priority, id) about your matches with the  ''getmatches()'' function: 
 +<code> 
 +:echo getmatches() 
 +</code> 
 + 
 +The ''id'' key is useful because its value allows you to delete a specific match with the ''matchdelete()'' function: '':call matchdelete({id})'' 
 + 
 +Besides, if you store the output of ''getmatches()'' inside a variable (let's say ''m'') : 
 +<code> 
 +:let m = getmatches() 
 +</code> 
 +... then you can clear your matches with the ''clearmatches()'' function: 
 +<code> 
 +:call clearmatches() 
 +</code> 
 +... and restore them with the ''setmatches()'' function afterwards: 
 +<code> 
 +:call setmatches(m) 
 +</code> 
 + 
 +Finally, if you have to define those matches regularly, you can gain some time by storing the commands that define them in a separate file and source it when needed. 
 + 
 +For example, you could store the following code in ''mymatches.vim'': 
 +<code> 
 +highlight MyGroup1 ctermbg=green guibg=green 
 +highlight MyGroup2 ctermbg=blue guibg=blue 
 + 
 +call matchadd("MyGroup1", "foo") 
 +call matchadd("MyGroup2", "bar") 
 +And source it with : :so mymatches.vim 
 +</code> 
 + 
 +Note that if one of your pattern is a double quote ''"'', you should escape it ''"\""'' or put single quotes around '''"'''. 
  
Navigation
Print/export
Toolbox