Questions tagged [external-command]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
25 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
26 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
1answer
29 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 ...
2
votes
0answers
28 views

Use external commands within venv virtual environment

Same question as Use Vim with virtualenv, except for these differences: I'm using bash, not zsh using venv, not virtualenv or virtualenvwrapper I have a keybinding to run the current buffer as a ...
3
votes
1answer
36 views

running external command on contents of register

I know I can use ranges/marks with the ! command like so: %! column -t etc. Is there any way to pass a register to the external command instead of the current buffer? I imagine it would look ...
2
votes
1answer
55 views

Neovim 0.17.5: bash command top failed tty get

please be gentle, I am trying to learn neovim, coming from vim the command :!top executed inside neovim returns top: failed tty get shell returned 1 After googling, only search results from fzf ...
0
votes
1answer
40 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 " ...
1
vote
2answers
31 views

How to get the current cmd line of (neo)vim?

If I start with nvim -u NONE , I want to get "-u NONE". I tried to get pid using bash and python, but it seems to return the pid of the process that is created (either python or bash). So how ...
1
vote
1answer
60 views

How to get the names of all open buffers?

I can use % to get the name of the focused window for commands. How can I get a space-separated list of all buffers for use in a command? For example, I would like to call :!cat [all] where [all] ...
0
votes
2answers
97 views

Prevent “Press ENTER or type command to continue” prompt after external command executes

I am using :grep to search for occurences of a string within a set of files: :grep rainbow *.txt This result is then shown in the terminal: doc1.txt:2:saw a rainbow today doc2.txt:17:it was not a ...
2
votes
1answer
40 views

Update external file based on VIM mode

Currently I have my vim set up to update the statuslline based on what mode the editor is in. Like if I'm in insert mode then the statusline turns red. Magenta in replace mode. Green in command ...
0
votes
1answer
39 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 $...
2
votes
1answer
47 views

Why does vim call powershell surrounded by two single quotes?

I'm attempting to use powershell from gvim, and when I do...I set: :set shellcmdflag=-NoProfile\ -NoLogo\ -ExecutionPolicy\ RemoteSigned\ -windowStyle\ Normal\ -Command :set shell='C:\\windows\\...
1
vote
1answer
51 views

How to pass a string as stdin to a job?

I have a shell command which reads from stdin, processes the input, and writes to stdout. To call it synchronously from vim I can do system('mycommand', data) where data is some string my vimscript ...
0
votes
2answers
58 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
41 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
139 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 ...
3
votes
1answer
270 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
34 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
712 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
97 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
59 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
32 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
26 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
187 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 ...
1
vote
1answer
101 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 ...
1
vote
1answer
70 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
30 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
46 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 ...
2
votes
1answer
418 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
86 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
25 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
50 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
42 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
989 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
381 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
36 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
199 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
206 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
156 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
293 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, ...
3
votes
1answer
5k 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
57 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
81 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
752 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
465 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
148 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
122 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
105 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 ...