4

Lets say I jump to mark with ]' and I want to remove it, how can I do it without typing :delmarks a?

noee
  • 43
  • 1
  • 3

3 Answers3

7

I'm going to swim against the stream on this one.

Just don't worry about it.

Marks are pretty ephemeral and there are bunch of marks Vim automatically maintains like '[, '', and '. Humans are typically very bad at bookkeeping so we typically use only a few registers and a few marks. I personally only use a few a-z marks (typically 'm) and often only in few immediate contexts e.g. macros or jumping between a few spots. Your workflow maybe different, but I see no reason to "clean up" the marks.

Now to answer your question:

nnoremap dm :execute 'delmarks '.nr2char(getchar())<cr>

Now you can do dma to delete mark 'a.

Or to delete all marks on the current line:

command! Delmarks silent execute 'delmarks '.join(map(filter(filter(map(split(execute('marks'),"\n"),'split(v:val)'), 'v:val[1]==line(".")&&v:val[0]!~#"[A-Z]"'), 'v:val[1]==line(".")&&v:val[0]!~#"[A-Z]"'), 'v:val[0]'))

Just map this to a key to so you don't have to type out :Delmarks.

Peter Rincker
  • 15,854
  • 1
  • 36
  • 45
  • I work with large source files and quite often need to move bookmark few lines up or down. Since @Mass posted similar answer first I will accept his. Thank you for your opinion. – noee Oct 20 '17 at 21:45
3

To delete a mark you can use :delmark it can be shortened to :delm. If you really want something shorter you can map a function which asks for an input but it's not really a common practice to have a map which takes a parameter or ask for an input.

function! MarkDelete()
    call inputsave()
    let l:mark = input("Mark to del: ")
    call inputrestore()
    execute 'delmark '.l:mark
endfunction

Now just map it:

nnoremap <F2> call MarkDelete()<CR>
statox
  • 49,782
  • 19
  • 148
  • 225
fievel
  • 383
  • 1
  • 6
1

You can delete all a-z marks on the current line using this function:

function! Delmarks()
    let l:m = join(filter(
       \ map(range(char2nr('a'), char2nr('z')), 'nr2char(v:val)'),
       \ 'line("''".v:val) == line(".")'))
    if !empty(l:m)
        exe 'delmarks' l:m
    endif
endfunction

and with a map

nnoremap <silent> dm :<c-u>call Delmarks()<cr>
Mass
  • 14,080
  • 1
  • 22
  • 47