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

question about shortcuts / bindings #27

Closed
aurisnoctis opened this issue Feb 11, 2015 · 10 comments
Closed

question about shortcuts / bindings #27

aurisnoctis opened this issue Feb 11, 2015 · 10 comments

Comments

@aurisnoctis
Copy link

First of all: thank you very much for this vim customization!

I like the idea of shortcuts a lot, but I am not sure how to use them. For instance I tried the option <leader>-k : Increase the priority of the current line. My leader is usually :. For instance, when I want to save a file and then exit, I type :wq. So I opened my todo.txt and typed :k, also tried :-k, but it returns E471: Argument required.

I also tried marking the whole line before applying this, but no luck.

Any help is greatly appreciated - thanks.

Update:
My key was not defined, so I added let mapleader=","to my .vimrc. Then I tried ,k and ,-k in command mode, but still no success for me.

Update 2:
I tried date<tab> now in insert mode, and it results in exactly that verbatim, without inserting the date. So maybe something is not set up correctly - like permissions. But I do get the highlighting, so the add-on is in the right folder ~/.vim.

Update 3:
Some of my other mappings from long ago were conflicting these mappings. So I temporarily moved my .vimrc, and then typed -- using the default map leader \ -- \k in command mode. Still no luck.

@stphnrdmr
Copy link
Contributor

Make sure that your cursor is on the correct line and that the line has a priority set already. Increasing/decreasing doesn't work with no priority on the line.

@freitass
Copy link
Owner

@aurisnoctis I don't think it's a good idea to use : as your <leader> key, since it's used to enter 'command-line' mode. Take a look at :h <leader> for more info. Moreover, you need to be in 'normal' mode for the commands to work properly.

@aurisnoctis
Copy link
Author

@freitass Agreed. I had never used a self-defined mapleader before, just shortcuts like :map i!mz_hr_=strftime("%Y%m%d")+ to add time stamps to my Fortran files. I looked at :h leader and now re-defined :let mapleader = "," again.

I open a todo.txt file, stay in normal mode, go to a line with priority (B), type ,-k and all that happens is the cursor going up when I hit - and once more when I hit k (as expected without special shortcuts). Obviously, I have no clue how to apply the -k command stated in the manual.

troubleshooting:

  • looked into ~/.vim/ftplugin/todo.vim, and the - in the todo.txt-vim description seems to only mean to press the leader and the following character together. Ok. Now, pressing ,k one after the other or together moves the cursor up one line, priority is unchanged.
  • typing :let mapleader yields mapleader ,, so the leader setting seems ok
  • my ~./vim directory has the following contents: README.markdown doc done.txt ferret.vim fortran.vim ftdetect ftplugin mysyntax.vim plugin syntax todo.txt
  • I had an entry nnoremap , g0ze in my .vimrc before that had worked fine. I commented it out after installing todo.txt-vim to avoid interference with the mapleader , that I defined
  • Maybe Note that the value of "mapleader" is used at the moment the mapping is defined. Changing "mapleader" after that has no effect for already defined mappings. from the vim help is related to my issues? Or other mappings?

Any help greatly appreciated.

Edit: As another test, I defined :nnoremap d dd in my .vimrc. This works fine: pressing ,d quickly one after the other deletes the current line. So the mapleader is working fine. And sorry I hadn't answered until now. Funnily enough, this was just closed while I write the draft for my post...

Edit2: I now also defined :let maplocalleader = "," to be sure as the todo.txt-vim description refers to , even though the definition in ~/.vim/ftplugin/todo.vimuses ...k :call TodoTxtPrioritizeDecrease().

@freitass
Copy link
Owner

@aurisnoctis that hyphen in the documentation is misleading, it is not included in the mapping. I will be fixing that soon.

All of the mappings were changed to use instead of because that's the recommended policy for filetype plugins (to avoid collision with mappings defined by global plugins). To set your you do let maplocalleader = ,. You can set the same key for both and . Please, see :h <localleader> for more info.

