[vim/vim] backtick-equals expansion doesn't work when sending command to shell (#7952)

150 views
Skip to first unread message

AvianY

unread,
Mar 11, 2021, 11:26:00 AM3/11/21
to vim/vim, Subscribed

Describe the bug
when using `= to expand an ex command in-line, it doesn't work when using ":!command" to send command to the shell

To Reproduce
Detailed steps to reproduce the behavior:

  1. Run vim --clean (or gvim --clean, etc.)
  2. Type "some text" in insert mode
  3. Type :!echo `=getline(".")` to print the line the cursor is on to the shell
  4. Shell gives an error:
/bin/bash: command substitution: line 0: syntax error near unexpected token `"."'
/bin/bash: command substitution: line 0: `=getline(".")'

Expected behavior
I expect the above procedure to produce "some text" printed out in the terminal

Environment (please complete the following information):

VIM - Vi IMproved 8.1 (2018 May 18, compiled Jun 15 2019 16:41:15)
Included patches: 1-875, 878, 884, 948, 1046, 1365-1368, 1382, 1401
Modified by team...@tracker.debian.org
Compiled by team...@tracker.debian.org
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     +tag_old_static
+arabic            +farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    +tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
+balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
+browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +textprop
+byte_offset       -hangul_input      +num64             +timers
+channel           +iconv             +packages          +title
+cindent           +insert_expand     +path_extra        +toolbar
+clientserver      +job               +perl              +user_commands
+clipboard         +jumplist          +persistent_undo   +vartabs
+cmdline_compl     +keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      +langmap           +profile           +visual
+comments          +libcall           -python            +visualextra
+conceal           +linebreak         +python3           +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
+cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          +rightleft         +wildmenu
+cursorshape       +lua               +ruby              +windows
+dialog_con_gui    +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             +X11
+digraphs          +modify_fname      +smartindent       -xfontset
+dnd               +mouse             +startuptime       +xim
-ebcdic            +mouseshape        +statusline        +xpm
+emacs_tags        +mouse_dec         -sun_workshop      +xsmp_interact
+eval              +mouse_gpm         +syntax            +xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save
  system vimrc file: "$VIM/vimrc"
    user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
     user exrc file: "$HOME/.exrc"
 system gvimrc file: "$VIM/gvimrc"
   user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
      defaults file: "$VIMRUNTIME/defaults.vim"
   system menu file: "$VIMRUNTIME/menu.vim"
 fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time  -g -O2 -fdebug-prefix-map=/build/vim-4Pursk/vim-8.1.0875=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L. -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.28/CORE -lperl -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu -lpython3.7m -lcrypt -lpthread -ldl -lutil -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-2.5 -lpthread -lgmp -ldl -lcrypt -lm
  • OS: Debian Buster
  • Terminal: MATE terminal


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Yegappan Lakshmanan

unread,
Mar 11, 2021, 12:29:52 PM3/11/21
to vim/vim, Subscribed

You can use the backtick-expansion only with Ex-commands that accept
a filename as mentioned in the help:

Note that such expressions are only supported in places where a filename is
expected as an argument to an Ex-command.

AvianY

unread,
Mar 11, 2021, 12:31:50 PM3/11/21
to vim/vim, Subscribed

if that is the case, then consider this a feature request as this is quite limiting at the moment

Gary Johnson

unread,
Mar 11, 2021, 12:49:24 PM3/11/21
to reply+ACY5DGB4NT747Q7ZN6...@reply.github.com, vim...@googlegroups.com
On 2021-03-11, AvianY wrote:
> if that is the case, then consider this a feature request as this is quite
> limiting at the moment

So use ^R (Ctrl-R) instead.

:!echo ^R=getline(".")

See

:help c_CTRL-R=

Regards,
Gary

vim-dev ML

unread,
Mar 11, 2021, 12:49:48 PM3/11/21
to vim/vim, vim-dev ML, Your activity

AvianY

unread,
Mar 11, 2021, 12:53:38 PM3/11/21
to vim/vim, vim-dev ML, Comment

Thank you for your response, but I still think that this is something that doesn't make sense to not be working. What you described seems more like a workaround to an otherwise sensibly-looking solution (what I proposed)


You are receiving this because you commented.

Gary Johnson

unread,
Mar 11, 2021, 1:04:56 PM3/11/21
to reply+ACY5DGD3C6E76JSWLG...@reply.github.com, vim...@googlegroups.com
On 2021-03-11, AvianY wrote:
> Thank you for your response, but I still think that this is something that
> doesn't make sense to not be working. What you described seems more like a
> workaround to an otherwise sensibly-looking solution (what I proposed)

A problem with what you propose is that ` is understood by the shell
to mean execute the command within a pair of `` and replace them
with the standard output of the command. So what you propose won't
work.

Regards,
Gary

vim-dev ML

unread,
Mar 11, 2021, 1:05:18 PM3/11/21
to vim/vim, vim-dev ML, Your activity

Bram Moolenaar

unread,
Mar 11, 2021, 1:08:59 PM3/11/21
to vim/vim, vim-dev ML, Comment

Right, the backtick expansion is expected to be handled by the shell, since you are entering a shell command and backticks have a meaning there. We can't change that without breaking things.


You are receiving this because you commented.

Bram Moolenaar

unread,
Mar 11, 2021, 1:09:02 PM3/11/21
to vim/vim, vim-dev ML, Comment

Closed #7952.


You are receiving this because you commented.

AvianY

unread,
Mar 11, 2021, 1:14:43 PM3/11/21
to vim/vim, vim-dev ML, Comment

I may be mistaken, but there doesn't seem to be any = command in the shell. There is also no semantic meaning of an `= command ` in the shell. So this doesn't appear to be a problem.
what am I missing still?


You are receiving this because you commented.

Gary Johnson

unread,
Mar 11, 2021, 2:39:47 PM3/11/21
to reply+ACY5DGAEREIAAOOORY...@reply.github.com, vim...@googlegroups.com
On 2021-03-11, AvianY wrote:
> I may be mistaken, but there doesn't seem to be any = command in the shell.
> There is also no semantic meaning of an `= command ` in the shell. So this
> doesn't appear to be a problem.
> what am I missing still?

No, there is no = command, at least not in bash. Are you suggesting
that vim parse the :! command line for the special case of
a backtick-equal combination, execute that as a Vim expression and
otherwise pass the backtick expression to the shell for
interpretation by the shell? That could be done but would be
horribly inconsistent and confusing.

Regards,
Gary

vim-dev ML

unread,
Mar 11, 2021, 2:40:14 PM3/11/21
to vim/vim, vim-dev ML, Your activity

AvianY

unread,
Mar 12, 2021, 12:36:59 PM3/12/21
to vim/vim, vim-dev ML, Comment

I think backticks are too limited at the moment. They only work if they provide filenames to an Ex command.
This seems to me unnecessary.
There is no reason something like this shouldn't be possible: :echo `ls`.
or something like this :echo `=getline(".")`
or even something like this: :!echo `=getline(".")`

I am proposing that inline backtics ALWAYS evaluate in the shell and inline backtick-equals ALWAYS evaluate in vim, not being limited to commands that accept filenames.

Since there is no shell command that starts with =, there is no problem if the expression gets always evaluated in vim, substituting whatever was there and then executing the remaining command.

This makes much more sense to me.


You are receiving this because you commented.

Reply all
Reply to author
Forward
0 new messages