Posts for: #Vim

Neovim + Sourcegraph Cody Plugin Integration

Introduction

Have you ever used Sourcegraph’s Cody? It is a great tool for developers, it is not just another LLM, it is tailored specifically for developers. Cody has some good features that allow parsing of context for the prompt in a smarter way.

What is Sourcegraph’s Cody

Cody is an AI assistant for developers that understands code context and can generate code. It goes beyond just answering questions - it can write code for you.

[]

Configure Neovim in Lua

Introduction

It has been a while since I have written a Vim article. Finally, I got some ideas after configuring my Neovim setup for Lua. I recently migrated to Ubuntu a couple of months back and it has been a cool change from Windows 7!

In this article, we’ll see how you can set up neovim for Lua. Since Neovim 0.5, it supports lua out of the box, so in the recent release 0.7, it added more native support to lua making it a lot easier to configure and play with neovim. So, we will see how we can use lua to convert all the 200 liner vimscript into lua (We can even have packages and modules:) We will cover how to configure your keymaps, pull up all the plugins, vim options, and other customizations.

[]

Vim: Get the Text from Visual Selection

Using Registers

We can get the selected text in a variable in Vim Script using registers.

normal gv"xy
let context = getreg("x")

Lets break down the command

normal mode -> gv -> (y)ank text -> to the "x" register
               |                  |
               |               Copy the contents into x register(or any register you like)    
               |                  
            Select the previously selected text   

Here, we are entering normal mode and selecting text which was previously selected and yank the contents into a register in this case we are using (x) register, it can be any register. Now to get the contents of that register we can use the function getreg("register_name") or use "xp" to paste the contents of the x register or more generally for any register("<register-name>p).

[]

Comment/Uncomment Code: Vim for Programmers

Introduction

We as programmers always fiddle with commenting out code for code testing, documenting the function of code, and most importantly debugging. So you can’t wait to comment on a large chunk of code manually, as it is quite a tedious thing to do. Let’s do it effectively in Vim.

In this part of the series, I’ll cover how to comment/uncomment chunks/blocks of code effectively in Vim. We will see and use some commands, keybindings for doing so, and also we would add certain components to our vimrc file as well to design some custom key mappings. Let’s get faster with Vim.

[]

Vim for Competitive Programming

Introduction

Vim is not a bad text editor when it comes to using it for Competitive Programming. It’s kind of one way or the other, you would love it or you could trash it as it can waste a tremendous amount of time to write code every time. But once you are in a decent setup including some key-bindings and plugins can improve your speed in using Vim. I personally have used it since the beginning and haven’t regretted it even a tiny bit till date. It’s a flawless and enjoyable experience. I’ve used C++ for my CP journey, C is quite similar as well, but C++ has more library support and is a bit easier to write comparatively.

[]

Why use Vim ?

Introduction

So, Why would one use Vim? As Vim being the most complicated Text editor when it comes to closing it!! Also, people think it’s not worth the time or it’s just not their type of Text Editor. Well, that’s true, I am not forcing anyone to use Vim, just to tell the reasons why people use Vim. Again, it’s not to show off to anyone that I use Vim, just to appreciate the power of Vim and its community, it’s just amazing!!

[]

Vim: NERDTree

Introduction

NERDTree is a great plugin in Vim for managing and navigating Files. Some might prefer fzf, telescope, and other plugins for navigation, NERDTree is not a bad option to begin within Vim. NERDTree allows you to even create/delete/move files and folders flawlessly without much effort, so it becomes a much more viable beginner’s plugin.

Installing NERDTree Plugin

So, let’s start with the Installation of the NERDTree Plugin, it’s quite straightforward and simple.

[]

Vim: Buffers

Introduction

I have talked about Vim tabs, window splits in the previous articles, and now I am quite keen on explaining the finest unit of file that you can open using Vim and that is a buffer. Tabs are a collection of windows, Windows are the viewport on buffers (collection to view the buffers), and Buffers are the memory that holds text in the file. So let us explore buffer in detail. This article won’t cover each and every tiny detail about buffers but surely enough to make you understand what a buffer is and how to manage those.

[]