@aurisnoctis
Copy link
Author

@freitass Thank you for getting back to me.

I added Edit2 above, probably at the same time as your comment, and had defined :let maplocalleader = "," as well. I now also updated all todo.txt-vim files in my /.vim directory and saw the change in /.vim/ftplugin/todo.vim to k :call todo#txt#prioritize_decrease(). Typing ,k still only moves the cursor one line up, as if there were no mapping at all, plain vi behavior.

I suspect my vim doesn't know about the todo.txt-vim files available in /.vim. For the other files in that directory, like fortran.vim I have a special entry in my /.vimrc that says let mysyntaxfile = "~/.vim/mysyntax.vim". In that file, there is are two lines

au BufRead,BufNewFile *.f set filetype=fortran
au! Syntax fortran source ~/.vim/fortran.vim

Could this be the reason? A missing hint to my vim to actually use it instead of just copying the files into ~/.vim?

@freitass
Copy link
Owner

@aurisnoctis Check if the mapping is correct by opening a todo.txt file and checking the output of :map ,k (remember to change , with your , mine is \). The result should be:

v  \k          &@:call todo#txt#prioritize_decrease()<CR>
n  \k          &@:call todo#txt#prioritize_decrease()<CR>

Also, make sure you have the latest version of this plugin, the function TodoTxtPrioritizeDecrease() has been renamed. I strongly recommend using a plugin manager (such as Vundle) if you are not using one yet.

@aurisnoctis
Copy link
Author

I now deleted everything in my /.vim directory except for the todo.txt-vim files (current version here). I deleted everything in my /.vimrc except for the following 3 lines

:let mapleader=","
:let maplocalleader = ","
:nnoremap d dd

the cursor still just goes one line up then pressing ,k in short sequence. Trying other todo.txt-vim shortcuts, they all behave as if without todo.txt-vim. My own shortcut in ~/.vimrc (3rd line above) works, also changing it to for instance :nnoremap d iHELLO).

Re your comment above, yes, exactly, the todo.txt-vim mapping is not known to my vim, just my own definitions from ~/.vimrc:

:map ,k No mapping found
:map \k No mapping found
:map ,d n  ,d          * dd

How can I make my vim see your configuration files?

@aurisnoctis
Copy link
Author

I again added the line let mysyntaxfile = "/.vim/mysyntax.vim" to my /.vimrc file. In the file ~/.vim/mysyntax.vim, I then added the lines

au BufRead,BufNewFile todo.txt set filetype=todo
au! Syntax todo source ~/.vim/ftplugin/todo.vim

to tell my vim where to find the definitions (analog to what I had before for fortran highlighting for example).

THIS WORKS. YAY. ,k and date and a couple of other things I tested.

So is there a part of the documentation missing? Or is there a part of todo.txt-vim configuration that should have done that configuration above for me?

@freitass
Copy link
Owner

The file ~/.vim/ftdetect/todo.vim inside you user runtime directory does exactly what you did manually, which is setting the filetype "todo" for todo.txt files. Vim should source the file ~/.vim/ftplugin/todo.vim automatically for all files with filetype "todo". The only thing I can imagine is that you have an old version of vim, but I can't tell in which version the behavior I just described was introduced. One way or another, I'm glad that you figured out a way to make it work!

@aurisnoctis
Copy link
Author

@freitass My vim version self-confesses the following

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled May  4 2012 04:22:36)
Included patches: 1-429
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by buildd@
Huge version with GTK2-GNOME GUI.

Thanks for the hint - I didn't know there was a central infrastructure in vim to recognize file type. Here is the documentation for the file type detection in vim http://vimdoc.sourceforge.net/htmldoc/filetype.html. It says filetype.txt For Vim version 7.3. Last change: 2008 Jul 15 - strange that my vim is still version 7.3 even though from 2 years later ...

I am just glad it works. So it's just the same I did for Fortran highlighting, just with your specific ~/.vim/ftplugin/todo.vim file and instructions as above. 👍

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