CSV to SQL
Before
id 1,Item 1,cost 1,location 1
id 2,Item 2,cost 2,location 2
id 10,Item 10,cost 10,location 10
After
INSERT INTO `database`.`table` (`id` ,`item` ,`cost` ,`location`) VALUES ('id 1','Item 1','cost 1','Location 1');
INSERT INTO `database`.`table` (`id` ,`item` ,`cost` ,`location`) VALUES ('id 2','Item 2','cost 2','Location 2');
INSERT INTO `database`.`table` (`id` ,`item` ,`cost` ,`location`) VALUES ('id 10','Item 10','cost 10','Location 10');
Preview
Command
%<alt-s>"yys\d<enter>
dhhbms
``x_ms(IINSERT INTO `
database<esc>
a.`table<esc>la <esc>
AVALUES (<esc>
"yPS,<enter>ms'A;<esc>Fl;~
-
%selects full file -
<alt-s>split selection into multiple selections on newlines -
"yyyanks the selections into "y" register. We'll need it for later -
sand then input the pattern\dthen<enter>which creates a selection on all digits -
ddeletes the selections. Essentially we've removed all the digits. -
hhgoes backwards 2 chars, important to make sure we are at the end of each word -
Use
bto select till the beginning of every word, which also nicely selects all the words that there are -
ms`surrounds each word with a backtick -
`switches all characters to lowercase -
xselects each line then use_to trim the trailing whitespace -
ms(surrounds each line with parentheses -
Igoes into insert mode at the beginning of each line -
Type the following:
INSERT INTO `database -
<esc>goes back to normal mode -
ato go into insert mode after the backtick then type:.`table -
<esc>goes back into normal mode, thenlato enter insert mode just before the opening parentheses -
Add a space
then<esc>to go back into normal mode again -
Agoes into insert mode at the end of each line, now type:VALUES ( -
Hit
<esc>to leave insert mode. Your cursor will be at the closing parenthesis. -
"yPpastes our previously yanked items from the "y" register -
S,<enter>splits current selection into multiple selections on each comma -
ms'surrounds each item with a single quote -
A;adds a semicolon at the end of each line -
<esc>goes back to normal mode andFlto place your cursor on the lowercase "l" of each "location" -
;collapses each selection into a single-width selection -
~toggles the case for each "l" into "L"