2022 Developer Survey is open! Take survey.

Questions tagged [external-command]

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

Filter by
Sorted by
Tagged with
1 vote
0 answers
15 views

Open a window with output of an external command [duplicate]

When editing a file, i sometimes run external commands - such as validating and formatting - and instead of capturing the external command's output and processing it in vimscript, i'd like to open an ...
user avatar
0 votes
1 answer
39 views

How to filter lines only if the filter is successful?

I have the following lines in ~/.vim/ftplugin/python.vim: " yapf integration function FormatFile() :normal mp 0,$!yapf :normal `p endfunction autocmd BufWritePre *.py call FormatFile() ...
user avatar
  • 23
0 votes
0 answers
26 views

Call custom bash function from Vim

I have created a bash function, in its own .sh file, which I want to use from within Vim, and later use if from within the lightline config file. I have tried many ways, but I cannot make it work. ...
user avatar
  • 165
2 votes
3 answers
58 views

how to use shell script (external command) to select a file to open&edit

I've got a shell script: find... | stuff | xargs vi which works fine from the shell. But if I invoke that from inside Vim like :! find... | stuff | xargs vi it's kinda weird... like maybe I'm seeing ...
user avatar
  • 695
0 votes
2 answers
41 views

How to execute a shell command with the current buffer content and open a new split buffer with the command output?

I have an external command which accepts a SQL. I want to execute it within vim while editing SQL. I found two ways but both are not very satisfying. :w !<cmd> This passes the content of the ...
user avatar
  • 103
0 votes
2 answers
32 views

Is there a way to run current script in a split window (mimicing VSCode for example)?

When editing a script in vim, I can run it with :! bash % or :! python % for python scripts. When running the script, vim kinda goes back to the terminal, runs there, and then, after "ENTER" ...
user avatar
1 vote
1 answer
69 views

`:!sort` unresponsive

I want to randomly sort a file, but it somehow seems to be stuck in a loop or unresponsive. I dinstinctly remember it worked last time, so I must have done something wrong. Here is my code: :!sort --...
user avatar
  • 135
0 votes
0 answers
23 views

How to recover buffer contents after a crashed shell command?

I had a buffer containing lines like the monkey to be located in the rainforest i assume I piped it through :%! awk '{n=$1;sub(/ *[0-9]+ +/,"");for(i=0;i<n;i++)print}' which caused VIM ...
user avatar
  • 1,689
1 vote
1 answer
69 views

`:call append!` -- how vim insert line (append or setline) while respecting indentation

I want to put a string function output in my vim when press xx. My current working example is: nnoremap <silent> xx :call append('.', 'string_output')<CR> However, this put a line without ...
user avatar
  • 25
4 votes
2 answers
65 views

Can a vim filter be interactive?

Is there a way to use a read filter that calls an interactive command? My use case is a grep command that returns a long list of tags that I might want to include in a blog post; I was hoping to be ...
user avatar
  • 171
4 votes
1 answer
96 views

How to reference a register in an ex command

I'm trying to write what I thought would be a simple macro to take some values that have been yanked into some registers (a & b) and use bc to do some addition with those values. Here is the ...
user avatar
  • 143
0 votes
0 answers
15 views

Make nvim to show colors while performing external commands [duplicate]

By default my new neovim doesn't do this showing everything black and white. How could I make it show as on picture 2 (it works this way on raw vim)?
user avatar
  • 1
0 votes
1 answer
46 views

Run another command if first command fails on keypress

Is it possible to combine the two commands map <F5> :w<CR>:exec '!python' shellescape(@%, 1)<CR> map <F6> :w<CR>:exec '!poetry run'<CR> so that when I press F5, it ...
user avatar
  • 3
1 vote
2 answers
133 views

Piping buffer through a command, handling failure gracefully

I want to be able to lint my code from within vim, using tools like clang-format and yapf and I'd rather do this without installing a more complex plugin. I can pipe the current buffer through a text ...
user avatar
  • 115
0 votes
0 answers
68 views

Reindent html with xmllint

I'm trying to reindent current HTML file with this command from inside vim : :!xmllint --html --format % 2>/dev/null But, all it does it displays the output to stdout without actually modifying ...
user avatar
  • 1,878
0 votes
2 answers
50 views

How to execute a shell script from a line in a file with `%` in it

I have a shell script on a line alone in a file which I would like to be able to easily execute from vim. Normally I could simply use Y:!^R", but this particular script has % in it, which is ...
user avatar
  • 173
-1 votes
1 answer
46 views

how to filter text containing a vim variable?

