Skip to main content
Minor improvement
Source Link

The following should solve your issue:

nnoremap <expr> : ShowLastCmd()

function! ShowLastCmd()
  echohl ModeMsg
  echo ':' . getreg(':')
  echohl None

  while 1
    try
      let char = getchar()
      if char == '^\d\+$' || type(char) == 0
        let char = nr2char(char)
      endif
    catch /^Vim:Interrupt$/
      return ''
    endtry

    if char == "\<cursorhold>"
      continue
    elseif char == "\<cr>"
      executereturn ':' . getreg(':')
  . "\<cr>"
   return ''else
    endif

    return ':' . char
    endif
  endwhile
endfunction

The while loops is there to catch the <cursorhold> key event.

The following should solve your issue:

nnoremap <expr> : ShowLastCmd()

function! ShowLastCmd()
  echohl ModeMsg
  echo ':' . getreg(':')
  echohl None

  while 1
    try
      let char = getchar()
      if char == '^\d\+$' || type(char) == 0
        let char = nr2char(char)
      endif
    catch /^Vim:Interrupt$/
      return ''
    endtry

    if char == "\<cursorhold>"
      continue
    elseif char == "\<cr>"
      execute getreg(':')
      return ''
    endif

    return ':' . char
  endwhile
endfunction

The while loops is there to catch the <cursorhold> key event.

The following should solve your issue:

nnoremap <expr> : ShowLastCmd()

function! ShowLastCmd()
  echohl ModeMsg
  echo ':' . getreg(':')
  echohl None

  while 1
    try
      let char = getchar()
      if char == '^\d\+$' || type(char) == 0
        let char = nr2char(char)
      endif
    catch /^Vim:Interrupt$/
      return ''
    endtry

    if char == "\<cursorhold>"
      continue
    elseif char == "\<cr>"
      return ':' . getreg(':') . "\<cr>"
    else
      return ':' . char
    endif
  endwhile
endfunction

The while loops is there to catch the <cursorhold> key event.

Improved the code
Source Link

The following should work (it works for me in neovim and vim in terminal)solve your issue:

nnoremap <expr> : ShowLastCmd()

function! ShowLastCmd()
  echohl ModeMsg
  echo ':' . getreg(':')
  echohl None

  while 1
    try
      let char = getchar()
      if char == '^\d\+$' || type(char) == 0
        let char = nr2char(char)
      endif
    catch /^Vim:Interrupt$/
      return ''
    endtry

    if char == "\<cursorhold>"
      continue
    elseif char == "\<cr>"
      execute getreg(':')
      return ''
    endif

    return ':' . char
  endwhile
endfunction

It needs some more work, e.g. to preventThe getchar()while from catchingloops is there to catch the <cursorhold> key event. But the basic layout works well, I think.

The following should work (it works for me in neovim and vim in terminal):

nnoremap <expr> : ShowLastCmd()

function! ShowLastCmd()
  echohl ModeMsg
  echo ':' . getreg(':')
  echohl None

  try
    let char = getchar()
    if char == '^\d\+$' || type(char) == 0
      let char = nr2char(char)
    endif
  catch /^Vim:Interrupt$/
    return ''
  endtry

  if char == "\<cr>"
    execute getreg(':')
    return ''
  endif

  return ':' . char
endfunction

It needs some more work, e.g. to prevent getchar() from catching the <cursorhold> key event. But the basic layout works well, I think.

The following should solve your issue:

nnoremap <expr> : ShowLastCmd()

function! ShowLastCmd()
  echohl ModeMsg
  echo ':' . getreg(':')
  echohl None

  while 1
    try
      let char = getchar()
      if char == '^\d\+$' || type(char) == 0
        let char = nr2char(char)
      endif
    catch /^Vim:Interrupt$/
      return ''
    endtry

    if char == "\<cursorhold>"
      continue
    elseif char == "\<cr>"
      execute getreg(':')
      return ''
    endif

    return ':' . char
  endwhile
endfunction

The while loops is there to catch the <cursorhold> key event.

Source Link

The following should work (it works for me in neovim and vim in terminal):

nnoremap <expr> : ShowLastCmd()

function! ShowLastCmd()
  echohl ModeMsg
  echo ':' . getreg(':')
  echohl None

  try
    let char = getchar()
    if char == '^\d\+$' || type(char) == 0
      let char = nr2char(char)
    endif
  catch /^Vim:Interrupt$/
    return ''
  endtry

  if char == "\<cr>"
    execute getreg(':')
    return ''
  endif

  return ':' . char
endfunction

It needs some more work, e.g. to prevent getchar() from catching the <cursorhold> key event. But the basic layout works well, I think.