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

f<key> doesn't jump to <key> if there is a mapping for <key> #152

Closed
gerardroche opened this issue Apr 6, 2017 · 8 comments
Closed

f<key> doesn't jump to <key> if there is a mapping for <key> #152

gerardroche opened this issue Apr 6, 2017 · 8 comments
Milestone

Comments

@gerardroche
Copy link
Contributor

Issue by tom-kuca
Saturday May 02, 2015 at 12:19 GMT
Originally opened as guillermooo/Vintageous#948


Mapping a <key> to a command in normal mode breaks the functionality of f<key> (and also t<key>, F<key>,, T<key>,). I expect that f<key> jumps to the next <key> character on the line, without invoking the command.

Example

I want to open a command palette when I press a , in the normal mode, but f, should jump to the next comma on the line without opening the pallete. I have just switched for sublime text 2 (Vintage), when the following mapping works as expected:

{ "keys": [","], "command": "show_overlay", "args": {"overlay": "command_palette"} }

I have tried to fix it by adding a proper context. I have searched for them in the vi/contexts.py without success. The relevant contexts, like vi_state_expecting_user_input, were removed. But in my opinion, it should work even without any context, I can't imagine the situation when I want to invoking anything in the middle of a motion command. But I admit my imagination can be limited.

  • Sublime Text 3, Build 3083
  • Vintageous - both current build and the version installed by Package manager

I guess that the bug (if it's really a bug) was introduced in a8809e1.

@gerardroche
Copy link
Contributor Author

Comment by jwkicklighter
Thursday Aug 11, 2016 at 19:03 GMT


Over a year later and I'm still having this issue as well.

@gerardroche
Copy link
Contributor Author

gerardroche commented Oct 9, 2017

@tom-kuca @jwkicklighter this will be fixed in the next version of NeoVintageous (1.4.0). In the meantime available from the develop branch: https://github.com/NeoVintageous/NeoVintageous/tree/develop. In case you don't know what NeoVintageous is: it is a fork of the discontinued Vintageous plugin. I show some examples of how to get it working:

Instead of defining the keymap as regular ST keybinding, you use the .vintageousrc file to map keys to commands.

Here's the working documentation for the develop branch:

The .vintageousrc file

A feature comparative to the .vimrc file.

The file is located at Packages/User/.vintageousrc and is read during startup. It can be opened for editing via the Command Palette: NeoVintageous: Open My .vintageousrc File. It can be reloaded too: NeoVintageous: Reload My .vintageousrc File.

let mapleader=, noremap, nnoremap, onoremap, vnoremap, map, nmap, omap, and vmap are all supported in basic use-cases. Note that map, nmap, omap, vmap work the same as their *remap variants, this is a known issue.

Mapping to basic ex commands is supported in the form :excommand<CR>.

To map to a Sublime Text command, the command must start an uppercase letter, to avoid confusion with builtin ex commands e.g. :YourCommand<CR>. The command is converted to snake case.

This is easiest to understand with some examples:

" The character " (the double quote mark) starts a comment

let mapleader=,

" Enter command line mode.
nnoremap <space> :

" Toggle the side bar.
nnoremap <leader>d :ToggleSideBar<CR>

" " Make j and k work file linewise instead of screen linewise.
" nnoremap j gj
" nnoremap k gk

" Scroll viewport faster.
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>

" Easy buffer navigation.
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" Select entire buffer
nnoremap <leader>vaa ggvGg_
nnoremap <leader>Vaa ggVG

" Test
" https://github.com/gerardroche/sublime-test
" https://github.com/gerardroche/sublime-phpunit
nnoremap <leader>t :TestNearest<CR>
nnoremap <leader>T :TestFile<CR>
nnoremap <leader>a :TestSuite<CR>
nnoremap <leader>l :TestLast<CR>
nnoremap <leader>g :TestVisit<CR>

There is current;y a limitation in that the commands you map to can't accept arguments so to map to the command to open the Command Palette you need to create a custom command. As I hope you can see, the command is just a proxy to the show_overlay command:

class ShowCommandPaletteCommand(WindowCommand):
    def run(self):
        self.window.run_command('show_overlay', {'overlay': 'command_palette'})

Now you can map that command to any key in your .vintageousrc file, for example to map it to your <leader> followed by cp:

nnoremap <leader>cp :ShowCommandPallette<CR>

The default leader is \. Most people set the leader to ,, but if you leave the leader as the default then you can map , to open the command pallete:

nnoremap , :ShowCommandPallette<CR>

Make sure to remove any existing ST keymaps using the comma, otherwise they will cause issues.

1.4.0 should be released soon enough. Hope you enjoy,

@gerardroche gerardroche added this to the 1.4.0 milestone Oct 9, 2017
@tom-kuca
Copy link
Contributor

tom-kuca commented Oct 9, 2017

It works, awesome! About a month ago, I tried a few different plugins just to found out that all of them suffers from this bug, I'm glad things has changed.

Just a note, the command name in mapping should match the definition. The mapping should be

nnoremap <leader>cp :ShowCommandPallette<CR>

@gerardroche
Copy link
Contributor Author

1.4.0 has been released. It took a little longer to get the release out the door. See the forum post on latest release: NeoVintageous 1.4.0 released zap KAPOW.

@dvcrn
Copy link

dvcrn commented Aug 29, 2019

Is it possible to get this working without using .vintageourc? Such as having a custom ST3 context when NeoVintageous is in a ongoing motion?

@gerardroche
Copy link
Contributor Author

@dvcm No that won't be possible because if you use a st context then Sublime captures the key and NeoVintageous doesn't know that the key was pressed. Out of interest what's the reason you can't use the rc file?

@dvcrn
Copy link

dvcrn commented Sep 3, 2019

Thanks for the explanation!

Just fragmentation. It's nicer and easier to maintain to have everything in one file, not in multiple split up

@timfjord
Copy link

I think this problem is still there, at least partly.

For example, when you do

nnoremap t<C-n> :SomeSublimeCommand<CR>

the default vim t<key> thing doesn't work anymore but t<C-n> works

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

No branches or pull requests

4 participants