Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [external-command]

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

0
votes
1answer
33 views

Shell coloring handling with :read command

How can I deal with the colored outputs of shell commands when inputing them with :read? As an example, I have a self-defined git log command, and I would like to see it in a split window. That works ...
0
votes
1answer
23 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....
1
vote
2answers
38 views

How can I pass a text to an external program without changing the current buffer?

I want to do filter through an external program without actually filtering the lines (but to keep them). For example : %!grep aa > newfile If I do this, all the lines are deleted and I need to do ...
1
vote
1answer
50 views

opening powershell from inside vim

I want to run powershell from vim and I have achieved it using the following mapping: map <leader>cd :cd %:p:h<cr>:silent !powershell<cr> The problem is that I can't do anything ...
1
vote
0answers
27 views

How to make vim shell command wait for keypress?

I have assigned the macro !clear && gcc % && ./a.out to the key 'r'. So when I press '@r', I expect vim to: Clear the shell compile the current C file run the output The problem is ...
0
votes
0answers
66 views

Display output of a shell command in vim-airline status upon every save

I have access to both vim8.xx and neovim. For the vim-airline plugin for filetype tex, I'd like to add the output from the following shell command each time the buffer is saved to disk. texcount -sum ...
0
votes
0answers
23 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 ...
2
votes
1answer
42 views

:global, how to use matched pattern in the cmd of :g/pat/cmd?

Give a buffer each line contain a filename. how to use r! cmd on the filename, within a :g command? eg, BEFORE PROCESSING: file1.txt file2.txt AFTER PROCESSING (with wc -l): file1.txt 12 ...
1
vote
1answer
35 views

How to run shell commands on file without saving?

For example, if I want to run tidy on a file r! tidy % But I have to save the file beforehand. Is there any way around this?
3
votes
3answers
234 views

How to run zsh aliased command from vim command mode?

I have a bunch of really useful terminal programs which I use often while I am editing or writing. For example, dictionary is a popular one and I have aliased its usage to single character d in .zshrc ...
0
votes
2answers
63 views

How can I import output from linux commands into vim for editing?

Is there a way I can directly import/insert the output of any linux command into vim editor? For example: pwd in currently open vim buffer. Also From terminal how can I directly open command output ...
0
votes
1answer
28 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?
-1
votes
2answers
95 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&...
2
votes
2answers
102 views

sending variable commands in vim-slime

I am relatively new to vim and have started using the vim-slime plugin. One thing I use it for is to run python scripts, for example :SlimeSend1 python ~/myPythonFile.py I now would like to automate ...
1
vote
0answers
83 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
35 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
1answer
134 views

How to avoid “file has changed” warning when writing buffer?

I am using system() to change a buffer's file. I apply the same change to the buffer itself. I can't just reload the buffer because there are other unsaved changes. When I come to write the buffer, ...
2
votes
1answer
182 views

What is the correct way to escape UNC paths?

Let's say there is a file \\server-42\tmp\dir\test.txt. When my plugin tries to execute this command via system() it triggers an error: cd "\\server-42\tmp\dir" && git ls-files --error-...
1
vote
0answers
54 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 ...
0
votes
1answer
36 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
261 views

Can I disable running shell commands in Vim?

I am developing a command line application that uses Vim to edit an existing file. Think visudo or crontab -e. Is there any command line option that I can pass to Vim to disable shell commands?
0
votes
1answer
130 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 --...
2
votes
1answer
68 views

How to execute a bash command from the normal mode and send the output on a different buffer?

I have a bash_file that operates on a latex file to produce a pdf. #!/bin/bash /usr/bin/pandoc/ filein.md -t beamer -o fileout.md ; /usr/bin/pdflatex/ fileother.tex ; /usr/bin/evince fileother.tex ...
1
vote
1answer
74 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
60 views

Execute selection and redirect output to new buffer/tab

I want to automate something I started using. Short story is I have a file with some lines and I want to execute each line every now and then and see its' output, but I don't want it to override the ...
3
votes
1answer
563 views

Copy output of bash command to system clipboard?

If I run: :w !node It will take my current buffer and send it to stdin and run the code in node. If I run: :redir @+ | echo "bob" | redir END It ends up on the system clipboard. But if I want to ...
1
vote
0answers
49 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&...
3
votes
1answer
58 views

Why python autocompletion does not work if path to python binary is taken from variable?

