JoshCheek / seeing_is_believing

Displays the results of every line of code in your file
1.31k stars 54 forks source link

Vim: Cursor jumps to top of the file after running commands #138

Closed ychaker closed 6 years ago

ychaker commented 6 years ago

Hey @JoshCheek, great work on this. I'm coming to you via @avdi and RubyTapas.

I'm trying to run the commands in Vim, I've used the config you posted in the wiki:

" ===== Seeing Is Believing =====
" Assumes you have a Ruby with SiB available in the PATH
" If it doesn't work, you may need to `gem install seeing_is_believing`

" Annotate every line
  nmap <leader>b :%!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk<CR>;
" Annotate marked lines
  nmap <leader>n :%.!seeing_is_believing --timeout 12 --line-length 100 --number-of-captures 300 --alignment-strategy chunk --xmpfilter-style<CR>;
" Remove annotations
  nmap <leader>c :%.!seeing_is_believing --clean<CR>;
" Mark the current line for annotation
  nmap <leader>m A # => <Esc>
" Mark the highlighted lines for annotation
  vmap <leader>m :norm A # => <Esc>

I was seeing one weird behavior, which is each time I run the command \b or \n commands the cursor would jump to the top of the file (and scroll the file too if the top was out of view).

Do you have any suggestions on how I can avoid this from happening?

JoshCheek commented 6 years ago

Honestly, I got frustrated with all the vim solutions and wound up making my own. They're here currently: https://github.com/JoshCheek/dotfiles/blob/fda95cb9bff8d3caddea51402b64be8a82afeee9/vimrc#L131-L186 but I still mostly run SiB from Atom, so I'm not sure how great they are. Also, the one that adds the hash rocket at the end of the line is pretty invasive, IMO, I should probably remove it 🤔 I should probably also update that wiki since I don't even use those keybindings anymore (they kept jumping me around the page and it was infuriating!)

ychaker commented 6 years ago

@JoshCheek those functions works great 👍

one caveat (if anyone else gets sees this): make sure your vim version is 8.0+, it doesn't work on vim 7.4 (which is what I had initially installed on my laptop).

thanks again @JoshCheek 🎉

JoshCheek commented 6 years ago

Note that I updated the vim integration in the wiki to point to what I'm doing in my vimrc. https://github.com/JoshCheek/seeing_is_believing/wiki/Editor-Integration#vim