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
9
votes
3answers
4k views

Bash not recognizing aliases when run from Vim [duplicate]

In Vim, when I run this command :!bash -c "ll", I get this error message bash: ll: command not found. ll is an alias in my ~/.bashrc file. If I just enter ll from bash it works. I created a ~/....
8
votes
1answer
4k views

Define custom commands for the * and + registers

If I'm using a build of Vim with the xterm_clipboard feature then the system clipboard content is available through the + register. If the build I'm using doesn't have this feature, can I make the "+ ...
82
votes
9answers
51k 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 ...
28
votes
5answers
7k views

How to use an external command in Vim to modify selected words and lines?

Something I've found useful in other editors is the ability to: take the selected text run an external command and pass the selection to its stdin take the external commands stdout and replace the ...
4
votes
2answers
488 views

Why do exclamation ! shell commands in GVIM show error: “syntax error near unexpected token (” for “ls() (”?

E.g., it I do: !echo a or any other !, it first prints: syntax error near unexpected token ( ls() ( /* my alias */ ) and then the actual command. The problem only happens in GVIM, not in Vim. ...
32
votes
2answers
11k 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 ==...
7
votes
1answer
183 views

Difference between `:!{cmd}` and `:w !{cmd}` regarding alternate screen

On a Linux platform I see this difference of behavior between running a shell command with :!{cmd} (which just runs the command directly) and with :w !{cmd} (which passes the buffer as standard input ...
14
votes
6answers
15k 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 ...
10
votes
5answers
3k views

Replace selection with output of external command

Assuming I have a line in a file with XXXX being a placeholder I have selected via v as follows: XXXX Some other text How can I change only the XXXX with the output of an external command, such as ...
52
votes
2answers
16k views

How to run bash command over current file and replace buffer with result? [duplicate]

I currently deal with lots of json files and am quite fond of the bash comand jq, e.g. if I want to format the file I do jq . ugly.json > formated.json Now, I don't want to leave vim, but run it ...
18
votes
2answers
7k views

How can I change Vim's start or intro screen?

When I start Vim without any files, I always see this: VIM - Vi IMproved version 7.4.580 by Bram Moolenaar et al. Vim is open source and freely distributable ...
9
votes
1answer
181 views

How to modify visually selected block with external command?

I have a file that is made up of two vertical parts. On the left side, the data is already formatted and I don't want to change it. I only want to format the data on the right side. Say I have a file ...
5
votes
2answers
252 views

How can I filter a buffer to an external command on save without causing any side effects?

Since importing a package and not using it in Go is a compilation error, fixing the import manually can be a bit of a pain while debugging, so I'm currently using this to fix it up automatically ...
1
vote
2answers
1k views

Escape sequences from external commands cluttering output in GVim

One of the reasons i prefer to run Vim from a terminal instead of running gVim is that the output of external gets cluttered up by escape sequences each time I execute commands like ls and grep that I ...
5
votes
1answer
1k 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
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 --...
63
votes
5answers
44k 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?
10
votes
1answer
8k views

Use Vim with virtualenv

I do a lot of Python and I use almost all the time a virtualenv along with virtualenvwrapper to keep my modules organised. But when I want to use those plugin from inside vim, through an external ...
19
votes
4answers
13k 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 ...
10
votes
3answers
3k views

How do I count the words in a part of a file, without leaving vim?

I have a file full of text (say Markdown or LaTeX). I would like to count the number of words in a part of this file. I know I can do :! wc -w % to run wc -w on the current buffer. And I know that I ...
5
votes
4answers
584 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?
9
votes
3answers
3k 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 ...
8
votes
4answers
2k views

Put a process started with ! in the background

If I do this from the shell: $ sleep 100 I can make it go to the background by doing: ^Z $ bg And then continue using my shell. You can get the same effect by adding a & to the end of the ...
5
votes
1answer
340 views

How can I make text formatting ignore concealed characters?

Question Working with text and various markup languages in Vim I have recently experimented with the conceal feature to hide some of the more verbose markup. I switch conceal off when writing and ...
10
votes
2answers
444 views

External command on unsaved buffer [duplicate]

Is it possible to pipe an unsaved buffer to an external command and then replace the buffer by the command’s output?
7
votes
1answer
4k views

Why vim cannot expand wildcards from the external command?

The following command works as expected within vim: :args `find . -type f` as well as this one (with wildcard): :args `find . -name \*.inc` However when I run the following: :args `find . -type f -...
6
votes
3answers
3k 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 ...
5
votes
1answer
229 views

Use shell variable substitution with current filepath

I want to be able to easily change the filename. This works: :! var=%; mv % ${var/.txt/.asc} But this doesn't: :! mv % ${%/.txt/.asc} My questions: Why doesn't this work? Doesn't VIM simply ...
4
votes
2answers
1k views

Error when sourcing my .vimrc

I've just added this line to my .vimrc to be able to open chrome without leaving vim. command GoogleChromeA execute "!google-chrome > /dev/null 2>&1 &" It works fine however, when I ...
1
vote
2answers
2k 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 ...
-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&...
5
votes
1answer
411 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/...
3
votes
2answers
2k views

How to export information from vim to bash

When you execute the shell in vim via the :sh command, the shell that is set in the shell option is executed. However, is it possible to pass some information from the vim instance that you are ...
3
votes
2answers
477 views

Passing a # character to the shell in vimscript?

In my previous question, I passed an argument into a Vimscript function and concatenated it into the command line. This works great, but when you pass a string that contains the # character, it balks ...
2
votes
2answers
716 views

Pipe shell command into buffer in real-time

I wrote this little function to update my plugins from within vim: function! UpdatePlugins() call system('for f in ~/.vim/bundle/*; do cd $f; git pull; done') endfunction command! UpdatePlugins ...
2
votes
2answers
288 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 ...
1
vote
1answer
1k 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?
1
vote
1answer
383 views

Concatination of arguments in vimscript when reading the output of a command to a buffer?

Is there a way to use a vimscript function to pass arguments to an external command? I have the following: function! GetJobLines(argA) " 1. Create a new buffer for the output enew " 2. ...
1
vote
1answer
594 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, ...
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 ...