In vim, version 8.1, I need to use a shell command, not on a constant text, but containing a vim variable. e.g. in Ex cmdline display by echo the difference in years from current date to a given date (...
user avatar
2 votes
2 answers
204 views

How to execute shell command and show result right inside vim similar to when execute command through autocmd?

The main objective of this question is I want to get the shell command's execution result to show in small split window right inside vim while I'm editing the file; the same result I would get when I ...
user avatar
  • 121
0 votes
1 answer
40 views

au VimLeave ex mode command not returning output

I've been using the fmt Unix tool to standardise line length, for example :%! fmt -999 (thanks to this answer). I'd like to do this by default in Markdown files, so in ~/.vim/ftplugin/markdown.vim I ...
user avatar
0 votes
2 answers
293 views

Colours in (g)vim output window

I've started learning Rust, and have been setting up my Vim workflow to use it. I'm still relatively new to Vim, and mostly what I've written in it is PHP for a website. Now that I'm working with a ...
user avatar
  • 123
0 votes
1 answer
33 views

Paste the first column at the bottom line of the editing file

Here is the file sample.txt i am editing in vim: col11 col12 col21 col22 awk can cut the first column from sample.txt: awk '{print $1}' sample.txt In vim it is :!awk '{print $1}' %,how can i ...
user avatar
  • 820
1 vote
0 answers
78 views

How do I define a custom fixer for ALEFix?

I'm trying to use :ALEFix to run a fixer that is not pre-defined. For example, I might want to run foo -a -b index.html to format index.html with options -a and -b. foo does not read files from stdin, ...
user avatar
-1 votes
1 answer
47 views

How to pass custom arguments to the shell invoked by :terminal?

I would like to specify the startup command to run on the :terminal shell. E.g. bash -c ls. The shell can be specified with set shell=bash, but how to specify the arguments? In another use case, I ...
user avatar
  • 371
1 vote
1 answer
1k views

How can I run awk script with in vim?

We know that we can run commands from vim using :!command <args>. For example: :%!awk '{ print $2,$1,$3 }' FS=',' OFS=',' :%!sort I am having trouble running an awk script within vim. I can run ...
user avatar
  • 113
1 vote
1 answer
54 views

How to use the current filename in a shell command?

I would like to run a shell command on the current file - ie, I saved an empty file and would like to delete it. I've found % represents the current filename, but when there are spaces in the filepath ...
user avatar
  • 173
0 votes
1 answer
74 views

What is :silent !echo doing? Why does it get the cursor to the top?

This question on StackOverflow triggered my curiosity. What does :silent !echo doing? The first time I saw something like :excommand !shellcommand was when I was looking for a way to save a read-only ...
user avatar
  • 1,572
-1 votes
1 answer
190 views

How can I display the sloc (source lines of code)?

Is there a way to display the sloc? I have searched every where and all I get is how to display total lines or how to show line numbers.
user avatar
1 vote
2 answers
281 views

Check if :make fails

I just setup this mapping for my latex development: nnoremap <buffer> <LocalLeader>o :make %:r.pdf <Bar> !open %:r.pdf<CR><CR><CR> But I wondered about checking if ...
user avatar
  • 20.6k
-1 votes
1 answer
51 views

Why doesn't xdg-open trigger autoread?

When set autoread,if I run :!kate %, do some editing operations and exit, the file in vim will auto reload to my new changes. However, :!xdg-open % doesn't work. My vim version is: VIM - Vi IMproved 8....
user avatar
  • 99
0 votes
1 answer
138 views

Formatting using BufWritePost ends up with WARNING

I am trying to format PHP files using the following function: function! PHPCSFixer() let l:fixer_path = '$HOME/....
user avatar
1 vote
1 answer
50 views

Shortcut to open a particular website

I'm using neovim on mac os, in case that information is of use. In the shell I have some aliases such as alias g='open HTTP://google.com For sites that I access regularly, I would like to be able to ...
user avatar
  • 735
0 votes
0 answers
18 views

Fix line wrapping in external commands

Sometimes when I have a vim instance open for a long time, I'll notice that newlines no longer reset the column in external commands: :! echo a; echo b [No write since last change] a b Press ENTER ...
user avatar
  • 273
1 vote
2 answers
215 views

How to run external commands in vim from windows OS?

I learn vim in the Debian distro. In debian I can run commands like 'ls', 'cd', 'curl' etc directly from vim via power of '!' this sign. But now I am in windows because of the driver issue. But I don'...
user avatar
  • 33
0 votes
1 answer
108 views

How to import library in my template python script? (not working like in vim like in the repl)

I have a python script for generating templates that's being invoked by this line in my vimrc file: autocmd BufNewFile ~/Documents/wiki/diary/*.mkd :silent 0r !vimwiki-diary-template.py That works. ...
user avatar
  • 695
2 votes
1 answer
161 views

How to put the output of a function call into quickfix list?

I have the following function that runs eslint project wise: function! EslintProject() " Allows using eslint --format compact output with quickfix list set errorformat+=%f:\ line\ %l\\,\ col\ %c\\...
user avatar
7 votes
1 answer
241 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 ...
user avatar
  • 25.5k
1 vote
1 answer
152 views

Nvim external commands to write and delete files inside a function

I use Neovim in a Linux (Arch Linux) environment. I have written a function to help me preview my markdown documents in PDF format without using a whole plugin. I've also added a simple command named "...
user avatar
  • 45
2 votes
3 answers
338 views

How can I make external command use current line as input and append output to end of same line?

Using Vim 8.0 I'm trying to make a table where the first column is the name of a file and the second column the creation date of such file, to which I have access by the exif data. I would like to ...
user avatar
  • 21
4 votes
4 answers
1k 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 ...
user avatar
  • 59
3 votes
2 answers
284 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 ...
user avatar
1 vote
0 answers
157 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) ...
user avatar
6 votes
1 answer
652 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/...
user avatar
  • 447
0 votes
1 answer
80 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 --------------- ...
user avatar
1 vote
3 answers
239 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 ...
user avatar
1 vote
1 answer
45 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 ...
user avatar
1 vote
1 answer
26 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?
user avatar
  • 13
0 votes
4 answers
101 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 =...
user avatar
  • 233
2 votes
0 answers
68 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 ...
user avatar
  • 121
3 votes
1 answer
578 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 ...
user avatar
  • 545
3 votes
1 answer
70 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 ...
user avatar

1
2 3 4 5