6 ms·
I love this, I've been iterating on workflows like this for something like a decade now. Over time I've tried to peel back as many of my custom layers as possib
by robenkleene 1y ago
I love this, I've been iterating on workflows like this for something like a decade now. Over time I've tried to peel back as many of my custom layers as possible, because all of those layers have a maintenance cost.
Stock Vim (without `tmux`) can actually do most of what's shared in this post with `rg --vimgrep restore_tool | vim -c cb -` (`vim -c cb -` is my favorite feature in Vim; I find it strange that it's so rarely used or talked about).
(Since re-running the `rg` search can be undesirable, and I often like to analyze results in a terminal before opening them in Vim. I use a custom `tmux` command to copy the output of the last command [using this trick that involves adding a Unicode character to your prompt https://ianthehenry.com/posts/tmux-copy-last-command/ https://ianthehenry.com/posts/tmux-copy-last-command/], then I send that into Vim with e.g., `tmux saveb - | vim -c cb -`.)
- radlad 1y ago> (`vim -c cb -` is my favorite feature in Vim; I find it strange that it's so rarely used or talked about). Care to explain what it does? Trying `ls | vim -` and `ls | vim -c cb -` I don't immediately see a difference.
- robenkleene 1y ago`cb[uffer]` processes the current buffer as a compile buffer, which will find `grep` format matching lines (i.e., at a minimum starting with `<path>:<line-number>:<column-number>`) and populate the quickfix list with them, and jump to the first match. E.g., your example doesn't do anything because `ls` doesn't output `grep` format lines. So try piping the output of `grep` (you'll need flags for the line number and column number with `grep`, hence the `--vimgrep` flag above) matching the above format (or you could try `ls | sed 's/$/:0:0/' | vim -c cb -`, which will hack `ls` output to grep, and is occasionally useful). (Note that the above hints at another useful tip, `grep` parsing is only part of what `cb[uffer]` does, it can also parse compile output, e.g., something like `gcc foo.c | vim -c cb -` will jump to the first compile error in your program and put the rest of the errors in the quickfix list).
- WorldMaker 1y agoYou get similar buffer behavior if you use :make inside Vim and Vim as your build terminal. Despite being named :make it isn't hardcoded to just make as build tool (there's a bunch of out-of-the box settings you can pick with :compiler or you can update individual settings like makeprg). Similar behavior with :grep inside Vim which you can change your grepprg to rg if you like. I've got a feeling the `| vim -c cd -` isn't as commonly known because the Vim-initiated versions are somewhat more commonly known. It's handy to know that vim can do it in both "directions" (initiated from the external shell / initiated to the internal shell support).
- msgodel 1y agoTen years ago I threw out my massive multi-file, multi-package vim config and have been slowly building up a much simpler vimrc about 1-2 lines a year. I completely agree, defaults in old software are almost always there for a reason and you should try to understand that before changing them.
- codyb 1y agoI also find creating my own little shortcuts to be super satisfying and of course very transferable since they work out of the box. ```some examples " Quick access to commonly edited config files (and a directory for my Shell scripts!) map <leader>v :e ~/.vimrc<cr> map <leader>V :source ~/.vimrc<cr> map <leader>w :e ~/Workspace/myCo/tmuxp-session.yaml<cr> map <leader>W :e ~/.tmux.conf<cr> map <leader>z :e ~/Shell<cr> " Super simple in editor note setup, amazing map <leader>x :vs<cr>:e ~/Documents/notepad.txt<cr> map <leader>X :vs<cr>:e ~/Documents/notes<cr> " Quick terminal pane map <leader>t :vs<cr><c-w>l:term<cr><c-w>j:q<cr> " Pull file path into clipboard nmap <leader>b :let @+ = expand("%")<cr> " Pull current line into clipboard nmap <leader>B "*yy ``` Quick disposable terminals, tons of short cuts to get me into the config files that make it all happen (vimrc, zshrc, tmux.conf, a tmuxp session file) and to reload them, and super quick access to a well organized directory of notes are all huge boons during my workday.
- kannanvijayan 1y agoI haven't had to in a while as I've lapsed into IDE usage as of late, but my vimrc is something I committed to memory a long time ago. set tabstop=4 set shiftwidth=4 set expandtab set showmatch set nohlsearch set background=dark syntax on Typing that config into a file is emotionally associated with a system feeling "ready" for me. "ah, now I can _do_ things".
- deathanatos 1y ago… why `memory commit` what you can `git commit` and then just `git clone`. (I keep most of my dotfiles in a repository called "dotfiles".) I get the emotional value/desire for a minimalistic .vimrc, but I also need the usefulness, and that necessitates, e.g., pulling in some plugins. E.g., lang-servers are just so valuable for immediate feedback in the editor. Over time, someone of my vimrc has been pruned away just by development that has happened in/on vim itself, which is always lovely to see.
- magarnicle 1y agoIs this the same/similar to 'vim -q <(ripgrep --vimgrep restore_tool)'?
- robenkleene 1y agoSimilar enough, minor semantic differences (e.g., I don't think `-q` creates a buffer containing the matches)
- anticodon 1y agoI use fish and neovim, thanks to the thread, created the following alias: nvim -q (rg --vimgrep needle --color=never | psub) -c copen
- jez 1y agoThis is cool, I learned about `:cb` today (populate quickfix from current buffer) I find that if I’m already piping into a buffer, I just leave it as a buffer. Vim’s gf and gf keybindings let me jump to the filename under the cursor, and it being a buffer makes it easier for me to edit (reorganize, group, further filter, etc). I do think people undervalue the quickfix buffer though!
- lynx97 1y ago"rg --vimgrep restore_tool | vim -c cb -" looks like I want to use it. However, it doesn't work for me. vim says it had errors while processing, and says I haven't saved the buffer. I get the rg result displayed, but how do I navigate to a place?
- covoeus 1y agoUse `cb!` instead of `cb`: rg --vimgrep restore_tool | vim -c cb! - You might also wanna open the quickfix list by default: rg --vimgrep restore_tool | vim -c cb! -c copen - You can learn more about how to navigate it using `:h quickfix`.
- palata 1y agoI had never heard of the quickfix list! Thanks a lot!
- _sharp 1y agoThis is amazing! Thank you!! The quickfix window is so small, so I added the "-c only" option to make it the only window that first pops up. Then made it a function so it's easier to call: ``` vgrep() { rg --vimgrep "$1" | vim -c cb! -c copen -c only - } ``` $> vgrep "restore_tool"
- sam_lowry_ 1y agoI tried searching how to open the quickfix window in a vertical split, but found nothing. Any ideas?
- sam_lowry_ 1y agogot it find "$1" -name "$2" | vim -c cb! -c "vert 40copen" - 40 means open at 40 column.
- heavyset_go 1y agoCan someone sell vim to me? I can't help but see it as the tiling window manager of text editors. Even with plugins it's less featureful than Kate or Jetbrains IDEs. And the last time I really gave it a go, it was slow, which is surprising for a terminal text editor. If I need to edit text via the terminal, micro has mouse support and keybindings that match what you'd expect in any OS. I don't like the idea of thinking people who use vim are insane, it obviously has value and people who use it have good reasons for using it, but I can't see it as more than a niche nerd thing a la tiling window managers.
- skydhash 1y agoVim has it’s advantages: - Fast and precise navigation (jumping to files and jumping to some point in the file) - Fast editing command (there’s no need to select first, and when you need to selection is fast due to the above) - Easy extensibility (either custom commands which you can bind to keys, or hooking some logic to editor’s event) - Integration with external tooling (using the text as input, collecting the output, intepret the output to find location to jump to) All of these are first citizen in Vim, whereas in some editors, it can only be done with plugins.
- agarsev 1y agoI use both (neovim instead of vim, i3 as wm) and you got me thinking. I think the point of both is actually not having to use the mouse. But the mouse is not the problem per se, probably is the spatial/visual interaction paradigm. I don't care where the window exactly goes, I just want it right/on top/minimized. I don't want to search visually for a button that does what I want, I know what I want, I can just "tell" the computer. It's not about keybindings as shortcuts to do something, it's talking to the computer via keyboard using my language center without the intermediary of the gesture/spatial metaphor. Maybe? I just thought of this sorry.
- vladxyz 1y agoIt's this. I make the analogy to playing a game with a controller. At some point you stop thinking what combination of physical button presses and holds you need to have your character go from a running start to a crouch-jump, you just think in terms of goals for you want your character to accomplish. vim motions put you in the same sort of connection with the text you're editing.
- lenkite 1y agoIsn't `rg --vimgrep restore_tool | vim -q -` better though ? -q [errorfile] QuickFix mode. The file with the name [errorfile] is read and the first error is displayed. See |quickfix|. If [errorfile] is not given, the 'errorfile' option is used for the file name. See 'errorfile' for the default value. If you wish to automatically also open the quickfix list rg --vimgrep restore_tool | vim -q - -c 'copen'