to VIM, or not to VIM
yes, Emacs also exits but no, I’m totally not going to consider using it
Vim? - are you serious?
Yes I am. (most of the time, actually)
After 10+ years I started using Vim on a daily basis again. A decade ago I was using Vim as main editor for my programming classes & assignments at University. I ditched Vim for ‘real IDEs’ when starting at a big company with 300+ developers and never really got back to it .. until I rediscovered it a couple of weeks ago.
I am, for various reasons, working on different devices which feature different editors/IDEs on a daily basis.
Yes, I’ve used IDEs and editors, such as KDevelop, Eclipse, Atom, vscode, notepad++, VisualStudio, IntelliJ, … (I could continue for a while) … before, but none of them ‘does it all’ (which is not a bad thing!), and none of these run on all of the platforms I tend to use regularly.
Being a long-time Linux user, I naturally came across Vi/Vim long time ago and had to learn the basic usage of vi for an LIPC exam about 15 years ago.
In short: I purchased a Chromebook a couple of months ago and started using it to write some code - turns out Vim runs flawless (especially in contrast to vscode) and enables me to do everything I need to do.
Extensions
NOTE: at the moment of writing this blogpost, I’m doing most of my work in PowerShell, a few lines of JavaScript as well as occasional bits and pieces in MSVC and Rust.
All of my personal notes, as well as this Blog are written in Markdown and then converted by Hugo or Pandoc.
NERDTree
A file system explorer that integrates into the editor.
Assuming you’re using Vim version 8+, simply clone the plugin directory into Vim’s ‘pack’ directory. (mind that paths differ between Linux and Windows, in Linux it normally is placed in ~/.vim/pack
, in Windows in $Home/vimfiles
)
git clone https://github.com/preservim/nerdtree.git ~/.vim/pack/vendor/start/nerdtree
.. alternatively, check if your OS does have a vim-nerdtree
(or similar) package pre-built, that should basically yield the same result.
To check if the plugin is loaded, use the :scriptnames
command inside and see if something like
~/.vim/pack/vendor/start/nerdtree/plugin/NERD_tree.vim
~/.vim/pack/vendor/start/nerdtree/autoload/nerdtree.vim
is being listed.
To toggle the NERDTree, use the :NERDTreeToggle
command.
Because always typing :NerdTreeToggle
is not really usable, creating a keymapping in your .vimrc
is what most people do. I use the often-seen <C-n>
shortcode (Control + n).
To enable this, put following into your .vimrc
(if the file does not exist, create it in your user’s home directory).
map <C-n> :NERDTreeToggle<CR>
vim-tabbar
In order to have a better overview of the currently opened buffers, (see :ls
), the vim-tabbar plugin adds lightweight tabs to the top of your editor. (you are still going to use :b <number>
to switch buffers, or :tab <number>
to switch tabs.)
Install the plugin with
git clone https://github.com/drmingdrmer/vim-tabbar.git ~/.vim/pack/vendor/start/vim-tabbar
YouCompleteMe
Probably one of the most powerful plugins out there: youcompleteme
To set it up, use the install.py script found in the ycm-GitHub Repo
git clone https://github.com/ycm-core/YouCompleteMe.git
cd YouCompleteMe
./install.py
more plugins
This blogpost is getting longer than I expected, just note that I currently also use following plugins:
- vim-editorconfig - make vim pay attention to .editorconfig files
- rust.vim - Rust language support
- vim-ps1 - PowerShell language support
my .vimrc / keymappings
My ~/.vimrc
is still pretty small .. 😄
filetype plugin on
filetype indent on
set number
syntax on
set tabstop=2
set shiftwidth=2
set expandtab
let mapleader=","
set splitbelow
set termwinsize=10x0
map <leader>def <c-]><cr>
map <C-n> :NERDTreeToggle<CR>
set makeprg=make\ -j9
nnoremap <F7> :make!<cr>
nnoremap <F5> :!./main<cr>
keys / commands to remember
These are the key combinations I use the most:
- ‘
<Esc>
’ => a.k.a. get me out of here - mash this key often enough to get back to default mode - ‘
i
’ => enter insert mode - ‘
:w
’ => save current document - ‘
:q
’ => quit (fails with unsaved changes) - ‘
:q!
’ => really quit (even quits if there are unsaved changes) - ‘
:wq
’ => save, then quit - ‘
h j k l
’ => cursor movement - ‘
*
’ => jump to next word matching word under cursor - ‘
#
’ => jump to previous word matching word under cursor - ‘
v
’ => enter visual mode (select stuff) - ‘
V
’ => enter visual mode (line based) - ‘
y
’ => ‘yank’ a.k.a. copy - ‘
yy
’ => yank current line - ‘
p
’ => paste - ‘
d
’ => cut - ‘
dd
’ => cut whole line - ‘
<Ctrl + d>
’ => move forward 1/2 screen - ‘
<Ctrl + u>
’ => move back 1/2 screen - ‘
/
’ => enter search mode (/
in search mode jumps to next match) - ‘
:term
’ => spawn terminal in split buffer - ‘
:ls
’ => show active buffers - ‘
:b <number>
’ => switch to buffer #number - ‘
:tabs
’ => list currently opened tabs - ‘
:tab <number>
’ => switch to tab #number - ‘
<Ctrl + w>< w >
’ => jump to next visible buffer - ‘
<Ctrl + w>< + >
’ => increase vertical size of current window - ‘
<Ctrl + w>< - >
’ => decrease vertical size of current window - ‘
<Ctrl + w>< > >
’ => decrease horizontal size of current window - ‘
<Ctrl + w>< < >
’ => decrease horizontal size of current window
I really wonder if this post is going to be of some use for anyone else than me in the future 😄
stay safe & ~ happy hacking ~