DEV Community

Cover image for My Vim Story

My Vim Story

Gaveen Prabhasara on March 09, 2020

Once you have used 'notepad.exe', you have used all text editors—they said. A text editor is a text editor is a text editor—they said. After the fi...
Collapse
 
eljayadobe profile image
Eljay-Adobe

Bill Joy, the creator of vi, who used an ADM-3A terminal (which is why some of the keys are mapped the way they are, and the ADM-3A didn't have separate arrow keys, and placement of ESC and CTRL). His interviews where he is nostalgic about how vi came about, in a world with 300 baud modems (2400 baud if you're lucky!), super-slow bandwidth where every character is "expensive" to transmit, why vi has so many short single-character commands. And how with modern computers with enormous speed and incredible bandwidth make the raison d'être for vi to be obsolete.

Nevertheless, vi persisted. (And Vim too!)

Collapse
 
demianbrecht profile image
Demian Brecht

Nice one! My only words of caution are applicable if you find yourself editing files across a number of different systems (especially when there may be network security restrictions at play): The more heavily you rely on customization, the more you're going to bash your head on your keyboard trying to remember how to do it the vanilla way. I used to have a heavily modified .vimrc with all kinds of plugins and custom keybinds, but ended up getting rid of many of them in favor of building muscle memory around the built-in commands instead after sufficient time was spent bashing my own head on my keyboard. YMMV though :)

Collapse
 
gaveen profile image
Gaveen Prabhasara • Edited

I agree, with caveats. Muscle-memory is a tricky thing. Therefore, learning the fundamentals is important before trying to customize. I probably should have mentioned that somewhere clear. Let me put it this way.

Whenever I introduce customization to an environments/tools—be it software or not—my idea is to learn the fundamentals of how it was meant to be used, then add bells and whistles. If you lose the bells and whistles, you still have access to the basics you learn to see you through. Same goes for vim.

If I can't get my customizations in, I should be able to get basic editing done without slowing me down too much. But if I can help it, there's no point of avoiding other niceties you can get. I have the ease of access with vimfiles on GitHub for the same reason.

Collapse
 
konart profile image
Artem Kondratev

nnoremap <Leader>/ :let @/=""<CR>

Might be a better way to clear / after the search. See stackoverflow.com/a/657484 (+ comments)

Collapse
 
gaveen profile image
Gaveen Prabhasara

It can definitely be useful depending on what you want to achieve. However, I wouldn't necessarily call it "better" without a context.

To elaborate, while :let @/=""<CR> clears the search pattern, what I have (i.e., :noh/:nohlsearch) only clears the highlighting (i.e., search pattern remains the same, just without highlighting), which is exactly what I want in most cases. This way, if I need to jump to the next occurrence of search pattern, I only need to press n which will do so, as well as start highlighting again.

Collapse
 
konart profile image
Artem Kondratev

Sure, different workflow, different approach.

I guess I'm too used to my typical workflow: while I still need my search result - I want it highlighted, but after I'm done with it - it should be gone.

Collapse
 
ianturton profile image
Ian Turton

I use :command! C let @/="" so I can simply hit :C to clear

Collapse
 
konart profile image
Artem Kondratev

Well, mapping is one's personal preference of course :)

Collapse
 
walopes profile image
Willian A. Lopes

Vim is really amazing. Today I use vim only for changing some configuration on my system or a minor thing in a file, but I know I should use it more, much more.
Thanks for the awesome article (makes me excited in making vim my main editor)! :D

Collapse
 
polemius profile image
polemius

Thanks you for good article!

Collapse
 
petr7555 profile image
Petr Janik

Hi, could you please explain what QuickfixToggle() is supposed to be used for?

Collapse
 
gaveen profile image
Gaveen Prabhasara

Vim has an inbuilt QuickFix window feature which can pop into view on errors, etc, sort of like in popular IDEs. This is sometimes used by filetype plugins as well. For example, if you run a compile action while on a file, the compiler errors could be displayed in the QuickFix window. Here's an outside link which shows it with a little more detail.

While it can be quite useful, it can be annoying if you have to open it manually too often (e.g., :copen or :cope) or if you have to go close it by typing in the relevant command (e.g., :cclose or :ccl).

Therefore, I wanted to map a keyboard shortcut which would toggle the QuickFix window. This is the action I have defined in the QuickfixToggle() function. It is later mapped to <leader>q.

Collapse
 
petr7555 profile image
Petr Janik

That's so cool! Thank you for a thorough explanation.

Collapse
 
imjaroiswebdev profile image
José Antonio Reyes

Thanks for sharing this helpful content, for me that i'm a newbie in Vim (with a lot of useless experience in VsCode and SublimeText) resulted very clearing. 👏🏽