Hot answers tagged

10 votes
Accepted

See what Vim `:!` executes

When you use ! or :! Vim builds the invoking command based on whatever is specified in the various 'shell...' settings (i.e. 'shell', 'shellcmdflag', 'shellquote', to name three). On Unix systems the ...
user avatar
  • 18.4k
7 votes
Accepted

What is "!!" filter used for?

!! (and more generally the ! operator) provides vim builtin support for all the unix filters that have evolved over the ages: this includes cut, paste, sort, uniq, awk, sed, even bash. Basically a ...
user avatar
  • 21.4k
6 votes

See what Vim `:!` executes

Is there a way to see exactly what shell command is being called out? To see what exactly is run, :echo getpid() will show vim's PID, e.g. 1234, with which you can then in another terminal run: sudo ...
user avatar
  • 510
5 votes
Accepted

Filter list by another list (list subtraction)

It is a little bit faster to use a string expression than a lambda (and arguably easier to understand in this case), call filter(a, 'index(b, v:val)<0') This naive implementation is O(N^2) but is ...
user avatar
  • 12.8k
4 votes

What filters are available?

consider every program that reads stdin and writes stdout a filter. What is available is out of scope of vim. It largely depends on your OS and installation. The sort of the example in the vim-docu is ...
user avatar
  • 2,599
4 votes

See what Vim `:!` executes

An easy check is :!foo that (probably) will print something like bash: line 1: foo: command not found. Also see :h job_start() (or :h jobstart() for Neovim) and so on. To summarize: :! always uses &...
user avatar
  • 16.9k
3 votes
Accepted

Ignore the result of a filter commands on non-zero exit code in neovim

You can check the exit code of an external command spawned with ! in the v:shell_error special variable. For instance, you can use that to check the error status of the external command and then use ...
user avatar
  • 26.2k
3 votes

Filter list by another list (list subtraction)

To keep it simple, I assume all elements are different (i.e. it's "set difference"): :call filter(list1, {_, v -> index(list2, v) < 0})
user avatar
  • 16.9k
3 votes
Accepted

How can I run awk script with in vim?

When using a relative path, awk assumes the path is relative to the current directory. In the comments, you note that :pwd gives /home/user; that means you need to give either an absolute path to ...
user avatar
  • 21.4k
3 votes

Filter specific lines matching a pattern through external command

but I don't have the option of piping the output to an external command Actually you do: echo system('wc -l', execute('g/http/')) However, note that execute() prepends a newline to the resulting ...
user avatar
  • 16.9k
3 votes

What is "!!" filter used for?

A classic example for this filter is to sort the input using the Shell command sort. So vi does not have to implement its own sorting algorithm but could plugin external commands to do that. Nowadays,...
user avatar
3 votes

Filter specific lines matching a pattern through external command

I'm not aware of any builtin, compact functionality that let's you filter the output of any vim command through any external command. With a little one-time scripting, though, you could get something ...
user avatar
  • 18.4k
2 votes

How to run Vim on a Chromebook?

Just (yesterday) bought a Lenovo Duet Chromebook to replace my Android tablet. Immediately swithed on the Linux Beta option in the setting menu. Turned out the linux environment comes with Vim (not ...
user avatar
  • 21
2 votes
Accepted

How to run Vim on a Chromebook?

If you have a recent enough and powerful enough Chromebook, then you should consider Crostini, which can give you a Linux container running in a lean virtual machine in your Chromebook. If you have ...
user avatar
  • 26.2k
2 votes

Vim filter command not using line-wise selection

To apply Ex command to an arbitrary selection you can do the following: Copy selection to the end of file Select those new lines and run the command Cut the result Replace old selection with the ...
user avatar
  • 16.9k
2 votes
Accepted

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

is there another way to run an external command on the alternate screen, that doesn't involve passing it lines from the current buffer as standard input? Try to remove ^[[?1049h from 't_ti' and ^[[?...
user avatar
  • 5,517
2 votes
Accepted

How to filter lines only if the filter is successful?

I pieced together this workaround from lots of stackexchange posts and vim wiki content: " yapf integration function FormatFile() let buffer_content = join(getline(1, '$'), "\n") ...
user avatar
  • 23
1 vote
Accepted

Can a vim filter be interactive?

On MacOS and Linux, this seems to work in vim (but not neovim): :set noshelltemp Afterwards this works as hoped. :r ! echo -e 'foo\nbar\nbaz' | fzf -m
user avatar
  • 181
1 vote

Join contiguous lines of natural text and leave adjacent, non-connected lines

Imagine you have a program (naturaljoin) that does that analysis and produce the result you need. Then you can filter buffer contents using it: :%!naturaljoin Help topic :h filter might be worth ...
user avatar
  • 10.4k
1 vote

How to run Vim on a Chromebook?

It's actually possible to get Vim (7.4) on a Chromebook without using Crostini nor Crouton! You can get it from the Chrome Web Store.
user avatar
1 vote

How to run an external filter on a part of a line?

Try this: :s/\%V.*\%V./\=system('myfilter', submatch(0))[:-2]/ As an example, consider this text: one zwei three four fünf six Visually select the block containing the german numbers zwei and ...
user avatar
  • 5,517
1 vote
Accepted

Filter specific lines matching a pattern through external command

Thanks to @B Layers and @Matts answers, I've written this function which serves my purposes perfectly. I'm sharing it here for future reference, if anyone needs the same functionality. " Function to ...
user avatar
  • 59
1 vote

Filter specific lines matching a pattern through external command

You can use :%s/pattern/gn The n tells it to count the g to count every occurrence.
user avatar
  • 1,154

Only top scored, non community-wiki answers of a minimum length are eligible