People who code: we want your input. Take the Survey

Questions tagged [external-command]

Questions about calling external (shell) commands from within Vi or Vim.

Filter by
Sorted by
Tagged with
1
vote
1answer
229 views

How to disable vim source .cshrc when running external command?

I'm running external command inside vim by :!command. Noticed vim will source .cshrc before run the command, because I've added some echo in the .cshrc. Is there a way to force vim don't source the ....
1
vote
1answer
226 views

How to execute persistent command from vim to bash? [closed]

When in vim I try to execute a persistent command, ie alias gh="history | grep -a cd" it seems to work at first but then I go to shell and type gh it says command not found. Note : I'm in tty shell, I'...
1
vote
2answers
237 views

File emptied when command not found

Given this command: ex -sc '%!alfa' -cx file I get this result: sh: alfa: command not found which is to be expected. However an unintended side effect of this is that the file is emptied and saved....
1
vote
0answers
36 views

How do I define a custom fixer for ALEFix?

I'm trying to use :ALEFix to run a fixer that is not pre-defined. For example, I might want to run foo -a -b index.html to format index.html with options -a and -b. foo does not read files from stdin, ...
1
vote
2answers
131 views

How can I make external command use current line as input and append output to end of same line?

Using Vim 8.0 I'm trying to make a table where the first column is the name of a file and the second column the creation date of such file, to which I have access by the exif data. I would like to ...
1
vote
0answers
112 views

How do I prevent Vim from showing my terminal when executing an external command?

I'm running a long, blocking command using execute in Vim as part of a script. Vim shows the underlying terminal while executing the command, which is pretty distracting. function! DoSomething(query) ...
1
vote
1answer
21 views

Showing external command output only if not empty

Is it possible to silently run an external command, but show the output on the prompt only if there was any?
1
vote
1answer
27 views

Retrieving results from variations of system('top') returns errors

Directly on the Ubuntu terminal, I can extract the results from top regarding a specific PID with: top -p <pid> -n1 | awk '/<pid>/' Where <pid> should be substituted with a PID ...
1
vote
0answers
188 views

What encoding does :! use?

I'd like low-level control over exactly what bytes I send and receive from a process spawned from some vimscript. What encoding is used for communications with commands started with :!foo? Can I ...
1
vote
0answers
39 views

Change where a register actually points (in this case, redirect “+” [sys clipboard], to an external program) [duplicate]

Setting up vim on WSL, and I want to be able to redirect the vim internal clipboard to the windows clipboard. This is possible if running an X server like XMing, but I don't want to do that. I have 2 ...
1
vote
0answers
58 views

How does one automatically run a function when any error message appears?

I would like to play sounds for accessibility reasons. Do I need to patch and compile (neo)vim to provide some sort of OnError autocmd? edit: more generically I'm looking for a way to hook into ...
1
vote
0answers
53 views

Reading in content from an external command with utf-8

I've got the following vim script to show a perldoc or per man page into a new tab and then rewrap it the text so it's more readable (I have a very wide monitor). nnoremap K :execute "tabnew <bar&...
1
vote
0answers
36 views

When defining a command which uses an external tool (like :perldo), how do I cancel upon error?

I created a Vim command which will invoke perl6 as a filter, analogous to :perldo, though of course it isn't as powerful as :perldo. (Being an external command rather than an internal interpreter, ...
1
vote
2answers
3k views

How can I run a batch file in Vim's console?

I want to use Vim as a simple c++ editor in windows (I have no experience with Linux). Nothing fancy, just want to get things started. To compile a .cpp file from CMD I have to run a batch file in ...
1
vote
0answers
660 views

Editing rich text document (.rtf) [duplicate]

In college sometimes we are not allowed to use MS Word (because we cant use autocorrect or the red underline) and I also want to use VIM so I can type quicker. Is there a way how I can make and edit ...
0
votes
4answers
81 views

“Hard-include” in vim script

I want to: let s:asciiart = ["", "", s:hardinclude(system("command params")), "", ""] where command returns one string with: "art-line-1", "art-line-2", "art-line-3" so I end up with: s:asciiart =...
0
votes
1answer
1k views

