vim search for ) replace with text then newline then )

Problem

I have a huge sql query with 574 lines and I needed to replace a closing bracket ) with text and then a new line with a closing bracket

Before:


) AS

After:


GROUP BY v.visit_id
) AS

Solution

Using vim’s search and replace feature


:%s/^)/GROUP BY v.visit_id\r)/gc

The above searches for the lines beginning with the closing bracket ) and then replaces it with text and then new line (\r) followed by a closing bracket )

References

How to replace a character by a newline in Vim

Add a newline after given patterns

FreeBSD shared object libdl.so.1 not found required by vim

Problem

I had installed vim on FreeBSD but I was getting the dependency error “shared object libdl.so.1 not found required by vim” whenever I would try to use it.

Solution

As detailed from this forum I had probably messed up in my initial install of vim therefore, the suggestion is to install postmaster:


To install the port: cd /usr/ports/ports-mgmt/portmaster/ && make install clean
To add the package: pkg install portmaster

Next is to rebuild vim with all it’s dependancies


portmaster -f vim

References

Shared object “libpcre.so.1” not found

Updated

This dint work. I was working in a jailed environment, not sure if this was a case.

 

Search when in Copy Mode Tmux

Problem

Need to search for a string when in copy mode.

Solution

In the user’s home directory, add the following file if it doesn’t exist and enter the below:

 $ vim .tmux.conf
setw -g mode-keys vi

Then save and exist.
So now, ctrl b [ to go to copy mode. Then ? to search Upwards and / to search downwards.

Other commands are as below as from this link:

 

Function                vi             emacs
   Back to indentation     ^              M-m
   Clear selection         Escape         C-g
   Copy selection          Enter          M-w
   Cursor down             j              Down
   Cursor left             h              Left
   Cursor right            l              Right
   Cursor to bottom line   L
   Cursor to middle line   M              M-r
   Cursor to top line      H              M-R
   Cursor up               k              Up
   Delete entire line      d              C-u
   Delete to end of line   D              C-k
   End of line             $              C-e
   Goto line               :              g
   Half page down          C-d            M-Down
   Half page up            C-u            M-Up
   Next page               C-f            Page down
   Next word               w              M-f
   Paste buffer            p              C-y
   Previous page           C-b            Page up
   Previous word           b              M-b
   Quit mode               q              Escape
   Scroll down             C-Down or J    C-Down
   Scroll up               C-Up or K      C-Up
   Search again            n              n
   Search backward         ?              C-r
   Search forward          /              C-s
   Start of line           0              C-a
   Start selection         Space          C-Space
   Transpose chars                        C-t

References
tmux shortcuts & cheatsheet