Posted

in

Migrating from VSCode to LunarVim

LunarVim

Like many, I used to code with VSCode with the VIM extension, but I always found this combination unnatural and not optimal.

In the past, I already tried several times to set up a dev environment using Vim or Emacs, but it was not a successful experience.

The last time, it was with Spacemacs. It’s a great product but I never succeeded in using it long-term. The performance and speed were not so outstanding compared to VSCode, and the overall experience left me with mixed feelings, even if it allowed me to discover the so-loved Org Mode. I even tried to replace Notion with Org Mode, but it was so time-consuming that I dismissed this experiment.

A few days ago, I see a tweet from Laracasts announcing a new course: Neovim as a PHP and Javascript IDE, made by Jess Archer (Laravel core team).

I viewed this announcement as a new opportunity to try to dismiss VSCode from my workflow completely. After a few episodes, my curiosity and impatience took over the (slow) rhythm of the course, and I decided to test LunarVim, which has the advantage of having a standalone configuration that does not overwrite your Neovim configuration.

Kitty, Tmux, LunarVim

I didn’t know Kitty initially, I heard this name for the first time in Jess Archer’s course. Kitty is a GPU-based terminal emulator made by Kovid Goyal, the creator of Calibre, the famous E-books management software.

I was quickly seduced by the very clear documentation, so I started using it jointly with LunarVim.

In my prior “terminal stack”, there was also Byobu, a terminal multiplexer. I also decided to replace this one in favour of Tmux.

So I had my new development stack: Kitty for the terminal, Tmux for terminal multiplexing, and LunarVim for code editing. Great!

And then, the first problem occurred… everything was so slow! It was a new disappointment. Scrolling my VueJS files – despite being correctly coloured and formatted – was painful.

I Googled the issue and implemented some proposed workarounds, but it didn’t solve the problem. I read the docs of Kitty again, and I found that:

I tried without Tmux, and indeed, everything was very fast.

Removing Tmux from my stack

In a desperate move, I decided to remove Tmux. I was doubtful about Kovid Goyal’s claim that Kitty can (almost) fully replace it. So I read the docs again. And again.

I added some shortcuts for Kitty, the same ones I used every day with Byobu:

map ctrl+a>c new_tab_with_cwd 
map ctrl+a>ctrl+c new_tab_with_cwd
map ctrl+a>n next_tab
map ctrl+a>ctrl+n next_tab
map ctrl+a>p previous_tab 
map ctrl+a>ctrl+p previous_tab 
map ctrl+a>d close_tab
map ctrl+a>ctrl+d close_tab
map ctrl+a>w new_os_window
map ctrl+a>ctrl+w new_os_window

And that’s it! Byobu/Tmux is replaced.

As you noticed, I duplicated all shortcuts to cover “Ctrl+A, Key” and “Ctrl+A, Ctrl+Key”. This is because my small left finger stays on the Ctrl key sometimes. I don’t know why, this has always been like that.

Customizing LunarVim

I added some options and shortcuts to LunarVim, but not so much.

First I never liked code breadcrumbs. These are useless to me.

-- Disable breadcrumbs
lvim.builtin.breadcrumbs.active = false

Then, I customised buffer switching. First, Ctrl+t to go back and forth between two buffers, and then, a variant of Tmux/Screen shortcuts to go to the next or previous buffer.

-- Buffer switching
lvim.keys.normal_mode['<C-t>'] = ':b#<CR>'
lvim.keys.normal_mode['<C-e>n'] = ':bn<CR>'
lvim.keys.normal_mode['<C-e>p'] = ':bp<CR>'

So, to go to the next terminal tab, I have to type Ctrl+a, n. And to go to the next buffer within LunarVim, I have to type Ctrl+e, n.

I also defined an alternative to exit the Insert mode. <Esc> is so far away!

-- Escape
lvim.keys.insert_mode["jk"] = '<Esc>'

And I added some other stuff copy-pasted or inspired from the course of Jess Archer:

-- Reselect visual selection after indenting.
vim.keymap.set('v', '<', '<gv')
vim.keymap.set('v', '>', '>gv')

-- Paste replace visual selection without copying it.
vim.keymap.set('v', 'p', '"_dP')


-- Easy insertion of a trailing ; or , from insert mode.
vim.keymap.set('i', ';;', '<Esc>A;')
vim.keymap.set('i', ',,', '<Esc>A,')

-- Wrap
lvim.builtin.wrap = true

-- Relative lines
vim.opt.relativenumber = true

And that’s it!

Am I happy?

For now, Yes.

This stack is so fast.

There are still some tweaks to do, but I can code without issue without them, it will be done progressively.

Some things I plan to do to improve it:

  • Adding Vim Snipe plugin ( I used it in VScode)
  • Solve some padding issues between Kitty and LunarVim (too much space between NeoVim and Kitty tabs).
  • Improve Linting
  • Learn and remember shortcuts of Nvim-tree,
  • Use Snippets,
  • Etc.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *