Skip to main content
1 of 16
dsimic
  • 252
  • 2
  • 7

Here's an excerpt from my ~/.vimrc, which I implemented using the very good "remap nothing" idea from the already existing answer provided by @the_velour_fog, but I improved the idea and the implementation further to be almost something like "change nothing", as described below:

" Display a list of marks and allow their easy selection, without
" remapping any keys or changing the original vim behavior, down
" to the error messages produced for unknown marks
function ListSelect(command, jump)
  execute a:command
  echohl Question
  echo "Enter mark (ESC to cancel): "
  echohl NONE
  let mark = nr2char(getchar())
  redraw
  if mark !=# "\e"
    try
      execute "normal! g" .. a:jump .. mark
    catch
      echohl ErrorMsg
      echo substitute(v:exception, "^Vim(.*):", "", "")
      echohl NONE
    endtry
  endif
endfunction

nnoremap ` :call ListSelect("marks", "`")<CR>
nnoremap ' :call ListSelect("marks", "'")<CR>

As described in the vimscript code, this version retains the ability to use <ESC> to cancel the whole operation, and still produces the same error messages for unknown marks, without throwing "execution failed" errors at the user.

This version also produces a prompt message that looks just like all such messages produced by vim itself, furthering the "change nothing" approach.

dsimic
  • 252
  • 2
  • 7