Posts
Vim Delete Alternate Lines
A co-worker was trying to delete alternate lines of a file in vim. He searched online and found this:
:g/^/+d It apparently says, “Globally, on every line, delete the next line”.
If you’re looking for something that is more verbose, here’s the equivalent:
:let i=1 | while i <= line('$') | if (i % 2) | exe i . "delete" | endif | let i += 1 | endwhile
Posts
vim Autocomplete
Pressing Ctrl-n (forward) and Ctrl-p (backwards) gives you word-autocomplete based on words in the current file. When you have multiple matches, choose from the list with arrow cursors and press Ctrl-y or Enter (or use Ctrl-p and Ctrl-n).
Pressing Ctrl-x followed by Ctrl-l gives you line-autocomplete. Use Ctrl-p, Ctrl-n, Ctrl-l, or up/down cursors to move through the list.
vim also provides filename-autocomplete with Ctrl-x followed by Ctrl-f.
Ctrl-e is to cancel the autocomplete.
Posts
vim Variables
Variables are easy to define in Vimscript: let my_variable=something.
They can be used to store user input collected with input('Prompt') (we typically call inputsave() before and inputrestore() after the input).
We can also get confirmations from the user with confirm('Prompt', 'options', 'default'). This returns 1 for Ok and 0 for a non-Ok.
Here’s an example:
call inputsave() let name=input('Name: ') call inputrestore() echo name You can fetch the value of a variable while typing commands by using Ctrl-R followed by the equals sign.
Posts
NoSQL Database Types
NoSQL refers to a class of non-relational databases and, by itself, the term means little because there are different kinds of NoSQL databases. It’s like using the term NoRED colors to refer to any of Green, Blue, Yellow, Orange… you get the idea.
NoSQL databases can be identified as Key-Value stores, Wide-Column stores, Graph stores, and Document stores. Each comes with it’s own set of merits and demerits and has their place.
Posts
Ambiguity SQL and MQL (rant - not tech-related)
…so, I was searching online for blog posts to read about SQL (Structured Query Language) and MQL (MongoDB Query Language), and I see a statement, “the difference between SQL and MQL is the intent to buy.” Wanting to know more about this deep philosophy, I click on the search result and then I begin trying to look at where they talk about databases because, when I start reading, I see a mention about CRM systems.
Posts
Elastic Sql
NoSQL databases generally provide query interfaces of their own, but many also support SQL or provide SQL-like query languages. ElasticSearch (from v6.3) has been supporting SQL queries - this is done by passing a GET request to “/_xpack/sql” with a JSON query body containing the SQL query for the field “query”. This can be mixed with ElasticSearch native query filtering. In addition, sending the query to “_xpack/sql/translate” provides the ElasticSearch native query equivalent.
Posts
Bash Options
Bash can save you a bit of typing when you are working with directories - instead of typing “cd” followed by the directory name, you can set the “autocd” option with shopt -s autocd and you can type only the directory name to enter it. Run shopt with the -u flag to unset.
Bash can also be forgiving when it comes to the spellings of the directory names. Enable the cdspell to auto-correct the directory name in “cd” commands.
Posts
Bash Double Hyphen
We often see commands posted online that use a double-hyphen (–). Many shell commands (the ones using getopt to fetch command-line options) support the use of this double-hyphen to stop further processing of command-line flags. This is useful when we want to specify a literal hyphen, and to prevent accidental injection of command line options.
For example, try this:
touch -f In the above example, touch assumes that “-f” is a command line flag.
Posts
Vim Echo vs Echom vs EchoErr
If all you do in your Vim scripts is echo, the echo will fall on deaf ears pretty quickly because it will soon be overwritten by the next echo. Fortunately, Vim has “echom” which works in exactly the same way except that the output is saved into messages (accessed with :messages ). echoerr goes a step further than echom by highlighting the text as an error message.
The echo commands are not persistent across Vim sessions.
Posts
Vim Maps
You can have up to 26 Vim macros, one for each letter of the alphabet. It is limiting, which is when you can use maps instead. Maps can be defined for specific modes. For example :map a1 :d3<CR> works in normal mode; if you add an exclamantion mark to the map command, it works in insert mode :map! <F2> <ESC>:d2<CR>i
See more at: https://vim.fandom.com/wiki/Mapping_keys_in_Vim_-Tutorial(Part_1)