Category Archives: VIM

Some shortcuts with vim

Many of you know that i like VI/VIM and when i say editor it must be VIM. Often i hear at customer sites or from my colleagues, that they can’t work with vi, that shortcuts are hard to remember or even they can’t save their changes.

When you remember some short commands, you can work very fast and you can edit files through all connections (ssh, x-forward) to a server.

I created a mindmap as preparation for a speedgeeking session, the session wasn’t accepted, but the file is already done. So you can download a cheat-mindmap with a collection of shortcuts.

Navigate in files

Shortcuts in command mode:

  • gg – top of file
  • G – end of file
  • :## – ##=number go to line number
  • 0 – beginning of line
  • $ – end of line

Save and undo

  • :w – save file
  • :wq – save and close
  • :q! – close and do not safe
  • u – Undo

Some additional things

When i need to change Connections URLs within LotusConnections-config.xml after adding the webserver to my ISC, i can do this with one line.

Changing Connections URLs

Checkout LotusConnections-config.xml and edit with vim. You will find several links to your application server hostname with WebSphere ports (e.g. http://washost1.example.com:9081). When you use a large deployment you have about 15 application servers with http and https links, so you need to change 30 different urls.

With vim we can use regular expressions to change the urls. Lets change washost1.example.com:anyport to connections.example.com.

Open LotusConnections-config.xml with vim and stay in command mode. Type

:%s/washost1.example.com:9[0-9]*/connections.example.com/g

lc1

  • :%s is search and replace,
  • first part within / / is text which will be replaced
  • [0-9]* any count of a number
  • g global replace (multiple search text in one line)

lc2

Comment out some lines in httpd.conf

I often test things in my IBM HTTP Server Configuration and when i want to comment out some lines or remove the comment signs there is a easy way with vim.

Open httpd.conf and hit Ctrl+V (enters Visual Block mode),

visualblock

now you can mark some characters with j (moves cursor down) or arrow keys:

mark

Now type a capital i -> Shift+i, the cursor jumps back to the first character you marked and you can add text (e.g. “# “):

addcomment

finish the commands with ESC:

commentout

Remove characters in multiple lines

You can remove the comments with nearly the same command.

Open the file, change to visual block mode (ctrl+v), mark the characters with arrow keys and remove with d.

mark2

commentremove