bash-tricks | Sweet Bash Tricks | Awesome List library
kandi X-RAY | bash-tricks Summary
kandi X-RAY | bash-tricks Summary
Sweet Bash Tricks
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of bash-tricks
bash-tricks Key Features
bash-tricks Examples and Code Snippets
Community Discussions
Trending Discussions on bash-tricks
QUESTION
At the end of this bash tutorial video link ,Spencer Krum shows a neat hack: how to open a file in vim at the line number where an immediately preceding 'git grep -n' search string was located. It seemed neat, but his code does not work as described on two different linux boxes I tried it with. It just always opens a blank file. original code here
My steps:
First, I made sure to have git initialized and files inside the directory to grep for. For example, I had a somefile.txt with three lines of words:
- its
- a
- mystery
Then I ran: git init;git add .; git commit
Then, modify your .bashrc file to redefine vim as shown below. Make sure to source the .bashrc file when complete: source ~/.bashrc
Finally, run the git grep -n command with a search term you know is in a file in your git directory that is your current working directory. Finally, run vim. It should open your file with the cursor at the search term line. But it doesn't: git grep -n mystery;vim
ANSWER
Answered 2020-Dec-24 at 04:28Ok, I finally understood what this is about.
His code was never really meant to somehow access the output of the git grep
command.
Instead, it's a realization that after a git grep
you're likely to want to open one of the results.
But, in his workflow, he still relies on copy & paste of the git grep
results into the Vim command-line.
The only difference is that, right after a git grep
, you can pass Vim a filename with a line number separated by :
rather than having to pass two separate arguments.
In his example, the result of git grep
started with:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install bash-tricks
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page