0aslam0 0aslam0 - 1 year ago 55
SQL Question

Edit an extremely long sentence in Vim

I have an SQL query that has over 5000 characters. I don't have access to mouse, just the terminal Vim editor. During testing, I need to change values of this query here and there. It is so long that, the next line number appears after 2 screens of pressing page-down.

So if I have to edit, I go to the beginning/end of the line and starts pressing

as required. This is very tiresome. Sometimes, doing a search helps. I hope you can understand the situation.

How can I make the editing easier?

Answer Source

These settings will help you immensely:

"Make long lines wrap
set wrap

"Make wraps *not* occur in the middle of a word
set linebreak

"Make the last line look OK
set display+=lastline

"Make 'j' and 'k' go down a visual line, not an entire line
nnoremap j gj
nnoremap k gk

"Make the arrow keys also go down a visual line
nnoremap <Up> gk
nnoremap <Down> gj

"Allow the option to move up entire lines
nnoremap gj j
nnoremap gk k

Since lines starting with " are comments, you can just directly copy and paste this into your .vimrc.

Another useful feature is the bar command |. If you type 200 |, this will jump to the 200th character on the current line.

If you want, you could also include these settings:

nnoremap $ g$
nnoremap 0 g0
nnoremap g$ $
nnoremap g0 0

With these settings, you can use g0 and g$ to jump to the first/last character on this visual line, rather than than the first/last character on the extremely long line. These settings don't hurt, but IMO the first group of settings I posted are more useful.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download