Creating simple tables in vim - vim

Recently I've started discovering "deeper" vim and now I want to create a simple table without using any external plugins (I know it's bad, but I want to have some "know-how").
Let's say I want to have a table like this:
| name | address | phone |
|---------------------------------------------------------|
| John Adams | 1600 Pennsylvania Avenue | 0123456789 |
|---------------------------------------------------------|
| Sherlock Holmes | 221B Baker Street | 0987654321 |
|---------------------------------------------------------|
But how do I manage to make underscores till the end of the longest line and seperate columns with equal width? (In short way, no typing all by hand)

If you know the amount of the dashes needed then you can do:
{number}i-<ESC>
Where {number} is the amount of dashes needed. If you want to "learn" that automatically then you need to use VimL and strlen() function to first learn how many dashes are needed and then you can use append() to insert text below provided line.

Related

Grep for string and read content until next match string

I am trying to read a file and search for a string using grep. Once I find the string, I want to read everything after the string until I match another string. So in my example, I am searching for ...SUMMARY... and I want to read everything until the occurrence of ... Here is an example:
**...SUMMARY...**
Severe thunderstorms are most likely across north-central/northeast
Texas and the Ark-La-Tex region during the late afternoon and
evening. Destructive hail and wind, along with a few tornadoes are
possible. Severe thunderstorms are also expected across the
Mid-South and Ohio Valley.
**...**North-central/northeast TX and southeast OK/ArkLaTex...
In the wake of a decaying MCS across the Lower Mississippi River
Valley, a northwestward-extending outflow boundary will continue to
modify/drift northward with rapid/strong destabilization this
afternoon particularly along and south of it. A quick
reestablishment of lower/some middle 70s F surface dewpoints will
occur into prior-MCS-impacted areas, with MLCAPE in excess of 4000
J/kg expected for parts of north-central/northeast Texas into far
southeast Oklahoma and the nearby ArkLaTex. Special 19Z observed
soundings are expected from Fort Worth/Shreveport to help better
gauge/confirm this destabilization trend and the degree of capping.
I have tried using the following code but only displays the ...SUMMARY... and the next line.
sed -n '/...SUMMARY.../,/.../p'
What can I do to solve this?
=======================================================================
Followup:
This is the result I am trying to get. Only show the paragraph under ...SUMMARY... and end at the next ... so this is what I should get in the end:
Severe thunderstorms are most likely across north-central/northeast
Texas and the Ark-La-Tex region during the late afternoon and
evening. Destructive hail and wind, along with a few tornadoes are
possible. Severe thunderstorms are also expected across the
Mid-South and Ohio Valley.
I have tried the following based on a recommendation Shellter:
sed -n '/...SUMMARY.../,/**...**/p'
But I get everything.
You may use
sed -n '/^[[:blank:]]*\.\.\.SUMMARY\.\.\./,/^[[:blank:]]*\.\.\./{//!p;}' file
See this online sed demo.
NOTES:
Escape literal dots
Literal asterisks should also be escaped, and they are necessary as /.../ just matches a line with any 3 chars
^ matches the start of a line and [[:space:]]* matches any 0+ whitespace chars
{//!p;} gets you the contents between two lines excluding those lines (see How to print lines between two patterns, inclusive or exclusive (in sed, AWK or Perl)?)

Is it possible to stop the NERDTree window resizing when using Ctrl W Equals to make all split window equally sized in Vim?

Usually NERDTree doesn't get resized when I do this. But when I am working with a bunch of horizontal and vertical splits for a while, it can happen.
I don't know what the change in state of within the instance of Vim is that makes this issue happen during a vim session. I'm not sure if the number of splits makes a difference.
Usually I set up 4 splits, along with the NERDTree window on the left like this...
|--|-----|-----|
| | | |
|NT|-----|-----|
| | | |
|--|-----|-----|
When I do the equal split resize I end up with this when things go wrong...
|-----|-----|-----|
| | | |
| NT |-----|-----|
| | | |
|-----|-----|-----|
That's not the end of the world. The real problem is when I close a couple of splits it ends up like this...
|--------|--------|
| | |
| NT |--------|
| | |
|--------|--------|
... which is just silly and I have to exit Vim and start over.
I use Ctrl-w followed by = to carry out the equal resizing of vim splits.
I think this is a bug, perhaps in NERDTree. There is a "change of state" that causes this problem to start happening. It is when you do a Ctrl-w followed by 'o' to maximize one of the splits. I've reported this as an issue in the NERDTree github project at https://github.com/scrooloose/nerdtree/issues/644

How to convert split windows to tabs and vice versa in Vim

For example, I use 3 split windows to open 3 different files:
+---------------+-----------+
| | |
| window 1 | |
| | |
+---------------+ |
| | window 3 |
| | |
| window 2 | |
| | |
| | |
+---------------+-----------+
Now, I want to open them with 3 different tabs and vice versa
Is there any trick to achieve this? Or do I need any plugin?
Besides, if I want to display 3 buffers in 3 full screen windows (as opposed to a split window), what should I do?
Not sure if there is a plugin, which will do all splits at once. But there is a way to do it one at a time
For moving the current split into a new tab use
ctrl + w, T (shift + t)
repeat the above process for all splits.
Now for getting the tab in to split, you can make use of a plugin call "Tabmerge", download Tabmerge.vim from http://www.vim.org/scripts/script.php?script_id=1961 to ~/.vim/plugin
then to merge the tab use :Tabmerge [tab number] [top|bottom|left|right]
If you are careful with your buffer list, you can use :sball and :tab sball to open in windows or tabs, respectively.

Cucumber scenario with quotes in the text

I'd like to have quotes in my scenario data. It's not working when that data has quotes in it. An example modified from The Cucumber Book would be:
Then I should see the "<message>" message
Examples:
| type | message |
| Swiss | I love Swiss cheese |
| Blue | I love "Blue" cheese |
| Cheddar | I love Cheddar cheese |
In my particular case I get an undefined step definition message because of "Blue" in the second scenario above. Is there a way I should be escaping the quotes? (I've tried backslashes but that didn't make any difference.)
My guess is that your current step definition looks like:
Then /I should see the "([^"]+)" message/ do |message|
p message
end
The [^"] tells the regex to match anything except double-quotes. This would be why your "Blue" example does not match.
Given that you are only looking for one argument, it would be safe to do:
Then /I should see the "(.*)" message/ do |message|
p message
end
Using (.*) would match everything between the quotes, including the quotes around Blue.

Pandoc markdown vertical lines in grid

I use Pandoc (http://johnmacfarlane.net/pandoc/README.html) and its Markdown processor. When I convert the grid below to PDF (directly via LaTeX) using Pandoc, there are no vertical lines in PDF. How to obtain them?
+---------------+---------------+--------------------+
| Fruit | Price | Advantages |
+===============+===============+====================+
| Bananas | $1.34 | - built-in wrapper |
| | | - bright color |
+---------------+---------------+--------------------+
| Oranges | $2.10 | - cures scurvy |
| | | - tasty |
+---------------+---------------+--------------------+
There is currently no way to add vertical lines, other than postprocessing pandoc's latex output, according to this bug https://github.com/jgm/pandoc/issues/922#issuecomment-38586467
I don't know of any way to do this directly. The only solution I know is to use pandoc to convert to LaTeX, then edit the table formatting in LaTeX.

Resources