Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Use getpos() and setpos() to preserve cursor position #12

Closed
alok opened this issue Dec 29, 2016 · 11 comments
Closed

Suggestion: Use getpos() and setpos() to preserve cursor position #12

alok opened this issue Dec 29, 2016 · 11 comments

Comments

@alok
Copy link
Contributor

alok commented Dec 29, 2016

I use this function, but I think neoformat should do something like this by default

function! WrapFormat()
  let l:cursor_pos = getpos('.')
  Neoformat
  call setpos('.', l:cursor_pos)
endfunction
@sbdchd
Copy link
Owner

sbdchd commented Dec 30, 2016

Hmm, I am trying to test out your wrap function on some files, but I am not having any luck seeing the difference between it and plain Neoformat. Can you provide some example to demonstrate the before and after behavior? Thanks!

@alok
Copy link
Contributor Author

alok commented Dec 30, 2016

It turns out neoformat does do that. I used that function for markdown files, when it turns out that they were using the wrong mapping because of my shada/viminfo file remembers too much, including old mappings.

doh!

@alok alok closed this as completed Dec 31, 2016
@adamyonk
Copy link

I'm seeing Neoformat move my cursor to the top of the window on every :w with the prettier formatter. Is there a setting I need to change or something?

@sbdchd
Copy link
Owner

sbdchd commented Feb 16, 2017

Neoformat should be able to save the cursor position to the extent that is possible with vim.

winsave() is used which saves cursor position along with some other things: https://github.com/sbdchd/neoformat/blob/master/autoload/neoformat.vim#L1-L11

Does the issue occur when using js-beautify as a formatter or is it only with prettier?

@adamyonk
Copy link

Yeah, if I setup:

let g:neoformat_jsx_jsbeautify = {
  \ 'exe': 'js-beautify',
  \ }

then
:Neoformat jsbeautify
it returns
Neoformat: no change necessary with js-beautify
and puts the cursor at the top.

@sbdchd
Copy link
Owner

sbdchd commented Feb 17, 2017

Interesting. Can you provide an example file?

@adamyonk
Copy link

Sure! The file I'm editing:

import styled from "styled-components";

const Heading = styled.h1`
  color: #0f80aa;
  font-family: sans-serif;
  font-size: 50px;
`;

export default Heading;

My Neoformat settings:

let g:neoformat_enabled_javascript = ['prettier']
let g:neoformat_enabled_jsx = ['prettier']
autocmd! BufWritePre *.js Neoformat

@sbdchd
Copy link
Owner

sbdchd commented Feb 17, 2017

I have tested that file with the following setup:

prettier --version: 0.18.0
Neoformat b479ba0

And I am :Neoformat prettier is saying that there is no change necessary.

@adamyonk
Copy link

Here's a gif of what I'm seeing:
feb-17-2017 10-49-59

@sbdchd
Copy link
Owner

sbdchd commented Feb 17, 2017

Okay, I can reproduce this bug now.

Would you mind creating a fresh issue for this?

@adamyonk
Copy link

#55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants