Posts tagged 'vim'

Vimprovements

published on March 26, 2015.

One part where I always felt (and still feel) that I could improve on my Vim usage, is when moving around. I don’t use the mouse, I don’t use the arrow keys, but for a while now I felt that spamming hjkl to get from one place to another is not really efficient. To be honest, it is kind of easy to just press down jjjjjjj … to move down lines. Went a bit too far? Just kk back. But there has to be a better way.

First off, I installed vim-hardtime to break the habit of spamming hjkl. That plugin limits the number of times one can press hjkl in a set time frame. I have it set up to block me from moving for a second after pressing the same motion twice in a row. jj is OK, but if I want to do jjj, well…

And this gets annoying. I want to edit code, not sit around and wait!

Faster moving around

I know about relative line numbers. I tried using them. And I guess my brain is just not wired in such a way that I could find relative numbers easy to use.

The second plugin I installed is vim-easymotion. It is supposed to make moving around in Vim much easier. There’s a lot of stuff going on in there, it has a lot of features. For now, I use 2 bits from it - jump to anywhere with s and k and j to move in lines up and down. I especially like these in visual mode, makes selecting text real nice.

I started using :<line_number> more to jump to specific lines, f and F to search on the current line, { and } to move in paragraphs. I’m also more comfortable with general search with / and ?.

One other pair of commands that help me reduce spamming jk is u and d to scroll the window up and down.

Faster working with files

The third plugin I installed is CtrlP. I stumbled upon it in a /r/vim thread and decided to try it out. Up until then I was using NERDTree exclusively to navigate around files and I can’t really remember when was the last time I hit n to open it since I have CtrlP. It’s just amazing to work with files now.

NERDTree still has it’s use cases, for example in a project where I don’t really know what files are in there, but for projects on which I work frequently… Oh boy! Wonderful stuff.

I left the default p for searching for files, but remapped <tab> to open CtrlP’s find buffer mode.

Misc

Other stuff I did to make working in Vim more comfortable…

I set leader to be . I had it as , for a long while, but realised that it’s to close on the keyboard to the . and I kept repeating the last command when I actually wanted to do some magical incantation.

I learned about :m[ove] to move and :co[py] to copy lines. Good stuff.

dap and cap pairs are also useful from time to time. They just simply delete, or change, around the current paragraph.

Finally, I added the following bit to my .vimrc to highlight the current line:

augroup CursorLine
    au!
    au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
    au WinLeave * setlocal nocursorline
augroup End

So, that’s pretty much it. I don’t think that I’m super fast navigating around in vim, but it’s definitely better than some 3 months ago.

Next thing I want to tackle is using registers, and especially macros.

And read more of that nice :help holy-grail.

Ack in vim

published on December 09, 2014.

I started using vim 3, 4 years ago. The way I use it is that I started out with no plugins and with a handful of lines in .vimrc. It is far too easy to cram all kind of stuff into it and then get lost in the myriads of key combinations. To prevent that, I decided to slowly add in bits and pieces I find lacking in my day to day usage of vim. Also allows me to first learn the editor and later the plugins.

Today was an exceptional day as I added not one, but two plugins to vim! And that is a big change for me as the total number of plugins I now use is 4.

The first one I added is ack.vim. It’s a nice little plugin to run ack from within vim and show the results in a split window. It’s rather easy to use, one just basically types :Ack search_string and that’s it. The one thing I immediately disliked is that it sort of gets lost in the subdirectories of a project.

A quick google search found a solution for that little problem as well: vim-rooter. It doesn’t do much, just changes the current working directory of vim to the project root when you open a file.

And that’s basically it. Nice and fast searching with ack from vim.

Tags: ack, vim, plugins, rooter.
Categories: Development, Software, Programming.
Robert Basic

Robert Basic

Software developer making web applications better.

Let's work together!

I would like to help you make your web application better.

Robert Basic © 2008 — 2020
Get the feed