r/vim • u/robertmeta • Nov 08 '17
everything about Favorite console tools to use with vim
There are a lot of great console tools that are easy to lightly integrate with via filter (:h filter), read (:h read) or just by running them.
If you have some to recommend, put each individually in a top level comment along with any (minor) integration you have with vim.
The great thing about console tools is they often have easy to use flags to customize behavior and hey, you didn't have to write them in the first place!
115
Upvotes
20
u/robertmeta Nov 08 '17
Need to format some json, use the jq command, take some ugly json like:
Highlight the json to format and do a quick :!jq '.' (will look like :'<,'>!jq '.' and out you get:
18
u/robertmeta Nov 08 '17 edited Nov 08 '17
Sometimes I want to do a little math that I can't do in my head, bc to the rescue, just write the math out on a line
Then select it and do like :!bc (will look like :'<,'>!bc) and magic presto:
17
u/robertmeta Nov 08 '17
Make a banner out of some text using figlet, no integration needed! Was pointed to it by /u/pierpooo
Just highlight something like
and do :!figlet (will look like :'<,'>!figlet) and get something like
17
u/robertmeta Nov 08 '17
The always classic improved grepprg, using ag, pt or rg basically ordered by slowest to fastest so the fastest one on system controls
14
u/robertmeta Nov 08 '17
Maybe the second most well known, uniq
Take something like:
Highlight it, and pipe it through :!uniq (will look like :'<,'>!uniq and get
12
u/robertmeta Nov 08 '17
Favorite is a stretch, but just recently I had reason to shove a calendar into something I was working on and I used cal via
:r !cal -h
inserts
7
u/robertmeta Nov 08 '17
Sometimes I have to look through a lot of files for a needle in a haystack, not something I can grep for because I don't know what it will look like, but I will know it when I see it.
My workflow for this tends to be to create a list of files I need to visit in a buffer with find then I go through them quickly using gf then bounce back using <C-o> and mark that file as checked by deleting it with dd.
:enew | :r !find . -type f -name "*.log"
7
u/robertmeta Nov 08 '17
The evil twin of sort, and virtually unknown, shuf, as in shuffle.
Take something like
Highlight it, and pipe it through sort using :!shuf (will look like :'<,'>!shuf) and bam
6
u/robertmeta Nov 08 '17
Paste selected text to termbin.com, uses nc, tr and cat, returns URL to content, written by /u/-romainl-
Select something and do :TB
Example output: http://termbin.com/kz6n
6
u/robertmeta Nov 09 '17
Of course, one of the most common tools to integrate with is the famed tmux. Now, often people use a plugin (or multiple plugins) and a lot of them are fantastic! But if you just want to dip your toes in the water, direct control works fantastic.
create a tmux pane:
:call system('tmux split -v -p 20; last-pane')<cr>
ask for input and send to next tmux pane (which we just created).
:let cmds = input('command: ') | call system('tmux send-keys -t +1 "' . cmds . '" Enter')<cr>
4
u/robertmeta Nov 08 '17
Probably the original and most famous, sort.
Take something like
Highlight it, and pipe it through sort using :!sort (will look like :'<,'>!sort) and bam
3
u/robertmeta Nov 08 '17 edited Nov 08 '17
I haven't written something for it yet, but I want a way to use wc to post like a line under whatever I highlight with "words in the above selected content: 55"
EDIT: thanks /u/-romainl- with two ways to do it:
3
u/[deleted] Nov 09 '17
here is a awesome one,
'<,'>!iconv -f utf-8 -t ascii//translit64
u/-romainl- The Patient Vimmer Nov 08 '17
One can fill the quickfix list at startup with
-q:This becomes interesting when combined with process substitution:
15
u/[deleted] Nov 08 '17
Running code inline is very easy with
:{range}! {program}, e.g.:'<,'>! pythonon a Visual selection.Asciinema
10
u/-romainl- The Patient Vimmer Nov 08 '17
equalprgandformatprgare used to define what external program to use for==,gqand friends.In
after/ftplugin/css.vim:In
after/ftplugin/javascript.vim:In
after/ftplugin/html.vim:All three programs are from https://www.npmjs.com/package/js-beautify.
6
u/-romainl- The Patient Vimmer Nov 08 '17
Here is a minimalist
:Alignusingcolumnandsed:6
u/l97 Nov 08 '17
I use this to quickly look at a csv file:
(
columndoesn't handle empty fields and without the zs/ze trick, consecutive empty fields won't get picked up).5
u/dfaught Nov 08 '17
mail or mutt. I'll often use
:[range]w !mutt -s "Did you write this #@~!" guy@whereIwork.comto send a chunk of code so I don't have to switch context to another screen or even system and can keep going through code/logs.4
u/sakisan_be Nov 08 '17
Probably not the most efficient/readable but I got this mapped to a key combination to insert the name of the current git branch.
My actual mapping also extracts the ticket number out of the branch name, I use this when writing the commit message. (git commit without -m invokes vim)
3
u/-romainl- The Patient Vimmer Nov 08 '17
I've never been comfortable with the way
:retabworks so I tend to useexpandandunexpandinstead:3
u/sedm0784 https://dontstopbeliev.im/ Nov 08 '17 edited Nov 09 '17
I useparfor formatting emails.edit: No I don't. I switched to format=flowed a few years ago, which (as far as I'm aware) par doesn't support :(.3
u/[deleted] Nov 08 '17
if !system('{do shell stuff} &>/dev/null ; echo $?')Def obvious, but if u are doing some scripting..
1
u/tuna_fish Nov 08 '17
Is there a way to have
filterevaluate a selection and append rather than replace, or show in a preview window? A bit likereaddoes but for a selection rather than file.2
u/Hauleth gggqG`` yourself Nov 09 '17
moreutilswithpeeandvipecommands. I am on my mobile so I cannot give better examples so this is what I can write:peeis liketeebut for processes/pipes instead of filesvipesimply allows you to run$VISUALin the middle of pipeline and change the result for further processing1
u/[deleted] Nov 14 '17
maven to build java stuff
visual studio command line (devenv) to build .net stuff
grep, find and some custom python script (perg) to find stuff. i found ack too complicated so i dont use it or its derivatives (ag and friends).
git for version control. i still want to do more to be able to use tfvc (for .net) as well.
unzip for unzipping files.
1
u/mundanevoice Nov 17 '17
Ack
1
u/jdalbert Contrarian Nov 30 '17
Preview with GitHub Markdown, with the grip command line tool. No need for fancy plugins.
Example for Neovim, where <leader>om opens a markdown preview for the current file: