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
2
votes
1answer
716 views

read from external command captures stderr as well

I have a binding in my .vimrc that reads the contents of the system clipboard to a line immediately below my cursor nnoremap <silent> <leader>f <esc> :read ! test -f /usr/bin/xsel &...
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
3answers
269 views

How can I show a preview of my LaTeX buffer without stealing focus from Vim?

I'm using Vim to write LaTeX on my Mac. I could make a shortcut to execute pdflatex (it should be possible right?) and see the result on Preview. But it steals the focus when it updates to the new ...
2
votes
1answer
123 views

Text manipulation by calling external binaries or scripts

I want to automate certain text manipulation (essentially writing a plugin), but for easiness, I wish to minimize the use of Vim script whenever possible. This is because, indeed it is much harder to ...
2
votes
2answers
51 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 ...
2
votes
1answer
69 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\\...
2
votes
1answer
164 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\\...
2
votes
1answer
327 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 ...
2
votes
1answer
55 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 ...
2
votes
2answers
245 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 ...
2
votes
1answer
68 views

Is there any way to switch between Vim and a :! command passed to the shell, before it is finished executing?

This would make my workflow immensely easier -- I have some simple maps for executing python .py files, and sometimes it would be nice to open an interactive session after running them (for example, ...
2
votes
2answers
1k views

How to filter text matched by global command?

I have a log file full of arbitrary lines, interspersed with some lines which are a proper xml sequence, with all the tags on a single line (for each sequence). I want to simply process this so that ...
2
votes
1answer
838 views

The right shebang for Vim to parse the file from the argument?

I'm following the page where there is an example how to set-up Vim as a system interpreter for vimscript by setting the following shebang line: #!/usr/bin/vim -nNesc:let&verbose=1|let&viminfo=...
2
votes
1answer
573 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 ...
2
votes
1answer
66 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
1k 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 ...
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 ...
2
votes
1answer
586 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 ...
2
votes
1answer
1k views

Mapping key to execute shell script from vim

I would like to execute a shell script, with parameters, from vim by mapping it to F6, however the current mapping I have in my .vimrc isn't working: " Map F6 to sync project changes to dev server ...
2
votes
0answers
55 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 ...
2
votes
0answers
324 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 ...
2
votes
0answers
72 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 ...
1
vote
3answers
188 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
2answers
1k views

How do I insert the output of an external command at the cursor position?

When we execute any system command and get the output, it prints in next line. But I want it in current line, next to the cursor or in place of cursor (not at the start of the current line) Example: ...
1
vote
2answers
2k 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
2answers
149 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?
1
vote
2answers
71 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 ...
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
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 ...
1
vote
2answers
82 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'...
1
vote
1answer
375 views

Compilation window that shows errors

The way I compile now is by calling make. A batch window pops up. Instead, I want the output to be in shown directly in Vim, just like Syntastic does it. Also, the errors inside should be navigable. ...
1
vote
2answers
143 views

How do I keep folds when formatting (reindenting) the whole file?

I do quite often use this mapping: autocmd FileType cpp nnoremap <buffer> == :%!clang-format -style=file<cr>2g;zz It reindents the whole file and returns the cursor to the last edit ...
1
vote
2answers
132 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 ...
1
vote
1answer
34 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 ...
1
vote
2answers
150 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
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
vote
1answer
171 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
232 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
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
305 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 ...
1
vote
1answer
371 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 ...
1
vote
1answer
61 views

Send all writable buffers to external command?

How can I send all writable buffers to an external command? For example, :wa ! wc -l does not work (gives trailing characters error). (Also, wa will not work anyway because it does not write ...
1
vote
1answer
92 views

Output of shell commands is going beyond available screen space

When Im writing shell scripts I often want to run/check a block of code, by V highlight block then :'<,'>w !bash vim will then execute highlighted block and display output at the bottom of ...
1
vote
1answer
314 views

Compilation terminal output

When I compile and execute a c++ program in vim it outputs "command terminated" however when I compile it in geany (another ide) it outputs "segmentation fault". Is there a way to get vim to output ...
1
vote
1answer
72 views

Why doesn't :!start work with non-commands?

The real start command on MS Windows uses ShellExecute and can therefore open directories and documents in addition to commands. I therefore have a habit of using start . to open Explorer in the ...
1
vote
1answer
27 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 ...
1
vote
1answer
55 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 "...
1
vote
1answer
41 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 ...
1
vote
1answer
186 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 ...
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, ...