> Another Spacemacs configuration for Jetbrain IDEs
Recently, I’m working on a React Native project. I have tried using Emacs to do the coding, but I
cannot really pick up the whole new stuff without a fancy auto-completion or finding definitions
since the syntax of React is so different and special. That’s why I pick up Webstorm as a
workaround. And there, I find a way to build my Jetbrain IDEs just like Spacemacs.
Like I said in my previous post, space way is good for Vim users and only Vim can do this because it
has other modes other than just insert mode. In this case, key bindings will never be a problem. We
are using the sticky key sequences and prefix key for memorization.
Welcome to the heaven!!!
If you’re too lazy to read the whole stuff, grab my
.ideavimrc on Github
Using space key as the leader is a very popular way of editing, navigation, and
commanding. There is never an easy way to get used to new shortcuts, but trust me, you would
definitely like it once you use it.
Think about how you invoke commands in VSCode before. When you want to call the command-palette,
you need to put your left hand’s two fingers on Ctrl + Shift key or Command +
Shift key and press p. And note that it’s a key chord combination when you actually
press these keys.
This looks so stupid when you compare it with just Space Space in Vim’s normal or visual
mode. And by saying Space Space, it’s a sticky key binding which means you just type
space key twice in sequence. And you can just set your hands as the default typing
position shown in this picture.
Well, now you probably get the point of using space key. But there is more of it.
Since sticky keys are just key sequences, you can cluster a lot of similar commands to a prefix like
space f (file related commands). For example, space> f f go to the explorer,
space> f s save file and space> f S save all. In this case, you won’t mess up
with these keys because they have the same prefix space> f.
Install ideaVim and create a .ideavimrc file in home directory, just like ~/.ideavimrc.
In case you want to sync your settings across multiple machines, you should checkout the Setting
Repository >
here.
If you want to use the Emacs key in Vim’s insert mode, which is the hybrid mode in Spacemacs,
copy the following script to ~/.ideavimrc.
" ============================================================================ " emacs keymaping for cursor movement{{{ " You have to unbind C-g before it works " ============================================================================ nmap <c-g> <Esc> vmap <c-g> <Esc> imap <c-g> <Esc>a nmap <c-a> ^ nmap <c-e> $ vmap <c-a> ^ vmap <c-e> $ imap <c-e> <Esc>A imap <c-a> <Esc>I imap <c-d> <del> inoremap <c-p> <up> inoremap <c-n> <down> " command line cnoremap <C-a> <Home> cnoremap <C-e> <End> "}}}
Note: You have to disable the C-a, C-e in Jetbrain IDE to have the visual mode
working correctly.
You can click the from here to find the action by key.
To bind the actions under space, put the following script in the ~/.ideavimrc.
The ugly <Backspace><Backspace><Backspace><Backspace><Backspace> is because when we enter the
command mode from visual mode, we have :'<,'>. The extra chars need to be deleted before we invoke
the actions.
let mapleader = " "
" ============================================================================ " key bindings for quickly moving between windows " h left, l right, k up, j down " ============================================================================ nmap <leader>wh <c-w>h nmap <leader>wl <c-w>l nmap <leader>wk <c-w>k nmap <leader>wj <c-w>j nmap <leader>wv <c-w>v nmap <leader>ws <c-w>s nmap <leader>wc <c-w>c nmap <leader>wm :action HideAllWindows<CR> nmap <leader>wz :action ToggleDistractionFreeMode<CR>
" tab is used in karabiner as <C-i>, <C-d> as delete nmap <tab> :action Forward<CR> nmap <delete> <C-d> vmap <tab> :<Backspace><Backspace><Backspace><Backspace><Backspace>action Forward<CR> vmap <delete> <C-d>
The multi-cursor action does not work correctly as well as the extend region and shrink region.
They mess up some visual selection in Vim and the original selection. That’s the reason. But so
far I cannot do anything. So I just put the script here in case they work later on.
" select occurrence, they do not work when editing nmap mn :action SelectNextOccurrence<CR> nmap mp :action UnselectPreviousOccurrence<CR> nmap ma :action SelectAllOccurrences<CR> vmap mn :<Backspace><Backspace><Backspace><Backspace><Backspace>action SelectNextOccurrence<CR> vmap mp :<Backspace><Backspace><Backspace><Backspace><Backspace>action UnselectPreviousOccurrence<CR> vmap ma :<Backspace><Backspace><Backspace><Backspace><Backspace>action SelectAllOccurrences<CR>
There are other options you might want to add.
set gdefault set smartcase
" use system clipboard set clipboard=unnamedplus,unnamed
set surround
" Allow backspace and cursor keys to cross line boundaries set whichwrap+=<,>,h,l
" black hole register vmap <backspace> "_d vmap <del> "_d