1

In gvim, you can create custom menus easily. Those extra lines in my gvimrc add a small python 'utilities' menu.

menu Python.Run <ESC>:Shell python %<cr>
menu Python.Run\.\.\. <ESC>:Shell python %:p
menu Python.Pyflakes <ESC>:Shell pyflakes %<cr>
menu Python.Pychecker <ESC>:Shell pychecker %<cr>
menu Python.Pep-8 <ESC>:call Flake8() %<cr>
menu Python.FixTabs <ESC>:ret<cr> 

With this line, I'm triyng to have this displayed in the command line :shell python my/file/full/path/myfile.py so that I can make some modifications to the path before hitting 'return'

But I can't get the full path evaluated in any way; this does not work:

menu Python.Run\.\.\. <ESC>:Shell python %:p  

I tried to call a separate function that would expand the path and echo the correct command but although it actually echoes the right stuff in Vim's command line, neither the text can be executed nor does the focus go to the command line.

I also tried this syntax found in vim tips, (wich I don't understand BTW) but with no more succes :

menu Python.Run\.\.\. <ESC>:Shell python <C-R>1<C-G>  

Has anybody encountered a similar issue?

msarch
  • 325
  • 1
  • 11

1 Answers1

3

Your custom menu invokes the :Shell command, which presumably later invokes :!. The important thing here is that the special placeholder %:p only gets evaluated in the end, by the :! command. Therefore, when you want to define a menu entry that is not complete (for further editing), that doesn't work, and you need to explicitly expand the placeholder.

The syntax you've found goes into the right direction. In command-line mode (which your mapping enters via the :), the Ctrl-R mapping inserts a register; cp. :help c_CTRL-R. With the special = expression register, you can evaluate a Vimscript expression, and there's indeed an expand() function that handles those placeholders. Ergo:

menu Python.Run\.\.\. <ESC>:Shell python <C-R>=expand('%:p')<CR>

The trailing <CR> only concludes the expression entry, but not the command-line itself, so it stays active for further editing!

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Ok, got it!. Works good! Thanks. I'm going to dig into that 'register' thing, it looks very powerful as in this SO answer: [http://stackoverflow.com/questions/3997078/how-to-paste-text-into-vim-command-line?rq=1] – msarch Sep 02 '14 at 14:28