Comments (17)
Looks promising!
from vim-simple-todo.
Okay, well. Almost there. It turned out to be a bit more complicated than I expected.
I figured the best way will be to let the user select the block he wants to sort and then do operation on it.
If the [ ] is at the beginning of each line and each task is on a separate line, this is trivial and only
requires remapping keys to :sort or :sort! ex commands.
However, if a task spans across multiple lines, and/or if the checkbox is at the end of each line, this is a bit less trivial.
I'll take another look into it! It's almost done, but it's still a bit silly.
from vim-simple-todo.
if the checkbox is at the end of each line
What do you mean? I don't see any reason to pull checkbox to the end.
from vim-simple-todo.
Well, as in:
Shopping list
Rolls: [x]
Bananas: [x]
Other stuff: [ ]
from vim-simple-todo.
@thegoodhen thank you for clarification, I never use this format before.
from vim-simple-todo.
I just thought some may want to do that. Also, if it spans across multiple lines, it rules out the option to use :sort.
Instead, it seems like it will be necessary to append everything into a buffer. Right now I am able to copy all tasks that are marked as done into a register. I can't select range yet, the last task stays on its place and they all have one character from the line after them.
from vim-simple-todo.
Hello! Believe it or not, I am working on it. :D Please, just tell me one thing. I cannot find it anywhere. How do you match following string? [] ?
I need this to be able to jump to the end of the line that is right before the line with a new task...
/$_.* matches nothing.
/[ and then k0 (as in, find it on this line, jump one line up and to the end of the line) causes problems.
I can't seem to be able to find any answer online...
from vim-simple-todo.
Did you mean match []
? Use \
to escape it, e.g. \[\]
.
from vim-simple-todo.
Nonono... I mean to match a regEx that starts with the "end of line" symbol...
/$_.* doesn't match anything...
from vim-simple-todo.
Oh, sorry, I see it now. I have written a string here and it has been misinterpreted as xml tags, thus I am causing confusion. My original text was:
<end of line><any characters>[<any character>] ?
from vim-simple-todo.
$
actually marks the end of line, e.g. there is no characters after it.
If you provide an example of text you are working on, then maybe I can help you.
from vim-simple-todo.
Hello. $ marks end of the line, but \_.
marks any character... So I assumed it would match end of the line and the new line after it... similar to \_.*$
which matches from current position across first EOL up to another EOL. (by EOL I mean end of line...)
And well... So far I've got this:
vnoremap aa <esc>'<ma'>o[ ]TGH_LINE_FOR_REMOVAL_TGH<esc>mbqaq:'a,'bg/.*\[x\]\_.*\[.\].*$/normal! v/\[<C-V><C-M>k$"Ad<CR>
This is a temp thingy. What I want from it: Once you select text which has completed and uncompleted tasks in it, it should delete all completed tasks (even if the task spans across multiple lines) and append it to the register a.
How it should work:
vnoremap - remap when in visual mode
aa - two presses of a, this is temporary
<esc> -escape-get out of visual selection mode
'< - go to the beginning of last visual selection made (this works)
ma - add mark a here. (This is needed since we will be selecting stuff later and the '< and '> registers will get changed
'> -go to the end of last visual selection made
o - create a new line under it
[ ]TGH_LINE_FOR_REMOVAL_TGH - write this text on the new line. This is a dummy line. I will be finding text that spans from [x] up to next [.], but after the last task there is no [.]. By adding this line, I am making sure the last task is correctly detected. (By basically adding a dummy task after the last one). I will delete this line then (not implemented yet).
<esc> - press escape (exit insert mode, back to normal)
mb - add mark b here. Now our text for sorting spans between marks a and b
qaq-store an empty macro in register a. This is a trick to clear register a. equivalent of :let @a=''
: -go into ex mode
'a,'b - set range for next command to be from the mark a to the mark b
g/ - with each line matching a following regular expression, do something
.*\[x\]\_.*\[.\].*$ - a regexp to match one line containing [x] up to the next line containing [ ] or [x]
normal! -the command to be ran for each line should be to press following keystrokes in normal mode:
v/ -start selecting in visual mode up to the next occurance of a following RegEx
\[-up to next [
<C-V><C-M> - weeeell... Print the "end of line symbol"... Basically this will press "enter" . I couldn't write <CR>, as that would press enter immediatelly. This is like... Press enter in the normal mode to perform search.
k-since the search has thrown us on the line with a next task, we need to move up one line now.
$ - and to the end of this line...
"Ad-and append the selection to register a
<CR>-this is the end of the ex command. Execute.
Aaaand it is buggy. When 2 tasks after one another are both checked, the second is skipped... I am not sure how to fix it. Also some odd problems occur with trailing whitespace before each line... I don't know.
from vim-simple-todo.
Okay, seems like I am close to a solution now... It's kinda ugly but should work...
from vim-simple-todo.
I never like regexps (my favorite on xkcd https://xkcd.com/1171/). A long time ago when I created this plugin I used them to quickly toggle list markers, and nothing more.
As you said, the built-in :sort
command is good for sorting single lines, but require a more complex logic for sorting multiline items. This regexp implementation:
- reuse existing registers (
a
,b
), which may rewrite important user's information - hard to understand and debug
This task require to rework core logic, e.g. detect each task item separately and then rearrange them while keeping internal state into script specific variables.
@thegoodhen how often do you sort your tasks? Looks like I'm able to sort them manually with any of existing plugins (vim-unimpaired or vim-move can rearrange lines in visual and normal modes).
from vim-simple-todo.
Yea, I am starting to dislike them as well... Unfortunately, I am not yet too good with Vimscript... Maybe Java and embedded C, but not Vimscript... I am aware of the issue with the overwritten registers, but it looked extremely daunting to implement it any other way. I finally almost got it to work. Now I am in state where it sorts the list nicely, but only when you have the word "end" on the end of each task. (That was for debug purposes, but when I tried to change it to what it's supposed to be, it died on me. It just stopped working.)
I have a script that can delete all tasks marked as done. It doesn't use user registers and it's a simple regex search/replace. I guess I'll stop trying tomorrow and give you a pull request with at least that and then I'll be done with it. :D Sorry! At least I tried, sigh.
from vim-simple-todo.
No problem, thank you anyway. I keep this issue opened as the reminder.
from vim-simple-todo.
As a reminder you can't always win against RegEx? :D
This. Is scary. But at like... 80% of cases, it kinda works.
vnoremap aa <esc>'<ma'>o[ ]TGH_LINE_FOR_REMOVAL_TGH<esc>mbqaq:'a,'bg/.*\[x\]\_.*\[.\].*$/normal! v/\[<C-V><C-M>$"Ay<CR>:'a,'bs/\zs.\{-}\[x\]\_.\{-}\n\ze.\{-}\[.\]//g<CR>:%s/\[ \]TGH_LINE_FOR_REMOVAL_TGH//g<CR>:nohlsearch<CR>'aO<esc>"ap
from vim-simple-todo.
Related Issues (14)
- Fix compatibility with auto-pairs plugin
- Selection remains after marking todo HOT 4
- Remove plain text readme
- Plugin dont remove the selected pattern after use HOT 1
- Side effect of highlighting all occurences of "[ ]" once task is marked as done HOT 6
- No option to turn the current line into a task HOT 2
- Mark all selected lines as TODO items or if it is, mark as DONE HOT 4
- Missing adding a todo in a list item at the start of the line. HOT 6
- Simplify adding new todo's above and below a task
- spacebar as Leader key conflicts with plugin mappings HOT 3
- open todo in small vertical split and global todo list HOT 1
- GFM compatibility
- Support Visual mode
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 vim-simple-todo.