Skip to content

Commit

Permalink
feat: customize mappings for tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarcosp authored and fdaciuk committed Nov 20, 2023
1 parent dca2bba commit bc8b19f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions customization/how-it-works.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ return {
hooks = {},
mappings = {
leader = " ",
tabs = nil,
custom = {},
by_mode = {
n = {},
Expand Down
2 changes: 1 addition & 1 deletion installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: 'Learn how to get started with BetterVim.'
- Brew
- unzip

## For Linux (Ubuntu, Arch and WSL2)
## For Linux (Ubuntu, Arch, Fedora and WSL2)
- Nodejs
- Git
- unzip
Expand Down
28 changes: 28 additions & 0 deletions mappings/custom-mappings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ You can use `i` (for `insert` mode), `n` (for `normal` mode), `v` (for `visual`
and `select` modes) or `x` (for only `visual` mode). The options are the same as
used in `mappings.custom`.

### Creating mappings for tabs

You can create custom mappings to change tabs. The default mapping is `alt/option` + **tab number**.
To customize it, just pass a function to the `tabs` key inside `mappings` table.
The function receives the `tab` number. That way you just concatenate the tab number with your custom keys:

``` lua better-vim.lua
return {
mappings = {
tabs = function(tab)
return "<leader>h" .. tab
end,
}
}
```

The example above will create the mappings:

```
<leader>h1 -> first tab
<leader>h2 -> second tab
...
<leader>h20 -> twentyth tab
```

Now, you can use `<leader>h1` to go to tab 1, instead of `alt` + `1`.

### Creating mappings with lua

To create custom mappings using `lua` you can use the `hooks.after_setup` entry in `better-vim.lua` file, following this [tutorial](https://neovim.io/doc/user/lua-guide.html#lua-guide-mappings)
from the Neovim official documentation.
5 changes: 3 additions & 2 deletions mappings/general.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ Better Vim comes with lots of slick defaults. Here is a complete list of common

## Tabs

- `alt/option` + tab number (e.g `1`) : Navigate to a specific
tab
- `alt/option` + tab number (e.g `1`) : Navigate to a specific tab

<Warning>
If you're using iTerm2 the mapping above will not work due some limitations with the iTerm2 built in mappings.
</Warning>

To customize mappings for tabs, check the [custom mappings](/mappings/custom-mappings#creating-mappings-for-tabs) documentation page.

0 comments on commit bc8b19f

Please sign in to comment.