Stack Exchange Network

Stack Exchange network consists of 175 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
2answers
27 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
35 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)...
3
votes
3answers
73 views

Write buffer to command and append stdout back to same buffer

I've opened an empty buffer with just vim. I have a shell script in the same directory that I can pipe SQL to. That script will print the result of the execution to stdout. In my empty buffer, I ...
2
votes
1answer
63 views

get exit status from system() call

Calling the function system("<command>") or systemlist("<command>") retrieves the stdout output from a shell call to <command>. How can I retrieve the exit status of that command? ...
0
votes
2answers
28 views

Pass character-wise visual selection to an external command

I want to VISUAL select a piece of text character-wise and pass it to an external command. For example I want to select only the URL from the the text below abcde www.google.com abcde and open it ...
0
votes
2answers
105 views

How to execute commands in vim, piping the output back into the editor in real time?

So, to begin, this is similar to Pipe shell command into buffer in real-time. The difference is that the top answer there pipes the output to a new buffer. How do I pipe the output to the editor ...
0
votes
1answer
83 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
0answers
23 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']) ...
2
votes
1answer
29 views

Why does colon in shell command read the wrong file?

I write ruby test files in vim, and regularly run tests from the file I'm editing by running :!rspec %:N or something similar (to execute the test at line N). The problem is that when the first ...
1
vote
1answer
22 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 ...
0
votes
1answer
83 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
35 views

Function arguments + shell

I'm trying to write a command for adding a Python import line. The problem is that what's added it import a:name and not the module name. Here's the code func! PyImport(name) w silent !isort ...
0
votes
1answer
56 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
26 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
43 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
237 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
58 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
24 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 ...
3
votes
1answer
46 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
38 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
604 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
185 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
31 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
155 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&...
3
votes
2answers
162 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
124 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
37 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
205 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
1k 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
56 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
64 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
489 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
297 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
2answers
110 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
92 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
99 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
607 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
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&...
3
votes
1answer
93 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
64 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
140 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
187 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
303 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
79 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
1k 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
171 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
254 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
33 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
225 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
752 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 ...