Vim Tips Wiki
No edit summary
 
(Remove html character entities)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=395
 
|id=395
  +
|previous=394
|title=visual marks
 
  +
|next=396
|created=January 8, 2003 7:29
+
|created=January 8, 2003
 
|complexity=basic
 
|complexity=basic
 
|author=Thomas Ramming
 
|author=Thomas Ramming
 
|version=6.0
 
|version=6.0
 
|rating=10/6
 
|rating=10/6
  +
|category1=
|text=
 
  +
|category2=
Hi,
 
 
}}
 
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:
   
  +
<pre>
 
" 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>
  +
</pre>
   
  +
==References==
Setting visual bookmarks in a file / buffer can be done in a simple way by using VIM's 'sign' feature.
 
  +
*{{help|:sign}}
   
 
==Comments==
This solution just sets the background of the current line to light blue.
 
 
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?
   
Also see ':help sign'.
 
 
 
 
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=&#35;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.&amp;mark.set\ bookmark :exe 'sign place 1000 name=MyBookmark line='.line(".").' buffer='.winbufnr(0)&lt;CR&gt;
 
 
amenu 1.200 PopUp.&amp;mark.del\ bookmarks :sign unplace 1000 &lt;CR&gt;
 
 
amenu 1.200 PopUp.&amp;mark.list\ bookmarks :sign list&lt;CR&gt;
 
 
 
 
 
 
Happy VIMming
 
 
 
 
Thomas
 
 
 
}}
 
 
== Comments ==
 
 
1 We need to add &lt;silent&gt; 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;
 
 
2. bookmark deletion doesn't work as expected.
 
Is it possible to delete highlighted bookmark under the cursor?
 
 
Thanks.
 
 
maxiangjiang--AT--hotmail.com
 
, January 8, 2003 15:38
 
 
----
 
----
The problem might be the 'id' (I used the same '1000' for each bookmark).
+
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.
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'),
+
There is a script 'showmarks' in the script database (search for 'showmarks'), which shows 'normal' vim marks.
which shows 'normal' vim marks (Thanks to the author!).
 
   
Thomas
 
 
'''Anonymous'''
 
, January 8, 2003 23:34
 
 
----
 
----
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>
   
 
Thomas
 
 
'''Anonymous'''
 
, January 9, 2003 5:02
 
 
----
 
----
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.
+
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|id=152}}
   
Anonymous
 
, January 9, 2003 6:31
 
 
----
 
----
 
Eventually, I have the following short and sweet version in my .vimrc:
[/scripts/script.php?script_id=152 vimscript &#35;152] showmarks.vim
 
 
zzapper--AT--ntlworld.com
 
, January 10, 2003 3:33
 
----
 
Thanks, Thomas
 
 
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 &lt;silent&gt;PopUp.bookmark_&amp;a :exe 'sign place '.line(".").
 
' name=bookmark line='.line(".").' buffer='.winbufnr(0)&lt;CR&gt;
 
sign define bookmark linehl=DiffDelete
 
   
 
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
   
maxiangjiang--AT--hotmail.com
 
, February 5, 2003 14:09
 
 
----
 
----
<!-- parsed by vimtips.py in 0.575125 seconds-->
 

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