Vim Usage
Jun 09, 2023
ctrl+o and ctrl+shit+i is the combo for going back and forth using vim jumps. Normally it should be ctrl+i or tab to jump forward. If it’s not working then I found you can use ctrl+shift+i.
Will keep updating this post with other vim related things that i want to track and share.
Golang Import Error Sometimes if you install golang package using go get in terminal outside vim editor. It’s still showing import error.
... ➦
Refactoring in vim - golang & graphql
Apr 19, 2023
Following will convert golang struct to a 99design graphql schema type.
1 2 3 4 5 6 type Post struct { UserID int `json:"userId"` ID int `json:"id"` Title string `json:"title"` Body string `json:"body"` } If you want to change case on selected lines you can use following.
1 :3,6s/`.*/ Above regular expression will remove the json tags from the line 3 to 6.
1 2 3 4 5 6 type Post struct { UserID int ID int Title string Body string } Next two steps are field name to camel case and data type to be capitalize.
... ➦
Check which process is using specific port
Mar 21, 2023
This is a simple command to find out about process id binded with a port. Maybe you can kil the process.
1 lsof -i tcp:1313
Change snake case to camel case using VIM
Mar 15, 2023
As I’m working on refactoring some legacy code, I’ve encountered the challenge of changing the variable naming convention. The current convention is not standardized, and I’ve noticed that snake case (e.g., first_name) is commonly used. One additional constraint is to only change part of a file.
Following will looks for any places with an underscore followed by a lower case letter and replaces that with an upper case letter.
1 :1,$s/_\([a-z]\)/\u\1/g If you want to change case on selected lines you can use following.
... ➦
Vim set current directory to the current buffer directory
Feb 27, 2023
Sometimes, I tend to forget this simple command, which can be handy for quickly switching to the directory of the current buffer in Vim. This can be useful when searching for files within your project, especially if your project search is not based on the git root or if your current directory is not being tracked by git.
1 :cd %:p:h
Golang Swagger2.0
Oct 28, 2022
This post is currently in progress. You shall not pass. 🧙🏻♂️
This post serve as small documentation to add swagger and its ui to your existing golang API. I will be using go swagger 2.0 library or framework to do so which basically add comments on your existing code to generate swagger documentation.
Make a small gorilla mux api two endpoints with GET and POST Add the comments annotations to source code, meaning handlers Download swagger-ui from the go-swagger repo Serve the swagger-ui folder as a fileserver.
... ➦
Vim Selecting Function Body
Oct 28, 2022
The better way to select a function content is to go inside a function with your cursor and type : vi} it will select everything between { and }.
Another method is using v{o} this will also select function body.
In case you want to select body and the function signature you can do va{V
Running Minecraft On Linux
Jun 08, 2020
I have heard about Minecraft before and never paid much attention to it until my wife told me to try it out and see if our kid take any interest in that. I took this mission and invest bit of time, if I recall correctly it took me 4 days to get the result i wanted with mods. I had to do mods to get Elephants available my Kid loves them.
... ➦
Setting up blog with hugo & vercel
Apr 30, 2020
I am playing with Hugo trying to get a blog up and running with it. I have following TODO items in mind with my blog:
get a clean theme get code preview maybe comments support something? deployment of theme and any custom code with Vercel formerly known as Zeit. Get Theme I end up choosing hyde-hyde due to it’s slick clean look. After that I explore how to make sidebar links work.
... ➦
Archive Folders With Powershell
Apr 30, 2014
When your web application is running on web server and you don’t have automatic backup service available form your hosting service provider taking manual backups is really a frustrating job.
I have Pscx module installed on my PC and they have a nice little command Write-Zip available so I decided to write a custom powershell function that can create archive in zip formats for me. You can use windows task scheduler to invoke any powershell script so you can take advantage of this to have automatic daily or monthly backups.
... ➦