9/10/2023 0 Comments Vim git blame![]() Let l:bw = getbufvar(+expand(''), 'blameWindow') Let l:ow = getbufvar(+expand(''), 'origWindow') My take on this fun! GbSyncLines(is_ow2bw) " the first token of a line is taken as SHA checsum of theĬommand! -nargs=* GShow call s:GitShowFromBlame() " function runs git show on report of git blame Setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap " Function runs git blame on file in current buffer andĬommand! -nargs=* Blame call s:GitBlame() while in the lower buffer: GShow will split the lower screen and open the commit 'git show -w ' for the current line in the right hand buffer (buffer again in read only mode).command Blame will run git blame on the current file, will split the screen and put the result of 'git blame -w' into the lower buffer (buffer is put into read only mode), your cursor will be in the blame buffer (current line as in source file).I have something here, the script can be copied and added to the. To get a git blame window for the rows around the cursor position in the current buffer.ġ: How can I make the scratch buffer that opens read-only so I can close it using only q? I would like to make this change in the function so that all: Shell commands can be closed with q.Ģ: How can i get line(".") - 5 expand into current line - 5 row number? Together with the above function I would like to do: noremap b :Shell git blame -L line(".") - 5, line(".") + 5 % ' executed.'Ĭommand! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShell() Silent! execute 'nnoremap r :call ExecuteInShell('''. Silent! execute winnr execute bufwinnr('. Let command = join(map(split(a:command), 'expand(v:val)')) This function is from the vim help page and enables me to open shell commands in a scratch buffer. Having git diffn available now though, I pretty much never use git diff unless I'm on another computer.I want a minimum way of using git blame from vim (I don't want to use the whole Fugitive plugin). Meld is awesome and I use it waaaay more than git diffn, though I do use both. See also my other answer here, where I just recommend you use meld as your git difftool instead.This is intentional and designed-in behavior to act as a visual separator between the line numbers added on the left and the original git diff output on the right. Notice that the colons are NOT colored or stylized to match the surrounding text on the left and right. +++ -1,8 +1,12 1:+// Basic hello world exampleĪnd a screenshot to show the color. Line numbers for unchanged lines shown for context are shown for both the left (old file) AND the right (new file), separated by a.Line numbers for added lines are farther to the right, and show a + sign on both the far left AND to the right of the.Line numbers for deleted lines are on the left, and show a - sign on both the far left AND to the right of the : to help you see better-whether your eyes like to scan down to the right of the colon or down on the far left of the screen.Notice it shows all line numbers perfectly! Note that the red highlighted section is simply showing empty whitespace (spaces in this case) that could be deleted: +++ -1,8 +1,12 Basic hello world exampleĪnd a screenshot to show the color. Here's the output of git diff first for comparison purposes: $ git diffĭiff -git a/hello_world.c b/hello_world.c ![]() Hello_world.c: // Basic hello world example Git diffn will now work as an exact drop-in replacement for git diff! Now close and re-open your terminal, or re-source it with. mkdir -p ~/binĮcho 'export PATH="$HOME/bin:$PATH"' > ~/.bashrc Option 2 (for those who just want the 1 file): download just the one file one time. Here's another solution, expanding on Andy Talkowski's code. If you really want line numbers that you can read, you'll need to use a diffing tool that will display them for you. Unified-diff format isn't really for human consumptionĪs you can probably tell, unified-diff format doesn't make it easy to figure out line numbers (at least if you're not a machine). While the next version of the file also starts at line 11, and also includes 7 lines. The hunk header -11,7 +11,7 that the previous version of the file starts at line 11, and includes 7 lines: 11 Example diff -git a/osx/.gitconfig b/osx/.gitconfig start represents the starting line number of each version of the file, and count represents how many lines are included, starting from the start point. ![]() That information is available in the (c)hunk headers for each change in the diff though, it's just in unified-diff format: -start,count +start,count original state of the file is represented with -, and the new state is represented with + (they don't mean additions and deletions in the hunk header. There aren't currently any options to get line-numbers displayed vertically on the side with git diff. You can't get human-readable line numbers with git diff ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |