Vim Tips Wiki
(Move categories to tip template)
(Remove html character entities)
 
Line 23: Line 23:
 
" add something to the context menue (right mouse)
 
" add something to the context menue (right mouse)
 
amenu 1.200 PopUp.-SEP3- :
 
amenu 1.200 PopUp.-SEP3- :
amenu 1.200 PopUp.&mark.set\ bookmark :exe 'sign place 1000 name=MyBookmark line='.line(".").' buffer='.winbufnr(0)<CR>
+
amenu 1.200 PopUp.&mark.set\ bookmark :exe 'sign place 1000 name=MyBookmark line='.line(".").' buffer='.winbufnr(0)<CR>
amenu 1.200 PopUp.&amp;mark.del\ bookmarks :sign unplace 1000 &lt;CR&gt;
+
amenu 1.200 PopUp.&mark.del\ bookmarks :sign unplace 1000 <CR>
amenu 1.200 PopUp.&amp;mark.list\ bookmarks :sign list&lt;CR&gt;
+
amenu 1.200 PopUp.&mark.list\ bookmarks :sign list<CR>
 
</pre>
 
</pre>
   
Line 32: Line 32:
   
 
==Comments==
 
==Comments==
1. We need to add &lt;silent&gt; on the map to make it work smoothly.
+
1. We need to add <silent> on the map to make it work smoothly.
   
amenu&lt;silent&gt; 1.200 PopUp.&amp;mark.set\ bookmark :exe 'sign place 1000 name=MyBookmark line='.line(".").' buffer='.winbufnr(0)&lt;CR&gt;
+
amenu<silent> 1.200 PopUp.&mark.set\ bookmark :exe 'sign place 1000 name=MyBookmark line='.line(".").' buffer='.winbufnr(0)<CR>
   
 
2. Bookmark deletion doesn't work as expected. Is it possible to delete highlighted bookmark under the cursor?
 
2. Bookmark deletion doesn't work as expected. Is it possible to delete highlighted bookmark under the cursor?
Line 46: Line 46:
 
To get unique identifier you can use the actual line number as identifier:
 
To get unique identifier you can use the actual line number as identifier:
   
amenu&lt;silent&gt; 1.200 PopUp.&amp;mark.set\ bookmark :exe 'sign place '.line(".").' name=MyBookmark line='.line(".").' buffer='.winbufnr(0)&lt;CR&gt;
+
amenu<silent> 1.200 PopUp.&mark.set\ bookmark :exe 'sign place '.line(".").' name=MyBookmark line='.line(".").' buffer='.winbufnr(0)<CR>
amenu&lt;silent&gt; 1.200 PopUp.&amp;mark.del\ bookmark :exe 'sign unplace '.line(".")&lt;CR&gt;
+
amenu<silent> 1.200 PopUp.&mark.del\ bookmark :exe 'sign unplace '.line(".")<CR>
   
 
----
 
----
Line 56: Line 56:
 
Eventually, I have the following short and sweet version in my .vimrc:
 
Eventually, I have the following short and sweet version in my .vimrc:
   
nme &lt;silent&gt;PopUp.bookmark_&amp;x :exe 'sign unplace '.line(".")&lt;CR&gt;
+
nme <silent>PopUp.bookmark_&x :exe 'sign unplace '.line(".")<CR>
nme &lt;silent&gt;PopUp.bookmark_&amp;a :exe 'sign place '.line(".").
+
nme <silent>PopUp.bookmark_&a :exe 'sign place '.line(".").
' name=bookmark line='.line(".").' buffer='.winbufnr(0)&lt;CR&gt;
+
' name=bookmark line='.line(".").' buffer='.winbufnr(0)<CR>
 
sign define bookmark linehl=DiffDelete
 
sign define bookmark linehl=DiffDelete
   

Latest revision as of 05:44, 29 September 2008

Tip 395 Printable Monobook Previous Next

created January 8, 2003 · complexity basic · author Thomas Ramming · version 6.0


Setting visual bookmarks in a file can be done in a simple way using Vim's 'sign' feature.

This solution just sets the background of the current line to light blue. Add these lines to your gvimrc:

" define a highlight colour group for bookmarks
hi default BookmarkCol ctermfg=blue ctermbg=lightblue cterm=bold guifg=DarkBlue guibg=#d0d0ff gui=bold
" define a bookmark / sign: just highlight the line
sign define MyBookmark linehl=BookmarkCol
" add something to the context menue (right mouse)
amenu 1.200 PopUp.-SEP3- :
amenu 1.200 PopUp.&mark.set\ bookmark :exe 'sign place 1000 name=MyBookmark line='.line(".").' buffer='.winbufnr(0)<CR>
amenu 1.200 PopUp.&mark.del\ bookmarks :sign unplace 1000 <CR>
amenu 1.200 PopUp.&mark.list\ bookmarks :sign list<CR>

References[]

Comments[]

1. We need to add <silent> on the map to make it work smoothly.

amenu<silent> 1.200 PopUp.&mark.set\ bookmark :exe 'sign place 1000 name=MyBookmark line='.line(".").' buffer='.winbufnr(0)<CR>

2. Bookmark deletion doesn't work as expected. Is it possible to delete highlighted bookmark under the cursor?


The problem might be the 'id' (I used the same '1000' for each bookmark). You have to find a way to automatically use unique ids or 'unplace' will delete the bookmarks in the order they have been created.

There is a script 'showmarks' in the script database (search for 'showmarks'), which shows 'normal' vim marks.


To get unique identifier you can use the actual line number as identifier:

amenu<silent> 1.200 PopUp.&mark.set\ bookmark :exe 'sign place '.line(".").' name=MyBookmark line='.line(".").' buffer='.winbufnr(0)<CR>
amenu<silent> 1.200 PopUp.&mark.del\ bookmark :exe 'sign unplace '.line(".")<CR>

Just download the showmarks.vim plugin from this site and forget about it. It'll automatically show you a mark as a sign when you set one. script#152


Eventually, I have the following short and sweet version in my .vimrc:

nme <silent>PopUp.bookmark_&x :exe 'sign unplace '.line(".")<CR>
nme <silent>PopUp.bookmark_&a :exe 'sign place '.line(".").
' name=bookmark line='.line(".").' buffer='.winbufnr(0)<CR>
sign define bookmark linehl=DiffDelete