Questions tagged [external-command]

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

Filter by
Sorted by
Tagged with
3
votes
4answers
99 views

Filter specific lines matching a pattern through external command

I'm trying to filter specific lines through external command. I think knowing how to do this would be extremely beneficial to me, so I'm trying to find a way to do this. As an example, I wanted to ...
3
votes
2answers
148 views

How can I use a range as input for an external command without deleting it?

I'm executing an external command that takes as input a range of lines within my file. :'<,'>!copy_stuff Running this runs copy_stuff correctly with the currently selected visual range (and it ...
1
vote
1answer
57 views

separate stdout and stderr of system() command

I can catch the output of running a system command via system() or systemlist(), but that actually gives me the result of stdout and stderr combined. As I am only interested in stdout (and may use ...
1
vote
0answers
55 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) ...
5
votes
1answer
113 views

job_start() command only works with seemingly random job options

I am getting some unexpected behavior when trying to run the zip shell command using Vim's job_start(). As an example, suppose I have two images (im1.png and im2.jpg) in the directory /home/username/...
0
votes
1answer
51 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 --------------- ...
1
vote
3answers
108 views

How can I create a command to remove non-consecutive duplicate lines?

I'm trying to remove (non-consecutive) duplicate lines in a file I have loaded in vim (without sorting them). In several places on the web I've found the nugget awk '!x[$0]++' as a pipe command that ...
1
vote
1answer
27 views

execute command after it print junk text?

I am using bspwm so I added this line to my .vimrc: au BufWritePost $XDG_CONFIG_HOME/sxhkd/sxhkdrc silent exec "!pkill -USR1 -x sxhkd && sxhkd & So that when I edit sxhkdrc, it ...
0
votes
2answers
46 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 ...
4
votes
1answer
188 views

Why is a pipe interpreted as a command termination in :cexpr system('shell cmd')?

If I type: :echo system('grep -IRn foobar ~/.vim | grep -v backup') Vim displays the output of the shell command: $ grep -IRn foobar ~/.vim | grep -v backup Which is the list of files containing ...
1
vote
1answer
18 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?
0
votes
3answers
49 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 =...
2
votes
0answers
40 views

Adjust terminal size using a system call from within Vim

All, I have a little function I'm trying to fix. I'd like to change my terminal Vim window size using the ASCII escape sequence \e[8;40;130t so that my writing window size stays the same when I use a ...
3
votes
1answer
39 views

How to open internal MediaWiki links with their full URL from within Vim?

I have a file in Mediawiki format, containing internal links (in a Mediawiki installation) * [[Topic A]] * [[Topic B]] * [[Vim]] (The asterisks are how MediaWiki lists are formatted, they are not ...
5
votes
4answers
384 views

How to dump output from external command into editor?

In example, I would like to paste the current time or date into editor by using external commands (such as date) without leaving vim. How this can be achieved?
0
votes
1answer
35 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
52 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 ...
26
votes
2answers
7k views

Extract the result of a shell command to a variable in a .vimrc file?

In my .vimrc file, I would like to store in a variable the result of an external command, in my case : $ echo $LANG So that my vimrc file would have : let language = output(!echo $LANG) if language ...
2
votes
0answers
97 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
49 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
244 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
47 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
1answer
78 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 ...
1
vote
2answers
37 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 ...
0
votes
2answers
229 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 ...
1
vote
1answer
117 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] ...
56
votes
4answers
38k views

How can I integrate gdb with Vim?

Instead of gdbtui or ctrl+x under gdb which shows source code on top of the screen I would like to see this in my Vim editor that would jump between tabs, and buffers accordingly. How can I do this?
17
votes
3answers
12k views

Can I issue an interactive shell in Vim window?

I know I can :! or :r! to execute external command and optionally insert its output into text. I can even perform :!sh and I'll spawn a shell that will live until I exit it - but while the shell is ...
2
votes
1answer
43 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 ...
2
votes
1answer
60 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\\...
8
votes
5answers
6k views

How do I get Vim to compile my .tex file when executing :w?

My writing routine is like this: I edit a .tex file using vim I go to the command line and I compile it using pdflatex. I find myself always saving the file with :w and immediately having to switch ...
0
votes
1answer
58 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 $...
1
vote
1answer
77 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
133 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
44 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
204 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 ...
4
votes
1answer
412 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? ...
1
vote
2answers
40 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
1k 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
115 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 ...
1
vote
2answers
1k views

How do you pass user input to a system command?

I'm trying to write an autocmd to make a commit to a git repository. Here is some non-functional code that should illustrate what I'm trying to do: let g: CommMsg = '' augroup misc autocmd! ...
0
votes
0answers
99 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
2answers
162 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 ...
3
votes
1answer
45 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
2answers
424 views

How to execute xdg-open from NERDTree in Linux?

Netrw able to execute file with xdg-open by pressing x, how about NERDTree ? [Response to downvote] If xdg-open can so easy/direct to work (which is the reason of downvote), then what's the point ...
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 ...
0
votes
1answer
321 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
121 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 ...
11
votes
3answers
5k views

Is it possible to have the output of a :! command in a split rather than the whole window?

If I have a vim session with two splits, when I execute a :! command, the result is shown in the entire window. Is it possible to have the output shown just on the active split?
72
votes
9answers
35k views

How to execute shell commands silently?

:!<command> can be used to execute a command in the shell. But this "takes over" my terminal and fills it with stdout of that particular command. How do I execute a command in the background ...