fzf.vim
fzf.vim copied to clipboard
Run a command just after a completion
- Category
- [x] Question
- [ ] Bug
- [x] Suggestion
- OS
- [x] Linux
- [ ] macOS
- [ ] Windows
- [ ] Etc.
- Vim
- [ ] Vim
- [x] Neovim
I want to execute a command just after entering in a file. In my case, I want to go to the last cursor position after executing :Mark
.
I tried
function! Jump2()
exec ':Marks'
exec "normal g\""
endfunc
or
:Marks | norm "g\""
But it doesn't work. The second command seems to be ignored. I didn't any any triggers that runs after the completion in the source code.
Is it possible? Do you think it's a good idea? Is it the fzf.vim's job?
Being that going to the last cursor position is built in to Vim via Vim's jumplist, I don't think this is fzf.vim's job.
:h jumplist
Your workflow would be :Marks
, go to a mark, maybe do some stuff, and then CTRL-O
to return to the cursor location before you moved to the mark. This is, of course, assuming you did not jump around once you moved to the mark. But even if you did, you could continue to call CTRL-O
until you reached your previous location.
I have the same issue. Please help me. I also contribute to OpenSource and I would need help on understanding how to use CTRL-O considering that I allways use fzf to search and move between lines, files and buffers
Marks will disappear when you edit the file so I think they are not useful
https://vi.stackexchange.com/questions/22716/can-i-debug-marks-being-deleted
you should have command in fzf.vim to move between the fzf jumplist like we do with ctrl+O
Thanks a lot @junegunn
Marks do not disappear when you edit a file. If you are having that issue, then you have a problem with your configuration that is outside the scope of this particular repository.
If you are interested in using fzf
to filter the :h jumplist
, then you can see how it is done with the function that :Marks
calls, since the format of :marks
and :jumps
is nearly identical.
For example, simply editing the command from marks
to jumps
will turn :Marks
into a jumplist filter. While this is not optimal, it illustrates just how closely the two are related.
function! fzf#vim#marks(...)
redir => cout
silent jumps " silent marks
redir END
let list = split(cout, "\n")
return s:fzf('marks', {
\ 'source': extend(list[0:0], map(list[1:], 's:format_mark(v:val)')),
\ 'sink*': s:function('s:mark_sink'),
\ 'options': '+m -x --ansi --tiebreak=index --header-lines 1 --tiebreak=begin --prompt "Marks> "'}, a:000)
endfunction
Someone has also submitted a PR implementing this feature https://github.com/junegunn/fzf.vim/pull/710 if you want to include it in your build (it hasn't been approved).
TEST SCENARIO
- add a market
ma
, navigate to that marker with'a
. Delete those lines.
RESULT
- when trying to navigate to that marker with
'a
vim will give errorMarker not set
.
EXPECTED BEHAVIOUR
- you navigate to the marker line 3 or 4 next to those deleted
That isn't expected behavior. You simply have a misunderstanding of what a mark is.
A mark is tied to a specific line--not a specific line number. In other words, if I have some line 42 auto foo = bar;
, the mark is going to be associated with auto foo = bar;
and not the line number 42--and this is what we want, because we are marking a particular piece of code that may be displaced as the file changes. If I add code above this line and it changes to 58 auto foo = bar;
, it would be pointless for my mark to go to line 42.
Vim has motions to jump to specific line numbers (e.g. <line-number>G
). Or in the example provided, let's say you set some mark ma
, did some work elsewhere in the file, jumped to the mark using 'a
, deleted the marked line and 3 lines on either side, and jumped to the top of the file using gg
. Now you want to go back to the place you deleted the lines. Vim has motions for that :h g;
.
You could fairly easily roll a solution to achieve what you are seeking (the ability to alias specific line numbers), but as I said previously, that is outside the scope of this repository (and you'll likely find that you don't even need it once you have a firmer grasp of Vim).
thanks. I will try using capital marks
https://stackoverflow.com/a/9009504/7295772
" Swap global marks
" https://unix.stackexchange.com/questions/154845/reverse-global-and-local-marks-in-vi-vim
nnoremap ma mA
nnoremap `a `A
nnoremap 'a 'A
nnoremap ms ms
nnoremap `s `s
nnoremap 's 's
nnoremap md md
nnoremap `d `d
nnoremap 'd 'd
nnoremap mf mf
nnoremap `f `f
nnoremap 'f 'f