my ag shortcut chokes on spaces

I got this in my .vimrc: set grepprg=grep\ -nriI\ --exclude=tags\ --exclude-dir=vendor " The Silver Searcher if executable('ag') " Use ag over grep let &grepprg = "ag --nogroup --nocolor --...
0
votes
2answers
4k views

Executing a shell command in the parent directory

I'm trying to use :! to run my test suite. The file I'm working on is: /foo/bar/baz.py My tests are in: /foo/test I tried running :!../python -m unittest test but I get the following error:/bin/...
0
votes
1answer
83 views

Why does :r!vi jam my terminal?

Is it legal to do :r!vi in vi? A friend asked me to try it and it jammed my terminal. What exactly causes this? Is there anyway to recover the terminal without closing it and opening a new one?
0
votes
1answer
29 views

Paste the first column at the bottom line of the editing file

Here is the file sample.txt i am editing in vim: col11 col12 col21 col22 awk can cut the first column from sample.txt: awk '{print $1}' sample.txt In vim it is :!awk '{print $1}' %,how can i ...
0
votes
1answer
231 views

How can I run awk script with in vim?

We know that we can run commands from vim using :!command <args>. For example: :%!awk '{ print $2,$1,$3 }' FS=',' OFS=',' :%!sort I am having trouble running an awk script within vim. I can run ...
0
votes
1answer
127 views

How can I keep the cursor position when piping the buffer through an external command?

I sometimes make shortcuts for myself, which run some external command on the current buffer, such as nnoremap <C-f> :%!clang-format -style=file<C-m> which formats the buffer with clang'...
0
votes
2answers
372 views

How to create a function to `hash` buffer content

I want to create a function that I can call to replace a specific string pattern with md5sum of current buffer. I have no experience writing VimL before and can't figure out the way to do it. This ...
0
votes
2answers
67 views

Can I pipe vim spelling suggestions to an external program?

I know I can write a buffer to an external program with :w !<command>, but is there a way to pipe the contents of the spelling correction list I get with z= into an external program (i.e. dmenu)...
0
votes
1answer
701 views

Vim can't search for dot

I'm trying to write a Vim script function to toggle between -> and . but searching for . is seemingly impossible. I've tried to search using ASCII (decimal and hex) and it doesn't work. It all ...
0
votes
1answer
49 views

How to map a call to a system function using the current filename?

I've been using vim for a little while and I'm doing some LaTeX with it, using Tectonic as the engine. What I was doing to generate the pdf (without leaving the editor) :call system("tectonic main....
0
votes
1answer
133 views

Substring of filename in external command (bang)

Is it possible to execute bash string manipulations to the filename of the current file, represented by % in external commands from within vim? Example: I am editing a file myfile.txt. Using :! ...
0
votes
1answer
14 views

au VimLeave ex mode command not returning output

I've been using the fmt Unix tool to standardise line length, for example :%! fmt -999 (thanks to this answer). I'd like to do this by default in Markdown files, so in ~/.vim/ftplugin/markdown.vim I ...
0
votes
2answers
29 views

Colours in (g)vim output window

I've started learning Rust, and have been setting up my Vim workflow to use it. I'm still relatively new to Vim, and mostly what I've written in it is PHP for a website. Now that I'm working with a ...
0
votes
1answer
183 views

I want to save my typescript file, and immediately run tsc myfile.ts from inside vim. What is the best way to accomplish this?

I am building a daemon, and nodemon currently monitors a file called server.js, which is compiled from the file I am working on, server.ts In order to compile server.ts, after saving with :w, I need ...
0
votes
1answer
121 views

How to replace entire buffer with the contents of a variable?

I am trying to replace the entire buffer with the output from an external command. Similar to :% !myprog, but only if the command succeeds: let output = system('myprog') if v:shell_error == 0 " ...
0
votes
1answer
687 views

Changing PYTHONPATH from inside VIM

Today I was writing code in VIM and wanted to change the PYTHONPATH and so I ran: :!echo $PYTHONPATH;export PYTHONPATH="/home/oli/git/published_libraries/computer_communication_framework";echo $...
0
votes
1answer
49 views

What is :silent !echo doing? Why does it get the cursor to the top?

This question on StackOverflow triggered my curiosity. What does :silent !echo doing? The first time I saw something like :excommand !shellcommand was when I was looking for a way to save a read-only ...
0
votes
1answer
96 views

Formatting using BufWritePost ends up with WARNING

I am trying to format PHP files using the following function: function! PHPCSFixer() let l:fixer_path = '$HOME/....
0
votes
1answer
71 views

How to import library in my template python script? (not working like in vim like in the repl)

I have a python script for generating templates that's being invoked by this line in my vimrc file: autocmd BufNewFile ~/Documents/wiki/diary/*.mkd :silent 0r !vimwiki-diary-template.py That works. ...
0
votes
2answers
107 views

don't capture stderr for git grep as grepprg

I'm trying to use git grep as my grepprg, but I keep getting spurious files such as ~/fatal: Not a git repository (or any of the parent directories): .git. Is there a way to configure vim to correctly ...
0
votes
1answer
251 views

How do I control an external program from vim? The final end is to listen to audio and make a transcript in sync

So it seems that vim is great for so many things. And I love it. And yet, it is the configuration that sometimes is a limitation for those of us who don't get a tight grasp on how to tinker into it. I ...
0
votes
1answer
41 views

e or tabe into path resulting from a ! command

Given a bash function, getMyFilePath(), which results in a directory path, /mydir, how can I open a new tab, passing this function to navigate there?
0
votes
1answer
300 views

How to setup the default browser to follow hyperlinks [closed]

On a text file with a hyperlink (http://url/) if I hover the mouse over the hyperlink and click on it, it is opened on chrome. How can I change the browser that vim decides to use when following ...
0
votes
1answer
380 views

Pipe the content of the current buffer into an external command and then read the output into a new empty buffer?

I've established that it's possible to take the contents of a buffer (even one that isn't saved anywhere) and pipe it to a command. like so: :w ! petit --wordcount But! Is it possible to take the ...
0
votes
0answers
13 views

Fix line wrapping in external commands

Sometimes when I have a vim instance open for a long time, I'll notice that newlines no longer reset the column in external commands: :! echo a; echo b [No write since last change] a b Press ENTER ...
0
votes
1answer
69 views

Is there a way to change the message “press ENTER or type command to continue” to something else?

I would like to change it to make something like a separator between !python % Change this(my computer is in spanish): To something like: Hello World --------------- Hello World --------------- ...
0
votes
0answers
331 views

How does (neo)vim set $PATH for system(['command'])

When I want to call an external program, I have the option of spawning a shell or not. system('my command') will spawn a shell (executing your .bashrc/etc and all it seems). system(['my command']) ...
0
votes
0answers
26 views

error output when using commands proxied via WSL (asyncrun plugin)

I have wsl - ubuntu installed under Windows 10. Some ubuntu's commands are proxied to use in cmd by create .bat files and add them to PATH environment of windows10, pattern like following: @echo off ...
-1
votes
2answers
349 views

Shortcut for automatic execution

I've found the following command to execute Python or Matlab or any other language as far as I understand to execute code nnoremap <buffer> <F9> :exec '!python' shellescape(@%, 1)<cr&...
-1
votes
1answer
42 views

Why doesn't xdg-open trigger autoread?

When set autoread,if I run :!kate %, do some editing operations and exit, the file in vim will auto reload to my new changes. However, :!xdg-open % doesn't work. My vim version is: VIM - Vi IMproved 8....
-1
votes
1answer
24 views

how to filter text containing a vim variable?

In vim, version 8.1, I need to use a shell command, not on a constant text, but containing a vim variable. e.g. in Ex cmdline display by echo the difference in years from current date to a given date (...
-1
votes
1answer
117 views

How can I display the sloc (source lines of code)?

Is there a way to display the sloc? I have searched every where and all I get is how to display total lines or how to show line numbers.
-1
votes
1answer
28 views

How to pass custom arguments to the shell invoked by :terminal?

I would like to specify the startup command to run on the :terminal shell. E.g. bash -c ls. The shell can be specified with set shell=bash, but how to specify the arguments? In another use case, I ...

1 2 3
4