[vim/vim] Pass buffer filetype to external shell command (Discussion #16022)

11 views
Skip to first unread message

avidseeker

unread,
Nov 9, 2024, 6:27:52 PM11/9/24
to vim/vim, Subscribed

"/home/mool/vim": >
  :p			/home/mool/vim/src/version.c
  :p:.				       src/version.c
  :p:~				 ~/vim/src/version.c
  :h				       src
  :p:h			/home/mool/vim/src
  :p:h:h		/home/mool/vim
  :t					   version.c
  :p:t					   version.c
  :r				       src/version
  :p:r			/home/mool/vim/src/version
  :t:r					   version
  :e						   c
  :s?version?main?		       src/main.c
  :s?version?main?:p	/home/mool/vim/src/main.c
  :p:gs?/?\\?		\home\mool\vim\src\version.c

Examples, when the file name is "src/version.c.gz": >
  :p			/home/mool/vim/src/version.c.gz
  :e						     gz
  :e:e						   c.gz
  :e:e:e					   c.gz
  :e:e:r					   c
  :r				       src/version.c
  :r:e						   c
  :r:r				       src/version
  :r:r:r			       src/version

The extension %:e is the closest to what I need, but that doesn't work for files without extensions (which have their ft set by a modeline)


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/16022@github.com>

Christian Brabandt

unread,
Nov 10, 2024, 9:37:08 AM11/10/24
to vim/vim, Subscribed

You are showing the documentation, I don't understand your issue. Note: Buffer Filetype is in &ft variable. you can use that to pass around


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/16022/comments/11204474@github.com>

avidseeker

unread,
Nov 10, 2024, 12:35:43 PM11/10/24
to vim/vim, Subscribed

I have a script that selects templates based on the given filetype and outputs them to stdout. For example:

:.!tplt %:e

But the %:e is not always reliable. Does vim offer a way to pass variables for shell? Maybe something like

:.!tplt "$ft"


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/16022/comments/11205532@github.com>

Gary Johnson

unread,
Nov 10, 2024, 2:02:33 PM11/10/24
to reply+ACY5DGGQ4A7ZNZFUVD...@reply.github.com, vim...@googlegroups.com
On 2024-11-10, avidseeker wrote:
> I have a script that selects templates based on the given filetype and outputs
> them to stdout. For example:
>
> :.!tplt %:e
>
> But the %:e is not always reliable. Does vim offer a way to pass variables for
> shell? Maybe something like
>
> :.!tplt "$ft"

To use the value of an option, prefix the name of the option with
'&', e.g.,

:echo &ft

The option value &ft has to be expanded and Vim needs to be told to
expand it rather than pass it to the shell command literally. That
can be be done with the :execute command, which expands its
arguments before executing the resulting expression, e.g.,

:execute ".!tplt" &ft

Note that the range has to be part of the expression that :execute
executes; the range can't come before "execute".

Note also that :execute inserts spaces between its arguments.

See

:help expr-option
:help :execute

HTH,
Gary

vim-dev ML

unread,
Nov 10, 2024, 2:03:01 PM11/10/24
to vim/vim, vim-dev ML, Your activity


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/16022/comments/11206019@github.com>

Reply all
Reply to author
Forward
0 new messages