I use YouCompleteMe for python3 code completion, and when I have let g:ycm_python_binary_path = '/usr/bin/python3' in my ~/.vimrc it works great. However, if I change it to let python3path = system(...
2
votes
0answers
61 views

Alter how oldfiles are displayed

Is it possible to "preprocess" the oldfiles list so that it's easier to navigate visually? As far as I can tell, the contents of the oldfiles list are presented as ordinary absolute paths, but with ...
4
votes
3answers
135 views

`Read` seems to bring an extra line - how to prevent this?

I set up this function in my .vimrc file. It duplicates the current window, moves it to a new tab, reads the output of yapf (a code formatter) run on the current file, sets up a diff between the ...
2
votes
2answers
138 views

Diffsplit with output of external command in Vim?

I know I can enter diff mode in vim by calling diffsplit <filename>. I also know I can call an external command and replace the file contents with its output (e.g. in this answer someone uses ...
2
votes
1answer
105 views

How to account for special characters \% in mapping

I am using vim on Windows and have following mappings: imap <f4> <ESC>:w<CR>:!clang -std=c++11 -o output\%.exe %<CR> imap <f5> <ESC>:!output\%.exe<CR> As we ...
0
votes
1answer
64 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
2answers
585 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/...
1
vote
1answer
141 views

Checking if Makefile exists before executing autocmd

I want Vim to execute build the project automatically after I write the buffer to a *.c or *.cpp file. Here is what I've done: autocmd BufWritePost *.c,*.cpp make This one works as expected (but the ...
0
votes
1answer
189 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 ...
1
vote
0answers
31 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, ...
2
votes
1answer
138 views

How to get line numbers of selected text

Is it possible to get the line numbers of selected text to pass to an external command? Context: I'd like to integrate pyfmt into vim. Ideally, I'd like to be able to select some text and type some ...
2
votes
3answers
554 views

Execute external command in split window

Is there a way to get the following in Vim: If I execute a command in Vim like !make c, I would like to have a frame/split that pops up like in syntastic instead of switching to terminal view. That ...
3
votes
2answers
70 views

Filter text and insert text after cursor or in register?

I want to filter some text through an external command without replacing the text, but rather have some way of inserting it afterwards or wherever I want. Say I want to calculate: 2^8 = I mark 2^8 ...
2
votes
2answers
384 views

How can I run :! commands inline instead of in a new cmd.exe window?

When using Gvim on Linux I can use :!ls to list files and directories 'in-line' in Gvim to navigate around the file structure and open files. However, on Windows when using :!dir, a cmd window opens ...
3
votes
3answers
147 views

How can I show a preview of my LaTeX buffer without stealing focus from Vim?

I'm using Vim to write LaTeX on my Mac. I could make a shortcut to execute pdflatex (it should be possible right?) and see the result on Preview. But it steals the focus when it updates to the new ...
3
votes
1answer
64 views

Text manipulation by calling external binaries or scripts

I want to automate certain text manipulation (essentially writing a plugin), but for easiness, I wish to minimize the use of Vim script whenever possible. This is because, indeed it is much harder to ...
8
votes
3answers
763 views

How do I know i am in a shell from vi command :sh?

In vi, I can get a shell terminal with :sh command. And later, I can return to vi by exit shell. But, if I was using the shell terminal for a long time, and I forgot whether exit will close anything ...
3
votes
1answer
48 views

# turning to exe when running terminal command

First of, I am sure there are plugins that will do what I am trying to achieve but I am using this as an exercise to learn vim as I am still quite new so I am not really interested in plugin ...
4
votes
1answer
365 views

Why does vim use temporary file or pipe for shell commands?

One can configure Vim to use temporary files(stored in /tmp directory by default) when shell commands(for example :%!ls) are executed. Those temporary files contain the output of an external command. ...
6
votes
1answer
112 views

Why does vim add ^J to the end of my macros?

I wrote short macro that helps me grep for the word under the cursor. Here it is in my .vimrc: let @a=":! git grep ^R^W^M" However, when I open vim and run :reg a, I see the following: "a :! git ...
2
votes
1answer
241 views

read from external command captures stderr as well

I have a binding in my .vimrc that reads the contents of the system clipboard to a line immediately below my cursor nnoremap <silent> <leader>f <esc> :read ! test -f /usr/bin/xsel &...
2
votes
1answer
53 views

Is there any way to switch between Vim and a :! command passed to the shell, before it is finished executing?

This would make my workflow immensely easier -- I have some simple maps for executing python .py files, and sometimes it would be nice to open an interactive session after running them (for example, ...
0
votes
1answer
80 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?