Comments (15)
I actually think that a user would expect such behavior. The only reason I see why users wouldn't expect it is because they are already used and conditioned to this after years of using comment-plugins which move the cursor-position.
I also think making this behavior default would be more consistent with how gcc
in Comment.nvim currently behaves. gcc
also doesn't move the cursor position to the beginning of the line whereas vim-commentary does move the cursor to the beginning of the line.
It's your decision after all but I personally wouldn't be to afraid to break from old norms if the new one is better.
Counter question. Are there reasons to move the cursor? It always felt arbitrary and disruptive to me.
from comment.nvim.
Thanks, @jandamm for the explanation. Surely marks
might be the way around this. But
- Marks API neovim/neovim#15346 recently got merged, thus only available in nightly. (I'll hate doing this the VimL way)
- Currently marks disappear when doing lines comments #24. This might be because of
nvim_buf_set_lines
which might be resetting everything like marks, ext-marks. Althoughnvim_buf_set_text
might be the solution but IDK for sure.
Considering the above, I think fixing marks should be the priority. Thoughts??
from comment.nvim.
@jandamm I wrote it a little bit confusing but I didn't mean that you use marks. I like your solution. I was responding to @numToStr because he suggested to use marks internally.
from comment.nvim.
Thanks for putting up your point. I had considered restoring cursor position as I also want this behaviour. But it might be subjective and other user might not expect this. Thoughts?
from comment.nvim.
It's your decision after all but I personally wouldn't be to afraid to break from old norms if the new one is better.
Same feelings 😂. As I said earlier, I also want this behaviour. So, I'll implement this sooner or later.
Are there reasons to move the cursor? It always felt arbitrary and disruptive to me.
IDK this might be a vim thingy. I didn't added any special cursor handling as of now. And most of the mappings like gcc
gc10j
doesn't move the cursor position.
from comment.nvim.
I tried and I failed 😢 . I don't know what is happening but I am not able to get the old cursor position. So, when the associated callback with keybind gets executed I am getting the same cursor position before and after commenting. It's somewhat same as when pressing yip
, the cursor seems to move to the start of the first line.
from comment.nvim.
I guess the solution would be to store the position in a variable before commenting and than moving the cursor back to the position in the variable after commenting.
from comment.nvim.
So, when the associated callback with keybind gets executed I am getting the same cursor position before and after commenting.
You can't 🙁. Technically you can but the both values are same. I suspect this is beacuse of g@
operatore-pending mode.
from comment.nvim.
So, when the associated callback with keybind gets executed I am getting the same cursor position before and after commenting. [...] both values are the same.
What do you mean you get the same cursor position? Which both values?
So I was thinking about storing position in variable with :h getcurpos()
and moving the cursor with :h cursor()
I am not sure what could go wrong there.
from comment.nvim.
Try getting cursor position inside pre and post hooks and press gcip
. That should clear things up a bit.
from comment.nvim.
@astier This is what I was talking about, the cursor position before and after comment being the same.
2021-10-16.11-23-29.mp4
from comment.nvim.
This observation should be true.
The opfunc is called with the current selection applied. So after the cursor has changed.
Only way I'd see is to use a mark.
For example prefix i<ESC>
to set the mark and then after the opfunc jump to mark .
.
from comment.nvim.
I just checked it for myself and understand now what you mean @numToStr If at
Comment.nvim/lua/Comment/comment.lua
Line 169 in a86384d
the cursor-position is already moved before the function is called because as @jandamm said at this point the selection has already be done and the cursor moved than the position has to be stored before the selection is done.
I just tried @jandamm PR and it works for me. It solves it more or less how I imagined it. I am not sure if using marks is a good solution. Wouldn't this potentially pollute/overwrite the user-marks?
from comment.nvim.
My solution does not use marks after all. It stores the current position as buffer variable before the operator is applied.
Afterwards it moves to the position and removes the variable.
So unless some other plugin uses b:comment_pos
there should be any collision.
from comment.nvim.
I am not sure if using marks is a good solution. Wouldn't this potentially pollute/overwrite the user marks?
Yup, this is surely a concern.
@jandamm I liked your approach though. I'll keep the rest of the talking on the PR ✌🏻.
from comment.nvim.
Related Issues (20)
- `gqq` to break long lines is broken HOT 2
- Not working for .kv files
- Issue with HCL files HOT 1
- how to add a header comment? HOT 3
- [Comment.nvim] nil for .lua files
- Adding a shortcut that selects the kind of comment
- Wrong commenting on HTML files. HOT 1
- Add blockwise comment support for verilog/systemverilog
- Support templ HOT 1
- How to support context filetype?
- Uses `//` as commentstring in html HOT 4
- NOT A BUG/ISSUE [a gen qs] HOT 2
- How to just do comment or uncomment?
- Willing to accept a PR if I add a setup option "default commentstring"? HOT 2
- comment config working on arch but not on linux (arch) HOT 1
- Retain visual mode after commenting HOT 1
- [BUG] When I try to comment linewise in visual mode, unrelated or extra code gets commented HOT 5
- Adding a FOSS license HOT 2
- Not working for typescript react HOT 1
- BUG: fails silently in absence of LuaJIT HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comment.nvim.