├── .gitignore ├── LICENSE ├── README.md ├── autoload └── leaderMapper.vim ├── doc └── vim-leader-mapper.txt ├── plugin └── leaderMapper.vim └── syntax └── leaderMapper.vim /.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | log.txt 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Damien Pretet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-leader-mapper 2 | 3 | ## Introduction 4 | 5 | Vim-Leader-Mapper is a plugin to create leader key mapping and a visual 6 | menu to display them. It's basically a copy of Spacemacs interactive menu, 7 | relying on leader key to toggle it. 8 | 9 | - Easy to use: the user can simply add his own commands with few setup and map 10 | them to leader key. 11 | - Configurable: the user can associate any command (internal or external command). 12 | - Fast: the plugin is very small, written in pure vimL. 13 | 14 | It's also inspired from 15 | [vim-leader-guide](https://github.com/hecal3/vim-leader-guide) but it's simpler 16 | and use floating window to display leader menu. 17 | 18 | [Vim-which-key](https://github.com/liuchengxu/vim-which-key) offers similar 19 | features. 20 | 21 | ## Installation 22 | 23 | Use [Vim-Plug](https://github.com/junegunn/vim-plug) or any other plugin 24 | manager to install it. 25 | 26 | ```vim 27 | Plug 'dpretet/vim-leader-mapper' 28 | ``` 29 | 30 | ## Configuration 31 | 32 | Follows a configuration example, binding regular Vim commands and FZF calls: 33 | 34 | ```vim 35 | 36 | " Define the menu content with a Vim dictionary 37 | let g:leaderMenu = {'name': "", 38 | \'f': [":Files", "FZF file search"], 39 | \'b': [":Buffers", "FZF buffer search"], 40 | \'s': [":BLines", "FZF text search into current buffer"], 41 | \'S': [":Lines", "FZF text search across loaded buffers"], 42 | \'g': [":BCommits", "FZF git commits of the current buffer"], 43 | \'G': [":Commits", "FZF git commits of the repository"], 44 | \'v': [':vsplit', 'Split buffer vertically'], 45 | \'h': [':split', 'Split buffer horizontally'], 46 | \'d': [':bd', 'Close buffer'], 47 | \'r': [':so $MYVIMRC', 'Reload vimrc without restarting Vim'], 48 | \'l': [':ls', 'List opened buffers'], 49 | \'t': [':Tags', 'FZF tag search'], 50 | \'o': [':normal gf', 'Open file under cursor'], 51 | \} 52 | ``` 53 | 54 | Finally to bind leader key to space and toggle the menu on each space pressure: 55 | 56 | ```vim 57 | " Define leader key to space and call vim-leader-mapper 58 | nnoremap 59 | let mapleader = "\" 60 | nnoremap :LeaderMapper "" 61 | vnoremap :LeaderMapper "" 62 | ``` 63 | 64 | One could want to specify the position of the window. This can be done with two 65 | parameters. 66 | 67 | To define the vertical placement of the window. Can be `top`, `bottom` or 68 | `center` (default is `center`): 69 | 70 | ```vim 71 | let g:leaderMapperPos = "center" 72 | ``` 73 | 74 | To define the window's width, in percentage of the Vim window (default is 75 | `70%`): 76 | 77 | ```vim 78 | let g:leaderMapperWidth = 70 79 | ``` 80 | 81 | 82 | It's also possible to add submenu binded with a key. Here is an example: 83 | 84 | ```vim 85 | 86 | " Define the menu dedicated to FZF 87 | let fzfMenu = {'name': "FZF Menu", 88 | \'f': [":Files", "FZF file search"], 89 | \'b': [":Buffers", "FZF buffer search"], 90 | \'s': [":BLines", "FZF text search into current buffer"], 91 | \'S': [":Lines", "FZF text search across loaded buffers"], 92 | \'g': [":BCommits", "FZF git commits of the current buffer"], 93 | \'G': [":Commits", "FZF git commits of the repository"], 94 | \} 95 | 96 | " Define the menu content including the above menu 97 | let g:leaderMenu = {'name': "Global Menu", 98 | \'f': [fzfMenu, "FZF menu"], 99 | \'v': [':vsplit', 'Split buffer vertically'], 100 | \'h': [':split', 'Split buffer horizontally'], 101 | \'d': [':bd', 'Close buffer'], 102 | \'r': [':so $MYVIMRC', 'Reload vimrc without restarting Vim'], 103 | \'l': [':ls', 'List opened buffers'], 104 | \'t': [':Tags', 'FZF tag search'], 105 | \'o': [':normal gf', 'Open file under cursor'], 106 | \} 107 | ``` 108 | 109 | Pressing 'f' key will open the dedicated menu to FZF. 110 | 111 | In case your function/command binded needs to access the lines range of a 112 | visual selection, vim-leader-mapper setup two variables: `leaderMapperLineStart` 113 | and `leaderMapperLineEnd`. These variables are setup to line numbers as long the 114 | plugin is executed. When closing, it will setup them to `-1`. 115 | 116 | ## License 117 | 118 | This plugin is under MIT license. Do whatever you want with it, and don't 119 | hesitate to fork it and contribute! 120 | -------------------------------------------------------------------------------- /autoload/leaderMapper.vim: -------------------------------------------------------------------------------- 1 | "--------------------------------------------------------------- 2 | " Plugin: https://github.com/dpretet/vim-leader-mapper 3 | " Description: A plugin to create a leader key menu 4 | " Maintainer: Damien Pretet https://github.com/dpretet 5 | "--------------------------------------------------------------- 6 | 7 | " Save compatible mode 8 | let s:save_cpo = &cpo 9 | " Reset compatible mode to default value 10 | set cpo&vim 11 | 12 | " Startup function to call the plugin from user land 13 | function! leaderMapper#start(...) 14 | 15 | if g:leaderMapperDebug 16 | echom "DEBUG: vim-leader-mapper - Start" 17 | endif 18 | 19 | if (a:0 == 2) 20 | if g:leaderMapperDebug 21 | echom " Line start: ".a:1 22 | echom " Line end: ".a:2 23 | endif 24 | let g:leaderMapperLineStart = a:1 25 | let g:leaderMapperLineEnd = a:2 26 | endif 27 | 28 | call s:LoadMenu(g:leaderMenu) 29 | 30 | " Initialize the start & end variables to avoid bad behavior 31 | " of commands/functions on next call 32 | let g:leaderMapperLineStart = -1 33 | let g:leaderMapperLineEnd = -1 34 | 35 | 36 | endfunction 37 | 38 | 39 | " Load menu, meaning create the buffer, display the window 40 | " and populate the content with leaderMenu configuration. Then 41 | " wiat for the user choice to operate 42 | function! s:LoadMenu(leaderMenu) 43 | 44 | " Create the string menu to fill the buffer to display 45 | call s:FillMenu(a:leaderMenu) 46 | " Open the window menu 47 | call s:OpenMenu() 48 | " Wait user actions 49 | call s:WaitUserAction(a:leaderMenu) 50 | 51 | endfunction 52 | 53 | 54 | " Open floating window where menu is displayed. Neovim only 55 | function! s:OpenMenu() 56 | 57 | if g:leaderMapperPos != "center" && g:leaderMapperPos != "top" && g:leaderMapperPos != "bottom" 58 | echo "WARNING: vim-leader-mapper plugin - g:leaderMapperPos is not correct (can be top/bottom/center)" 59 | let g:leaderMapperPos = "center" 60 | endif 61 | 62 | if g:leaderMapperDebug 63 | echom "DEBUG: vim-leader-mapper - open window" 64 | endif 65 | 66 | " From menu dimension compute the window size & placement 67 | let height = len(s:leaderMenu) 68 | 69 | " Handles the window position 70 | if g:leaderMapperPos == "top" 71 | let row = 2 " 2 to put the window slightly below the window's top 72 | elseif g:leaderMapperPos == "bottom" 73 | let row = &lines - height - 4 " -4 to avoid status line overlap 74 | else 75 | let row = (&lines - height) / 2 76 | endif 77 | 78 | " Use row 3 because 0 is the title, 1 is a blank line 79 | " -3 to put window limit closed to border 80 | let width = len(s:leaderMenu[3]) - 3 81 | let col = (&columns - width) / 2 82 | 83 | if has("nvim") 84 | 85 | " Set the position, size, ... of the floating window. 86 | let opts = { 87 | \ 'relative': 'editor', 88 | \ 'row': row, 89 | \ 'col': col, 90 | \ 'width': width, 91 | \ 'height': height 92 | \ } 93 | 94 | " Open floating windows to display our menu 95 | let s:win = nvim_open_win(s:menuBuffer, v:true, opts) 96 | " Set floating window highlighting 97 | call setwinvar(s:win, '&winhl', 'Normal:Normal') 98 | 99 | setlocal colorcolumn= 100 | setlocal buftype=nofile 101 | setlocal nobuflisted 102 | setlocal bufhidden=hide 103 | setlocal nonumber 104 | setlocal norelativenumber 105 | setlocal signcolumn=no 106 | setlocal foldcolumn=0 107 | 108 | else 109 | let opts = { 110 | \ 'border': [0,0,0,0], 111 | \ 'wrap': v:true, 112 | \ } 113 | let s:win = popup_create(s:leaderMenu, opts) 114 | call popup_setoptions(s:win, {'highlight': 'Normal'}) 115 | endif 116 | 117 | endfunction 118 | 119 | 120 | " Return the name of the longest string in a list 121 | function! s:GetLongestLine(list) 122 | 123 | let len = 0 124 | " Simply parse one by one the line and check if 125 | " its length is the longest 126 | for line in a:list 127 | let _temp = len(line) 128 | if _temp > len 129 | let len = _temp 130 | endif 131 | endfor 132 | 133 | return len 134 | 135 | endfunction 136 | 137 | 138 | " Close leader menu and free the buffer 139 | function! s:CloseMenu() 140 | 141 | " Delete menu's buffer 142 | if exists('s:menuBuffer') 143 | unlet s:menuBuffer 144 | endif 145 | 146 | " Close window (force) 147 | if has("nvim") 148 | call nvim_win_close(s:win, 1) 149 | else 150 | call popup_close(s:win) 151 | endif 152 | 153 | " Free the window's handle 154 | unlet s:win 155 | 156 | if g:leaderMapperDebug 157 | echom "DEBUG: vim-leader-mapper - close window and delete buffer" 158 | endif 159 | 160 | endfunction 161 | 162 | 163 | " Wait for user action to decide next steps 164 | function! s:WaitUserAction(leaderMenu) 165 | 166 | " redraw to force display of menu (hidden by default with getchar call) 167 | redraw 168 | let userAction = "" 169 | let notCommand = 1 170 | 171 | while (notCommand) 172 | 173 | " wait for a user character input. Return ASCII code 174 | let userInput = getchar() 175 | " Convert to string 176 | let userInput = nr2char(userInput) 177 | let userAction = userAction . userInput 178 | 179 | " Break the loop if command recognized 180 | if has_key(a:leaderMenu, userAction) 181 | call s:CloseMenu() 182 | let notCommand = 0 183 | endif 184 | 185 | " Give up if receive ctrl-c or escape 186 | if userInput == "\" || userInput == "\e" || userInput == "\" 187 | call s:CloseMenu() 188 | return 189 | endif 190 | 191 | endwhile 192 | 193 | if g:leaderMapperDebug 194 | echom "DEBUG: vim-leader-mapper - User choice: ".userAction 195 | endif 196 | 197 | " Retrieve command and execute it 198 | call s:ExecCommand(a:leaderMenu, userAction) 199 | 200 | endfunction 201 | 202 | 203 | " Read leaderMenu and fill the menu's buffer 204 | function! s:FillMenu(leaderMenu) 205 | 206 | " Window buffer, delete first if exists 207 | if exists('s:menuBuffer') 208 | unlet s:menuBuffer 209 | endif 210 | 211 | " Convert the conf into a list of string and create/fill the buffer 212 | let s:leaderMenu = s:CreateMenu(a:leaderMenu) 213 | 214 | if has('nvim') 215 | let s:menuBuffer = nvim_create_buf(v:false, v:true) 216 | call nvim_buf_set_lines(s:menuBuffer, 0, 0, 0, s:leaderMenu) 217 | call nvim_buf_set_option(s:menuBuffer, 'filetype', 'leaderMapper') 218 | endif 219 | 220 | endfunction 221 | 222 | 223 | " Parse leaderMenu and create a list of string to display 224 | function! s:CreateMenu(leaderMenu) 225 | 226 | " Menu title 227 | let title = "" 228 | let strMenu = [] 229 | 230 | let max_key_len = 1 231 | " First grab the max length of the entries to align them with white spaces 232 | for [key, val] in items(a:leaderMenu) 233 | if key != "name" 234 | if strlen(key) > max_key_len 235 | let max_key_len = strlen(key) 236 | endif 237 | endif 238 | endfor 239 | 240 | " Then add the different user configuration 241 | for [key, val] in items(a:leaderMenu) 242 | if key != "name" 243 | " Extract description (ix 0 = cmd, ix 1 = description) 244 | " and add a space margin 245 | let str = repeat(" ", max_key_len - strlen(key)). key . " -> " . val[1] 246 | call add(strMenu, str) 247 | endif 248 | endfor 249 | 250 | " Put in shape the menu 251 | let menuLayout = s:DoMenuLayout(strMenu) 252 | 253 | " Then parse the menu to search for a name 254 | for [key, val] in items(a:leaderMenu) 255 | if key == "name" && !empty(val) 256 | let title = val 257 | endif 258 | endfor 259 | 260 | " If title doesn't exist, simply name it 'Menu' 261 | if empty(title) 262 | let title = " Leader Key Menu" 263 | endif 264 | 265 | " Append as first element the menu title and a blank on last line 266 | let finalMenu = [" ".title, ""] + menuLayout + [""] 267 | return finalMenu 268 | 269 | endfunction 270 | 271 | 272 | " Used to create the final layout of the menu, 273 | " by arranging the entry over the full window space 274 | function! s:DoMenuLayout(menuContent) 275 | 276 | " Sort list with alphabetic order and ignore case 277 | let sortedMenu = sort(a:menuContent, "i") 278 | " Get max len of menu items 279 | let lenMax = s:GetLongestLine(a:menuContent) 280 | " Compute window width and item nb per line 281 | let winLen = (&columns * g:leaderMapperWidth / 100) 282 | " Maximum per line 283 | let maxItem = winLen / lenMax 284 | " Check nb of entry to insert and shorten maxItem 285 | " to avoid crashing the loop 286 | if len(sortedMenu) < maxItem 287 | let maxItem = len(sortedMenu) 288 | endif 289 | " Maxim item len allowed per column 290 | let maxItemLen = float2nr(ceil(winLen / maxItem)) 291 | " Create the final menu based on maximum item per row. Append first the border 292 | let finalMenu = [" ╭" . repeat("─", (maxItem * maxItemLen) + 1) . "╮"] 293 | let tempItem = " │ " 294 | 295 | let iLen = 0 296 | " Concatenate the items to display several by line as 297 | " long it fits into the window 298 | for item in sortedMenu 299 | " Get number of space to append 300 | let itemLen = len(item) 301 | let missingLen = maxItemLen - itemLen 302 | " Append whitespace to have equal length entries 303 | let newItem = item . repeat(" ", missingLen) 304 | let tempItem = tempItem . newItem 305 | " If matched the num of item per line, append and continue 306 | let iLen += 1 307 | if iLen == maxItem 308 | call add(finalMenu, tempItem . "│") 309 | let tempItem = " │ " 310 | let iLen = 0 311 | " if reach the last item, add it 312 | elseif item == sortedMenu[-1] 313 | let missingLen = (maxItem - iLen) * maxItemLen 314 | let tempItem = tempItem . repeat(" ", missingLen) 315 | call add(finalMenu, tempItem . "│") 316 | endif 317 | 318 | endfor 319 | 320 | " Append bottom and return the formatted menu 321 | let bottom = " ╰" . repeat("─", (maxItem * maxItemLen) + 1) . "╯" 322 | call add(finalMenu, bottom) 323 | return finalMenu 324 | 325 | endfunction 326 | 327 | 328 | " Execute command requested by user 329 | function! s:ExecCommand(leaderMenu, cmd) 330 | 331 | " Extract command (ix 0 = cmd, ix 1 = description) 332 | let choice = get(a:leaderMenu, a:cmd)[0] 333 | " Check if is a dict, so a sub-menu 334 | if type(choice) == 4 335 | if g:leaderMapperDebug 336 | echom "DEBUG: vim-leader-mapper - enter sub-menu" 337 | endif 338 | call s:LoadMenu(choice) 339 | " Else run the command 340 | else 341 | if g:leaderMapperDebug 342 | echom "DEBUG: vim-leader-mapper - execute ".choice 343 | endif 344 | execute choice 345 | endif 346 | 347 | endfunction 348 | 349 | 350 | " Restore compatible mode 351 | let &cpo = s:save_cpo 352 | unlet s:save_cpo 353 | -------------------------------------------------------------------------------- /doc/vim-leader-mapper.txt: -------------------------------------------------------------------------------- 1 | *vim-leader-mapper.txt* Leader key menu maker 2 | *leader-mapper* 3 | 4 | ============================================================================== 5 | CONTENTS *leader-mapper-contents* 6 | 7 | Overview |leader-mapper-overview| 8 | 9 | Installation |leader-mapper-installation| 10 | 11 | Changelog |leader-mapper-changelog| 12 | 13 | 14 | ================================================================================= 15 | Overview *leader-mapper-overview* 16 | 17 | |vim-leader-mapper| is a Neovim plugin to create leader key mapping and a visual menu to display 18 | them. It's basically a copy of Spacemacs interactive menu, relying on leader key to toggle it 19 | (any key is possible). 20 | 21 | - Easy to use: the user can simply add his own commands with few setup and map them to leader key. 22 | - Configurable: the user can associate any command (internal or external command). 23 | - Fast: the plugin is very small, written in pure vimL. 24 | - No intrusion: no change on user mapping & configuration. 25 | 26 | It's also inspired from vim-leader-guide but it's simpler and use floating window to display 27 | the menu. 28 | 29 | 30 | ===================================================================================== 31 | Installation *leader-mapper-installation* 32 | 33 | 34 | Use Vim-Plug or any other plugin manager to install it: 35 | 36 | Plug 'dpretet/vim-leader-mapper' 37 | 38 | 39 | Follows a configuration example, binding regular Vim commands and FZF calls: 40 | 41 | " Define the menu content with a Vim dictionary 42 | let g:leaderMenu = {'name': "", 43 | \'f': [":Files", "FZF file search"], 44 | \'b': [":Buffers", "FZF buffer search"], 45 | \'s': [":BLines", "FZF text search into current buffer"], 46 | \'S': [":Lines", "FZF text search across loaded buffers"], 47 | \'g': [":BCommits", "FZF git commits of the current buffer"], 48 | \'G': [":Commits", "FZF git commits of the repository"], 49 | \'v': [':vsplit', 'Split buffer vertically'], 50 | \'h': [':split', 'Split buffer horizontally'], 51 | \'d': [':bd', 'Close buffer'], 52 | \'r': [':so $MYVIMRC', 'Reload vimrc without restarting Vim'], 53 | \'l': [':ls', 'List opened buffers'], 54 | \'t': [':Tags', 'FZF tag search'], 55 | \'o': [':normal gf', 'Open file under cursor'], 56 | \} 57 | 58 | 59 | Finally to bind leader key to space and toggle the menu on each space pressure: 60 | 61 | " Define leader key to space and call vim-leader-mapper 62 | nnoremap 63 | let mapleader = "\" 64 | nnoremap :call leaderMapper#start() "" 65 | vnoremap :call leaderMapper#start() "" 66 | 67 | 68 | One could want to specify the dimension and position of the window. This can be done 69 | with two parameters. 70 | 71 | To define the vertical placement of the window. Can be top, bottom or center (default is center): 72 | 73 | let g:leaderMapperPos = "center" 74 | 75 | To define the window's width, in percentage of the Vim window (default is 70%): 76 | 77 | let g:leaderMapperWidth = 70 78 | 79 | 80 | It's also possible to add submenu binded with a key. Here is an example: 81 | 82 | 83 | " Define the menu dedicated to FZF 84 | let fzfMenu = {'name': "", 85 | \'f': [":Files", "FZF file search"], 86 | \'b': [":Buffers", "FZF buffer search"], 87 | \'s': [":BLines", "FZF text search into current buffer"], 88 | \'S': [":Lines", "FZF text search across loaded buffers"], 89 | \'g': [":BCommits", "FZF git commits of the current buffer"], 90 | \'G': [":Commits", "FZF git commits of the repository"], 91 | \} 92 | 93 | " Define the menu content including the above menu 94 | let g:leaderMenu = {'name': "", 95 | \'f': [fzfMenu, "FZF menu"], 96 | \'v': [':vsplit', 'Split buffer vertically'], 97 | \'h': [':split', 'Split buffer horizontally'], 98 | \'d': [':bd', 'Close buffer'], 99 | \'r': [':so $MYVIMRC', 'Reload vimrc without restarting Vim'], 100 | \'l': [':ls', 'List opened buffers'], 101 | \'t': [':Tags', 'FZF tag search'], 102 | \'o': [':normal gf', 'Open file under cursor'], 103 | \} 104 | 105 | Pressing 'f' key will open the dedicated menu to FZF. 106 | 107 | In case your function/command binded needs to access the lines range of a 108 | visual selection, vim-leader-mapper setup two variables: `leaderMapperLineStart` 109 | and `leaderMapperLineEnd`. These variables are setup to line numbers as long the 110 | plugin is executed. When closing, it will setup them to `-1`. 111 | 112 | ================================================================================= 113 | Changelog *leader-mapper-changelog* 114 | 115 | v1.2.0 - 13/04/2020 - Fix issue to call functions/commands with visual selection 116 | Issue #4 117 | 118 | v1.1.1 - 01/11/2020 - Fix issue in display if last menu list is not fully filled 119 | - Add keyword highlight in menu 120 | 121 | v1.1.0 - 01/10/2020 - Add sub-menu support 122 | - fix several small bugs 123 | 124 | v1.0.2 - 12/17/2019 - Add border to floating window 125 | 126 | v1.0.1 - 12/12/2019 - Minor syntax fix in doc 127 | 128 | v1.0.0 - 12/11/2019 - Initial release 129 | 130 | 131 | -------------------------------------------------------------------------------- /plugin/leaderMapper.vim: -------------------------------------------------------------------------------- 1 | "--------------------------------------------------------------- 2 | " Plugin: https://github.com/dpretet/vim-leader-mapper 3 | " Description: A plugin to create a leader key menu 4 | " Maintainer: Damien Pretet https://github.com/dpretet 5 | "--------------------------------------------------------------- 6 | 7 | if exists('loaded_leader_mapper_vim') || &cp 8 | finish 9 | endif 10 | 11 | let loaded_leader_mapper_vim = 1 12 | 13 | " Next initialize the variable if not specified by user 14 | 15 | if !has('g:leaderMapperPos') 16 | " Can be center, top, bottom 17 | let g:leaderMapperPos = "center" 18 | endif 19 | 20 | if !has('g:leaderMapperWidth') 21 | " Percentage of the window 22 | let g:leaderMapperWidth = 70 23 | endif 24 | 25 | " Enable debug prints in :messages 26 | let g:leaderMapperDebug = 0 27 | 28 | " Shared variable with commands/functions to describe visual selection 29 | let g:leaderMapperLineStart = -1 30 | let g:leaderMapperLineEnd = -1 31 | 32 | " Save compatible mode 33 | let s:save_cpo = &cpo 34 | " Reset compatible mode to default value 35 | set cpo&vim 36 | 37 | " Declare startup command 38 | command! -nargs=? -range LeaderMapper call leaderMapper#start(,) 39 | 40 | " Restore compatible mode 41 | let &cpo = s:save_cpo 42 | unlet s:save_cpo 43 | -------------------------------------------------------------------------------- /syntax/leaderMapper.vim: -------------------------------------------------------------------------------- 1 | if exists("b:current_syntax") 2 | finish 3 | endif 4 | 5 | syntax case ignore 6 | syntax keyword leaderMapperKeyword select open close write read fzf load git 7 | \ buffer buffers search tag terminal execute 8 | \ task item image link column table row status 9 | \ rows columns tag tags 10 | highlight link leaderMapperKeyword Keyword 11 | 12 | syn region LeaderMapperKeys start="\["hs=e+1 end="\]\s"he=s-1 contained 13 | syn region LeaderMapperBrackets start="\(^\|\s\+\)\[" end="\]\s\+" contains=leaderMapperKeyword keepend 14 | 15 | hi def link LeaderMapperKeys Type 16 | hi def link LeaderMapperBrackets Delimiter 17 | 18 | let b:current_syntax = "leaderMapper" 19 | --------------------------------------------------------------------------------