When I want to find out what might be causing lag within vim, I use the following commands

:profile start ~/profile.log | :profile func * | :profile file *
<do actions that cause lag>
:profile pause :noautocmd qall!

Is there any way I could turn these into a keybinding so I wouldn't have to type it out every time?

I've tried the following, but apparently I'm not setting it up correctly:

nnoremap <silent> <leader>O :call ProfileStart()<CR>
nnoremap <silent> <leader>o :call ProfileEnd()<CR>

function! ProfileStart()
  :profile start ~/profile.log | :profile func * | :profile file *

function! ProfileEnd()
  :profile pause :noautocmd qall!

Two separate issues!

Firstly, adding | to a keybinding (officially called a map, if you don't mind me nitpicking) is tricky. It is a special character so it must be escaped. Here are two examples of how to do this:

nnoremap x :echo "hi" \| echo "hi2" <CR>
nnoremap x :echo "hi" <Bar> echo "hi2" <CR>

Secondly, when you are writing a vimscript function, vim is in a different mode. You do not have to have : to enter command mode. You're already in command mode! And you don't need to use | to have multiple commands on the same line.

function! ProfileStart()
  profile start ~/profile.log
  profile func *
  profile file *

You're running into 2 separate problems with only 1 goal, that is confusing. Tough to debug... But you got this, good luck!

| improve this answer | |
  • Excellent, thank you @Ari_Sweedler! fist bump with explosion – Spectator6 Aug 8 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.