We’re hiring. Write for Howchoo
We’re hiring. Write for Howchoo
We’re hiring. Write for Howchoo
We’re hiring. Write for Howchoo
Learn how to split a string into an array.
Posted in these interests:
The split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.
var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 falseLearn how to split a string into an array.
Posted in these interests:
The split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.
var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 falseLearn how to split a string into an array.
Posted in these interests:
The split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.
var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 falseLearn how to split a string into an array.
Posted in these interests:
Posted in these interests:
The split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.
var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 falseThe split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.
var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 falseThe split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.
var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 falseWant to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
I find Vim to be very useful in my daily development activities. I was delighted to learn that you can have your own key mappings in Vim. It is documented very well in the vim help section. But if you want a quick gist of what is available this post is for you.
I am picking a simple example from the vim help documentation itself so you can quickly understand what is going on. Suppose you want a quick way of inserting today’s date below your current cursor position. EG:
cursor was here| "Now hitting leader followed by 2 d keys will print the line below
Date: Tue Mar 17 16:11:47 IST 2015
Here is the mapping you can define in your ~/.vimrc
map dd oDate: :read !datekJ
I will try to break down what the above key mapping does does in the steps below. Note Leader is mapped to ** by default. You can optionally change it to any other key. Spacebar** is a good option which can be achieved with the following mapping in my ~/.vimrc file
let mapleader = " "
You can define custom mappings in ~/.vimrc so that they are permanent across your vim sessions. To define mappings for your current session you can type
:map dd oDate: :read !datekJ
which will save your mapping for the current session. If you define new mapping in your ~/.vimrc, you may need to run
source ~/.vimrc
in your current shell for your new mappings to reflect.
In the above example we trigger our key mapping by typing dd in normal mode. Key mappings can be defined for different modes as listed below
:map Normal, Visual and Operator-pending
:vmap Visual
:nmap Normal
:omap Operator-pending (Eg: dw where d is operator character and w is motion character)
:map! Insert and Command-line
:imap Insert
:cmap Command-lineOnce we trigger our custom key binding we ask it to perform some commands. In this case
oDate: :read !datekJ
The break down
o -> Insert a line below current cursor position and switch to insert mode
Date -> Type the text "Date"
-> Bring us out of insert mode and into normal mode
: -> This character takes vim to the command line where you can execute commands
read -> Vim command to Insert output below the cursor(typically from a file) (:help :read)
!date -> ! is a way to execute a shell command in vim. eg: try !ls
-> This is like hitting enter. (:help key-notation)
What the above commands does is print the following output below the current cursor position
cursor was here
2 Date:
Tue Mar 17 16:11:47 IST 2015
Now the kJ do the following
k -> Move the cursor up by one line
J -> Join the lines together
Final output:
cursor was here
2 Date: Tue Mar 17 16:11:47 IST 2015You can get a similar shortcut in insert mode with the following mappings.
imap dd Date: :read !datekJA
Slight difference here
Date: -> Since already in insert mode type enter to go to next line and then type Date.
-> Bring us out of insert mode and read the date as before
To bring us back to insert mode we finish with A in the end. Note Based on feedback, I learnt that mapping in insert mode has a drawback. For example if you type
This is today's date dd
Date: Wed Mar 18 11:23:09 IST 2015
This prints the date below. But if you hit undo u it deletes the entire text inxluding This is today’s date unless you switched to normal mode first. So good to remember that.
Based on some feedback, I learnt that there is a key difference between map and noremap noremap is an option that prevents mapping recursively. Consider these mappings
map a $
map T a
noremap M a
Here typing a will take you to the end of the line. T will do the same. However M will behave as a and let you append from current cursor position. So it is always recommended to use non recursive versions of mappings to not get caught in unexpected recursive maps. So generally user
nnoremap, xnoremap, cnoremap, inoremap, etc.
unless know you know what you are doing.
I often need to insert logging statements in my code for debugging purposes. The following mapping will help me easily do that, then get my cursor ready to start typing my debug statements.
noremap db ologging.debug("")hi
inoremap db logging.debug("")hi
So hitting
db will print
logging.debug("|")
with my cursor ready to type between the debug quotes.
Sometimes you have some plugins with your vim setup that already define a ton of mappings. You can use
:map
:noremap
and
:imap
:inoremap
to list all your command and insert mode mappings. Similarly you can list your other mode mappings with corresponding commands.
Ensure you are not overlapping with existing mappings or existing vim commands so that your current functionality does not break. Example mapping my command to dd instead of dd would mess up my delete line functionality. Also ensure you have your key mappings in the mode that you want them in.
You can find more details about key mapping in vim documentation itself.
:help key-mappings
:help 40.1
:help map-overview
Let me know if you have any comments or suggestions in the comments below and of any cool ways you use custom key mappings. Hope you learnt something new today.
I find Vim to be very useful in my daily development activities. I was delighted to learn that you can have your own key mappings in Vim. It is documented very well in the vim help section. But if you want a quick gist of what is available this post is for you.
I am picking a simple example from the vim help documentation itself so you can quickly understand what is going on. Suppose you want a quick way of inserting today’s date below your current cursor position. EG:
cursor was here| "Now hitting leader followed by 2 d keys will print the line below
Date: Tue Mar 17 16:11:47 IST 2015
Here is the mapping you can define in your ~/.vimrc
map dd oDate: :read !datekJ
I will try to break down what the above key mapping does does in the steps below. Note Leader is mapped to ** by default. You can optionally change it to any other key. Spacebar** is a good option which can be achieved with the following mapping in my ~/.vimrc file
let mapleader = " "
You can define custom mappings in ~/.vimrc so that they are permanent across your vim sessions. To define mappings for your current session you can type
:map dd oDate: :read !datekJ
which will save your mapping for the current session. If you define new mapping in your ~/.vimrc, you may need to run
source ~/.vimrc
in your current shell for your new mappings to reflect.
In the above example we trigger our key mapping by typing dd in normal mode. Key mappings can be defined for different modes as listed below
:map Normal, Visual and Operator-pending
:vmap Visual
:nmap Normal
:omap Operator-pending (Eg: dw where d is operator character and w is motion character)
:map! Insert and Command-line
:imap Insert
:cmap Command-lineOnce we trigger our custom key binding we ask it to perform some commands. In this case
oDate: :read !datekJ
The break down
o -> Insert a line below current cursor position and switch to insert mode
Date -> Type the text "Date"
-> Bring us out of insert mode and into normal mode
: -> This character takes vim to the command line where you can execute commands
read -> Vim command to Insert output below the cursor(typically from a file) (:help :read)
!date -> ! is a way to execute a shell command in vim. eg: try !ls
-> This is like hitting enter. (:help key-notation)
What the above commands does is print the following output below the current cursor position
cursor was here
2 Date:
Tue Mar 17 16:11:47 IST 2015
Now the kJ do the following
k -> Move the cursor up by one line
J -> Join the lines together
Final output:
cursor was here
2 Date: Tue Mar 17 16:11:47 IST 2015You can get a similar shortcut in insert mode with the following mappings.
imap dd Date: :read !datekJA
Slight difference here
Date: -> Since already in insert mode type enter to go to next line and then type Date.
-> Bring us out of insert mode and read the date as before
To bring us back to insert mode we finish with A in the end. Note Based on feedback, I learnt that mapping in insert mode has a drawback. For example if you type
This is today's date dd
Date: Wed Mar 18 11:23:09 IST 2015
This prints the date below. But if you hit undo u it deletes the entire text inxluding This is today’s date unless you switched to normal mode first. So good to remember that.
Based on some feedback, I learnt that there is a key difference between map and noremap noremap is an option that prevents mapping recursively. Consider these mappings
map a $
map T a
noremap M a
Here typing a will take you to the end of the line. T will do the same. However M will behave as a and let you append from current cursor position. So it is always recommended to use non recursive versions of mappings to not get caught in unexpected recursive maps. So generally user
nnoremap, xnoremap, cnoremap, inoremap, etc.
unless know you know what you are doing.
I often need to insert logging statements in my code for debugging purposes. The following mapping will help me easily do that, then get my cursor ready to start typing my debug statements.
noremap db ologging.debug("")hi
inoremap db logging.debug("")hi
So hitting
db will print
logging.debug("|")
with my cursor ready to type between the debug quotes.
Sometimes you have some plugins with your vim setup that already define a ton of mappings. You can use
:map
:noremap
and
:imap
:inoremap
to list all your command and insert mode mappings. Similarly you can list your other mode mappings with corresponding commands.
Ensure you are not overlapping with existing mappings or existing vim commands so that your current functionality does not break. Example mapping my command to dd instead of dd would mess up my delete line functionality. Also ensure you have your key mappings in the mode that you want them in.
You can find more details about key mapping in vim documentation itself.
:help key-mappings
:help 40.1
:help map-overview
Let me know if you have any comments or suggestions in the comments below and of any cool ways you use custom key mappings. Hope you learnt something new today.
I find Vim to be very useful in my daily development activities. I was delighted to learn that you can have your own key mappings in Vim. It is documented very well in the vim help section. But if you want a quick gist of what is available this post is for you.
I am picking a simple example from the vim help documentation itself so you can quickly understand what is going on. Suppose you want a quick way of inserting today’s date below your current cursor position. EG:
cursor was here| "Now hitting leader followed by 2 d keys will print the line below
Date: Tue Mar 17 16:11:47 IST 2015
Here is the mapping you can define in your ~/.vimrc
map dd oDate: :read !datekJ
I will try to break down what the above key mapping does does in the steps below. Note Leader is mapped to ** by default. You can optionally change it to any other key. Spacebar** is a good option which can be achieved with the following mapping in my ~/.vimrc file
let mapleader = " "
You can define custom mappings in ~/.vimrc so that they are permanent across your vim sessions. To define mappings for your current session you can type
:map dd oDate: :read !datekJ
which will save your mapping for the current session. If you define new mapping in your ~/.vimrc, you may need to run
source ~/.vimrc
in your current shell for your new mappings to reflect.
In the above example we trigger our key mapping by typing dd in normal mode. Key mappings can be defined for different modes as listed below
:map Normal, Visual and Operator-pending
:vmap Visual
:nmap Normal
:omap Operator-pending (Eg: dw where d is operator character and w is motion character)
:map! Insert and Command-line
:imap Insert
:cmap Command-lineOnce we trigger our custom key binding we ask it to perform some commands. In this case
oDate: :read !datekJ
The break down
o -> Insert a line below current cursor position and switch to insert mode
Date -> Type the text "Date"
-> Bring us out of insert mode and into normal mode
: -> This character takes vim to the command line where you can execute commands
read -> Vim command to Insert output below the cursor(typically from a file) (:help :read)
!date -> ! is a way to execute a shell command in vim. eg: try !ls
-> This is like hitting enter. (:help key-notation)
What the above commands does is print the following output below the current cursor position
cursor was here
2 Date:
Tue Mar 17 16:11:47 IST 2015
Now the kJ do the following
k -> Move the cursor up by one line
J -> Join the lines together
Final output:
cursor was here
2 Date: Tue Mar 17 16:11:47 IST 2015You can get a similar shortcut in insert mode with the following mappings.
imap dd Date: :read !datekJA
Slight difference here
Date: -> Since already in insert mode type enter to go to next line and then type Date.
-> Bring us out of insert mode and read the date as before
To bring us back to insert mode we finish with A in the end. Note Based on feedback, I learnt that mapping in insert mode has a drawback. For example if you type
This is today's date dd
Date: Wed Mar 18 11:23:09 IST 2015
This prints the date below. But if you hit undo u it deletes the entire text inxluding This is today’s date unless you switched to normal mode first. So good to remember that.
Based on some feedback, I learnt that there is a key difference between map and noremap noremap is an option that prevents mapping recursively. Consider these mappings
map a $
map T a
noremap M a
Here typing a will take you to the end of the line. T will do the same. However M will behave as a and let you append from current cursor position. So it is always recommended to use non recursive versions of mappings to not get caught in unexpected recursive maps. So generally user
nnoremap, xnoremap, cnoremap, inoremap, etc.
unless know you know what you are doing.
I often need to insert logging statements in my code for debugging purposes. The following mapping will help me easily do that, then get my cursor ready to start typing my debug statements.
noremap db ologging.debug("")hi
inoremap db logging.debug("")hi
So hitting
db will print
logging.debug("|")
with my cursor ready to type between the debug quotes.
Sometimes you have some plugins with your vim setup that already define a ton of mappings. You can use
:map
:noremap
and
:imap
:inoremap
to list all your command and insert mode mappings. Similarly you can list your other mode mappings with corresponding commands.
Ensure you are not overlapping with existing mappings or existing vim commands so that your current functionality does not break. Example mapping my command to dd instead of dd would mess up my delete line functionality. Also ensure you have your key mappings in the mode that you want them in.
You can find more details about key mapping in vim documentation itself.
:help key-mappings
:help 40.1
:help map-overview
Let me know if you have any comments or suggestions in the comments below and of any cool ways you use custom key mappings. Hope you learnt something new today.
I find Vim to be very useful in my daily development activities. I was delighted to learn that you can have your own key mappings in Vim. It is documented very well in the vim help section. But if you want a quick gist of what is available this post is for you.
I am picking a simple example from the vim help documentation itself so you can quickly understand what is going on. Suppose you want a quick way of inserting today’s date below your current cursor position. EG:
cursor was here| "Now hitting leader followed by 2 d keys will print the line below
Date: Tue Mar 17 16:11:47 IST 2015
Here is the mapping you can define in your ~/.vimrc
map dd oDate: :read !datekJ
I will try to break down what the above key mapping does does in the steps below. Note Leader is mapped to ** by default. You can optionally change it to any other key. Spacebar** is a good option which can be achieved with the following mapping in my ~/.vimrc file
let mapleader = " "
You can define custom mappings in ~/.vimrc so that they are permanent across your vim sessions. To define mappings for your current session you can type
:map dd oDate: :read !datekJ
which will save your mapping for the current session. If you define new mapping in your ~/.vimrc, you may need to run
source ~/.vimrc
in your current shell for your new mappings to reflect.
In the above example we trigger our key mapping by typing dd in normal mode. Key mappings can be defined for different modes as listed below
:map Normal, Visual and Operator-pending
:vmap Visual
:nmap Normal
:omap Operator-pending (Eg: dw where d is operator character and w is motion character)
:map! Insert and Command-line
:imap Insert
:cmap Command-lineOnce we trigger our custom key binding we ask it to perform some commands. In this case
oDate: :read !datekJ
The break down
o -> Insert a line below current cursor position and switch to insert mode
Date -> Type the text "Date"
-> Bring us out of insert mode and into normal mode
: -> This character takes vim to the command line where you can execute commands
read -> Vim command to Insert output below the cursor(typically from a file) (:help :read)
!date -> ! is a way to execute a shell command in vim. eg: try !ls
-> This is like hitting enter. (:help key-notation)
What the above commands does is print the following output below the current cursor position
cursor was here
2 Date:
Tue Mar 17 16:11:47 IST 2015
Now the kJ do the following
k -> Move the cursor up by one line
J -> Join the lines together
Final output:
cursor was here
2 Date: Tue Mar 17 16:11:47 IST 2015You can get a similar shortcut in insert mode with the following mappings.
imap dd Date: :read !datekJA
Slight difference here
Date: -> Since already in insert mode type enter to go to next line and then type Date.
-> Bring us out of insert mode and read the date as before
To bring us back to insert mode we finish with A in the end. Note Based on feedback, I learnt that mapping in insert mode has a drawback. For example if you type
This is today's date dd
Date: Wed Mar 18 11:23:09 IST 2015
This prints the date below. But if you hit undo u it deletes the entire text inxluding This is today’s date unless you switched to normal mode first. So good to remember that.
Based on some feedback, I learnt that there is a key difference between map and noremap noremap is an option that prevents mapping recursively. Consider these mappings
map a $
map T a
noremap M a
Here typing a will take you to the end of the line. T will do the same. However M will behave as a and let you append from current cursor position. So it is always recommended to use non recursive versions of mappings to not get caught in unexpected recursive maps. So generally user
nnoremap, xnoremap, cnoremap, inoremap, etc.
unless know you know what you are doing.
I often need to insert logging statements in my code for debugging purposes. The following mapping will help me easily do that, then get my cursor ready to start typing my debug statements.
noremap db ologging.debug("")hi
inoremap db logging.debug("")hi
So hitting
db will print
logging.debug("|")
with my cursor ready to type between the debug quotes.
Sometimes you have some plugins with your vim setup that already define a ton of mappings. You can use
:map
:noremap
and
:imap
:inoremap
to list all your command and insert mode mappings. Similarly you can list your other mode mappings with corresponding commands.
Ensure you are not overlapping with existing mappings or existing vim commands so that your current functionality does not break. Example mapping my command to dd instead of dd would mess up my delete line functionality. Also ensure you have your key mappings in the mode that you want them in.
You can find more details about key mapping in vim documentation itself.
:help key-mappings
:help 40.1
:help map-overview
Let me know if you have any comments or suggestions in the comments below and of any cool ways you use custom key mappings. Hope you learnt something new today.
I am picking a simple example from the vim help documentation itself so you can quickly understand what is going on. Suppose you want a quick way of inserting today’s date below your current cursor position. EG:
cursor was here| "Now hitting leader followed by 2 d keys will print the line below
Date: Tue Mar 17 16:11:47 IST 2015
Here is the mapping you can define in your ~/.vimrc
map dd oDate: :read !datekJ
I will try to break down what the above key mapping does does in the steps below. Note Leader is mapped to ** by default. You can optionally change it to any other key. Spacebar** is a good option which can be achieved with the following mapping in my ~/.vimrc file
let mapleader = " "
You can define custom mappings in ~/.vimrc so that they are permanent across your vim sessions. To define mappings for your current session you can type
:map dd oDate: :read !datekJ
which will save your mapping for the current session. If you define new mapping in your ~/.vimrc, you may need to run
source ~/.vimrc
in your current shell for your new mappings to reflect.
I am picking a simple example from the vim help documentation itself so you can quickly understand what is going on. Suppose you want a quick way of inserting today’s date below your current cursor position. EG:
cursor was here| "Now hitting leader followed by 2 d keys will print the line below
Date: Tue Mar 17 16:11:47 IST 2015
Here is the mapping you can define in your ~/.vimrc
map dd oDate: :read !datekJ
I will try to break down what the above key mapping does does in the steps below. Note Leader is mapped to ** by default. You can optionally change it to any other key. Spacebar** is a good option which can be achieved with the following mapping in my ~/.vimrc file
let mapleader = " "
You can define custom mappings in ~/.vimrc so that they are permanent across your vim sessions. To define mappings for your current session you can type
:map dd oDate: :read !datekJ
which will save your mapping for the current session. If you define new mapping in your ~/.vimrc, you may need to run
source ~/.vimrc
in your current shell for your new mappings to reflect.
In the above example we trigger our key mapping by typing dd in normal mode. Key mappings can be defined for different modes as listed below
:map Normal, Visual and Operator-pending
:vmap Visual
:nmap Normal
:omap Operator-pending (Eg: dw where d is operator character and w is motion character)
:map! Insert and Command-line
:imap Insert
:cmap Command-lineIn the above example we trigger our key mapping by typing dd in normal mode. Key mappings can be defined for different modes as listed below
:map Normal, Visual and Operator-pending
:vmap Visual
:nmap Normal
:omap Operator-pending (Eg: dw where d is operator character and w is motion character)
:map! Insert and Command-line
:imap Insert
:cmap Command-lineOnce we trigger our custom key binding we ask it to perform some commands. In this case
oDate: :read !datekJ
The break down
o -> Insert a line below current cursor position and switch to insert mode
Date -> Type the text "Date"
-> Bring us out of insert mode and into normal mode
: -> This character takes vim to the command line where you can execute commands
read -> Vim command to Insert output below the cursor(typically from a file) (:help :read)
!date -> ! is a way to execute a shell command in vim. eg: try !ls
-> This is like hitting enter. (:help key-notation)
What the above commands does is print the following output below the current cursor position
cursor was here
2 Date:
Tue Mar 17 16:11:47 IST 2015
Now the kJ do the following
k -> Move the cursor up by one line
J -> Join the lines together
Final output:
cursor was here
2 Date: Tue Mar 17 16:11:47 IST 2015Once we trigger our custom key binding we ask it to perform some commands. In this case
oDate: :read !datekJ
The break down
o -> Insert a line below current cursor position and switch to insert mode
Date -> Type the text "Date"
-> Bring us out of insert mode and into normal mode
: -> This character takes vim to the command line where you can execute commands
read -> Vim command to Insert output below the cursor(typically from a file) (:help :read)
!date -> ! is a way to execute a shell command in vim. eg: try !ls
-> This is like hitting enter. (:help key-notation)
What the above commands does is print the following output below the current cursor position
cursor was here
2 Date:
Tue Mar 17 16:11:47 IST 2015
Now the kJ do the following
k -> Move the cursor up by one line
J -> Join the lines together
Final output:
cursor was here
2 Date: Tue Mar 17 16:11:47 IST 2015You can get a similar shortcut in insert mode with the following mappings.
imap dd Date: :read !datekJA
Slight difference here
Date: -> Since already in insert mode type enter to go to next line and then type Date.
-> Bring us out of insert mode and read the date as before
To bring us back to insert mode we finish with A in the end. Note Based on feedback, I learnt that mapping in insert mode has a drawback. For example if you type
This is today's date dd
Date: Wed Mar 18 11:23:09 IST 2015
This prints the date below. But if you hit undo u it deletes the entire text inxluding This is today’s date unless you switched to normal mode first. So good to remember that.
You can get a similar shortcut in insert mode with the following mappings.
imap dd Date: :read !datekJA
Slight difference here
Date: -> Since already in insert mode type enter to go to next line and then type Date.
-> Bring us out of insert mode and read the date as before
To bring us back to insert mode we finish with A in the end. Note Based on feedback, I learnt that mapping in insert mode has a drawback. For example if you type
This is today's date dd
Date: Wed Mar 18 11:23:09 IST 2015
This prints the date below. But if you hit undo u it deletes the entire text inxluding This is today’s date unless you switched to normal mode first. So good to remember that.
Based on some feedback, I learnt that there is a key difference between map and noremap noremap is an option that prevents mapping recursively. Consider these mappings
map a $
map T a
noremap M a
Here typing a will take you to the end of the line. T will do the same. However M will behave as a and let you append from current cursor position. So it is always recommended to use non recursive versions of mappings to not get caught in unexpected recursive maps. So generally user
nnoremap, xnoremap, cnoremap, inoremap, etc.
unless know you know what you are doing.
Based on some feedback, I learnt that there is a key difference between map and noremap noremap is an option that prevents mapping recursively. Consider these mappings
map a $
map T a
noremap M a
Here typing a will take you to the end of the line. T will do the same. However M will behave as a and let you append from current cursor position. So it is always recommended to use non recursive versions of mappings to not get caught in unexpected recursive maps. So generally user
nnoremap, xnoremap, cnoremap, inoremap, etc.
unless know you know what you are doing.
I often need to insert logging statements in my code for debugging purposes. The following mapping will help me easily do that, then get my cursor ready to start typing my debug statements.
noremap db ologging.debug("")hi
inoremap db logging.debug("")hi
So hitting
db will print
logging.debug("|")
with my cursor ready to type between the debug quotes.
I often need to insert logging statements in my code for debugging purposes. The following mapping will help me easily do that, then get my cursor ready to start typing my debug statements.
noremap db ologging.debug("")hi
inoremap db logging.debug("")hi
So hitting
db will print
logging.debug("|")
with my cursor ready to type between the debug quotes.
Sometimes you have some plugins with your vim setup that already define a ton of mappings. You can use
:map
:noremap
and
:imap
:inoremap
to list all your command and insert mode mappings. Similarly you can list your other mode mappings with corresponding commands.
Sometimes you have some plugins with your vim setup that already define a ton of mappings. You can use
:map
:noremap
and
:imap
:inoremap
to list all your command and insert mode mappings. Similarly you can list your other mode mappings with corresponding commands.
Ensure you are not overlapping with existing mappings or existing vim commands so that your current functionality does not break. Example mapping my command to dd instead of dd would mess up my delete line functionality. Also ensure you have your key mappings in the mode that you want them in.
Ensure you are not overlapping with existing mappings or existing vim commands so that your current functionality does not break. Example mapping my command to dd instead of dd would mess up my delete line functionality. Also ensure you have your key mappings in the mode that you want them in.
You can find more details about key mapping in vim documentation itself.
:help key-mappings
:help 40.1
:help map-overview
Let me know if you have any comments or suggestions in the comments below and of any cool ways you use custom key mappings. Hope you learnt something new today.
You can find more details about key mapping in vim documentation itself.
:help key-mappings
:help 40.1
:help map-overview
Let me know if you have any comments or suggestions in the comments below and of any cool ways you use custom key mappings. Hope you learnt something new today.
Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications. AppleScript is a scripting language created by Apple that allows us to automate control of Mac applications, and osascript is a tool that allows us to execute AppleScript from the command line.
With these tools, we can easily display macOS notifications from the command line or from within shell scripts.
The display command can be run like this:
display notification "test notification!" But if we want to execute this from the command line, we need to use osascript with the -e flag.
osascript -e 'display notification "test notification!"' osascript -e 'display notification "test notification!" with title "This is the title"' Run any of these examples from the Terminal application (or your favorite terminal emulator), and you’ll see the notifications appear!
In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications. AppleScript is a scripting language created by Apple that allows us to automate control of Mac applications, and osascript is a tool that allows us to execute AppleScript from the command line.
With these tools, we can easily display macOS notifications from the command line or from within shell scripts.
The display command can be run like this:
display notification "test notification!" But if we want to execute this from the command line, we need to use osascript with the -e flag.
osascript -e 'display notification "test notification!"' osascript -e 'display notification "test notification!" with title "This is the title"' Run any of these examples from the Terminal application (or your favorite terminal emulator), and you’ll see the notifications appear!
In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications. AppleScript is a scripting language created by Apple that allows us to automate control of Mac applications, and osascript is a tool that allows us to execute AppleScript from the command line.
With these tools, we can easily display macOS notifications from the command line or from within shell scripts.
The display command can be run like this:
display notification "test notification!" But if we want to execute this from the command line, we need to use osascript with the -e flag.
osascript -e 'display notification "test notification!"' osascript -e 'display notification "test notification!" with title "This is the title"' Run any of these examples from the Terminal application (or your favorite terminal emulator), and you’ll see the notifications appear!
In this guide, we’re going to use AppleScript and a tool called osascript to display macOS notifications. AppleScript is a scripting language created by Apple that allows us to automate control of Mac applications, and osascript is a tool that allows us to execute AppleScript from the command line.
With these tools, we can easily display macOS notifications from the command line or from within shell scripts.
The display command can be run like this:
display notification "test notification!" But if we want to execute this from the command line, we need to use osascript with the -e flag.
osascript -e 'display notification "test notification!"' osascript -e 'display notification "test notification!" with title "This is the title"' Run any of these examples from the Terminal application (or your favorite terminal emulator), and you’ll see the notifications appear!
The display command can be run like this:
display notification "test notification!" But if we want to execute this from the command line, we need to use osascript with the -e flag.
osascript -e 'display notification "test notification!"' osascript -e 'display notification "test notification!" with title "This is the title"' Run any of these examples from the Terminal application (or your favorite terminal emulator), and you’ll see the notifications appear!
The display command can be run like this:
display notification "test notification!" But if we want to execute this from the command line, we need to use osascript with the -e flag.
osascript -e 'display notification "test notification!"' osascript -e 'display notification "test notification!" with title "This is the title"' Run any of these examples from the Terminal application (or your favorite terminal emulator), and you’ll see the notifications appear!


Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
At some point you’ll want to read, set, and remove cookies using JavaScript. This is actually way more complicated than it should be so I’ll provide a few example functions and refer you to a solid jQuery plugin.
Posted in these interests:
First you should understand what the cookie is and how it’s set. A cookie is a string that is stored on the user’s computer to allow data to persist throughout the user’s session. Cookies are often set by HTTP response headers, but they can also be set directly in the browser using JavaScript. To read the entire cookie string you can access document.cookie.
document.cookie What you’ll likely see is a long string of semi-colon delineated key/value pairs. ps=31;_ssd3=P0-1415818163-1436218393727;favorite_animal=goat;_gaa=23.00334.....You can manually set a cookie by setting document.cookie equal to the desired cookie using this format:
document.cookie = "name=tyler;expires=Thu, 03 Sep 2015 05:33:44 GMT"; This can be a little cumbersome, so the function below should make things easier. function setCookie(name, value, exdays) { var d, expires; exdays = exdays || 1; d = new Date(); d.setTime(d.getTime() + (exdays2460601000)); expires = "expires=" + d.toUTCString(); document.cookie = name + "=" + value + "; " + expires; } To set a cookie that lasts for one year, you could use: setCookie('name', 'Batman', 365);To read a cookie you can simply access document.cookie.
console.log(document.cookie); If you’re searching for a specific value you can use the following function. function getCookie(name) { var cookie, c; cookies = document.cookie.split(';'); for (var i=0; i < cookies.length; i++) { c = cookies[i].split('='); if (c[0] == name) { return c[1]; } } return ""; } This function uses JavaScript’s string split method to split the cookie string by semi-colons. Then it loops through the result array of strings and splits them again by “=” producing the cookie key/value pair. Then it simply tests the cookie key (c[0]) against the name of the cookie you are trying to read. If it matches it returns the value (c[1]). To delete a cookie, you simply need to expire it. So deleting a cookie is basically setting the cookie with an expiration in the past. Using our setCookie function:
setCookie('name', '', -1);If you’re using jQuery, you might as well use this cookie plugin. It allows easy management of cookies.
// read $.cookie('name'); // => "Batman" // set $.cookie('name', 'Iron Man'); // delete $.removeCookie('name');At some point you’ll want to read, set, and remove cookies using JavaScript. This is actually way more complicated than it should be so I’ll provide a few example functions and refer you to a solid jQuery plugin.
Posted in these interests:
First you should understand what the cookie is and how it’s set. A cookie is a string that is stored on the user’s computer to allow data to persist throughout the user’s session. Cookies are often set by HTTP response headers, but they can also be set directly in the browser using JavaScript. To read the entire cookie string you can access document.cookie.
document.cookie What you’ll likely see is a long string of semi-colon delineated key/value pairs. ps=31;_ssd3=P0-1415818163-1436218393727;favorite_animal=goat;_gaa=23.00334.....You can manually set a cookie by setting document.cookie equal to the desired cookie using this format:
document.cookie = "name=tyler;expires=Thu, 03 Sep 2015 05:33:44 GMT"; This can be a little cumbersome, so the function below should make things easier. function setCookie(name, value, exdays) { var d, expires; exdays = exdays || 1; d = new Date(); d.setTime(d.getTime() + (exdays2460601000)); expires = "expires=" + d.toUTCString(); document.cookie = name + "=" + value + "; " + expires; } To set a cookie that lasts for one year, you could use: setCookie('name', 'Batman', 365);To read a cookie you can simply access document.cookie.
console.log(document.cookie); If you’re searching for a specific value you can use the following function. function getCookie(name) { var cookie, c; cookies = document.cookie.split(';'); for (var i=0; i < cookies.length; i++) { c = cookies[i].split('='); if (c[0] == name) { return c[1]; } } return ""; } This function uses JavaScript’s string split method to split the cookie string by semi-colons. Then it loops through the result array of strings and splits them again by “=” producing the cookie key/value pair. Then it simply tests the cookie key (c[0]) against the name of the cookie you are trying to read. If it matches it returns the value (c[1]). To delete a cookie, you simply need to expire it. So deleting a cookie is basically setting the cookie with an expiration in the past. Using our setCookie function:
setCookie('name', '', -1);If you’re using jQuery, you might as well use this cookie plugin. It allows easy management of cookies.
// read $.cookie('name'); // => "Batman" // set $.cookie('name', 'Iron Man'); // delete $.removeCookie('name');At some point you’ll want to read, set, and remove cookies using JavaScript. This is actually way more complicated than it should be so I’ll provide a few example functions and refer you to a solid jQuery plugin.
Posted in these interests:
First you should understand what the cookie is and how it’s set. A cookie is a string that is stored on the user’s computer to allow data to persist throughout the user’s session. Cookies are often set by HTTP response headers, but they can also be set directly in the browser using JavaScript. To read the entire cookie string you can access document.cookie.
document.cookie What you’ll likely see is a long string of semi-colon delineated key/value pairs. ps=31;_ssd3=P0-1415818163-1436218393727;favorite_animal=goat;_gaa=23.00334.....You can manually set a cookie by setting document.cookie equal to the desired cookie using this format:
document.cookie = "name=tyler;expires=Thu, 03 Sep 2015 05:33:44 GMT"; This can be a little cumbersome, so the function below should make things easier. function setCookie(name, value, exdays) { var d, expires; exdays = exdays || 1; d = new Date(); d.setTime(d.getTime() + (exdays2460601000)); expires = "expires=" + d.toUTCString(); document.cookie = name + "=" + value + "; " + expires; } To set a cookie that lasts for one year, you could use: setCookie('name', 'Batman', 365);To read a cookie you can simply access document.cookie.
console.log(document.cookie); If you’re searching for a specific value you can use the following function. function getCookie(name) { var cookie, c; cookies = document.cookie.split(';'); for (var i=0; i < cookies.length; i++) { c = cookies[i].split('='); if (c[0] == name) { return c[1]; } } return ""; } This function uses JavaScript’s string split method to split the cookie string by semi-colons. Then it loops through the result array of strings and splits them again by “=” producing the cookie key/value pair. Then it simply tests the cookie key (c[0]) against the name of the cookie you are trying to read. If it matches it returns the value (c[1]). To delete a cookie, you simply need to expire it. So deleting a cookie is basically setting the cookie with an expiration in the past. Using our setCookie function:
setCookie('name', '', -1);If you’re using jQuery, you might as well use this cookie plugin. It allows easy management of cookies.
// read $.cookie('name'); // => "Batman" // set $.cookie('name', 'Iron Man'); // delete $.removeCookie('name');At some point you’ll want to read, set, and remove cookies using JavaScript. This is actually way more complicated than it should be so I’ll provide a few example functions and refer you to a solid jQuery plugin.
Posted in these interests:
Posted in these interests:
First you should understand what the cookie is and how it’s set. A cookie is a string that is stored on the user’s computer to allow data to persist throughout the user’s session. Cookies are often set by HTTP response headers, but they can also be set directly in the browser using JavaScript. To read the entire cookie string you can access document.cookie.
document.cookie What you’ll likely see is a long string of semi-colon delineated key/value pairs. ps=31;_ssd3=P0-1415818163-1436218393727;favorite_animal=goat;_gaa=23.00334.....You can manually set a cookie by setting document.cookie equal to the desired cookie using this format:
document.cookie = "name=tyler;expires=Thu, 03 Sep 2015 05:33:44 GMT"; This can be a little cumbersome, so the function below should make things easier. function setCookie(name, value, exdays) { var d, expires; exdays = exdays || 1; d = new Date(); d.setTime(d.getTime() + (exdays2460601000)); expires = "expires=" + d.toUTCString(); document.cookie = name + "=" + value + "; " + expires; } To set a cookie that lasts for one year, you could use: setCookie('name', 'Batman', 365);To read a cookie you can simply access document.cookie.
console.log(document.cookie); If you’re searching for a specific value you can use the following function. function getCookie(name) { var cookie, c; cookies = document.cookie.split(';'); for (var i=0; i < cookies.length; i++) { c = cookies[i].split('='); if (c[0] == name) { return c[1]; } } return ""; } This function uses JavaScript’s string split method to split the cookie string by semi-colons. Then it loops through the result array of strings and splits them again by “=” producing the cookie key/value pair. Then it simply tests the cookie key (c[0]) against the name of the cookie you are trying to read. If it matches it returns the value (c[1]). To delete a cookie, you simply need to expire it. So deleting a cookie is basically setting the cookie with an expiration in the past. Using our setCookie function:
setCookie('name', '', -1);If you’re using jQuery, you might as well use this cookie plugin. It allows easy management of cookies.
// read $.cookie('name'); // => "Batman" // set $.cookie('name', 'Iron Man'); // delete $.removeCookie('name');First you should understand what the cookie is and how it’s set. A cookie is a string that is stored on the user’s computer to allow data to persist throughout the user’s session. Cookies are often set by HTTP response headers, but they can also be set directly in the browser using JavaScript. To read the entire cookie string you can access document.cookie.
document.cookie What you’ll likely see is a long string of semi-colon delineated key/value pairs. ps=31;_ssd3=P0-1415818163-1436218393727;favorite_animal=goat;_gaa=23.00334.....First you should understand what the cookie is and how it’s set. A cookie is a string that is stored on the user’s computer to allow data to persist throughout the user’s session. Cookies are often set by HTTP response headers, but they can also be set directly in the browser using JavaScript. To read the entire cookie string you can access document.cookie.
document.cookie What you’ll likely see is a long string of semi-colon delineated key/value pairs. ps=31;_ssd3=P0-1415818163-1436218393727;favorite_animal=goat;_gaa=23.00334.....You can manually set a cookie by setting document.cookie equal to the desired cookie using this format:
document.cookie = "name=tyler;expires=Thu, 03 Sep 2015 05:33:44 GMT"; This can be a little cumbersome, so the function below should make things easier. function setCookie(name, value, exdays) { var d, expires; exdays = exdays || 1; d = new Date(); d.setTime(d.getTime() + (exdays2460601000)); expires = "expires=" + d.toUTCString(); document.cookie = name + "=" + value + "; " + expires; } To set a cookie that lasts for one year, you could use: setCookie('name', 'Batman', 365);You can manually set a cookie by setting document.cookie equal to the desired cookie using this format:
document.cookie = "name=tyler;expires=Thu, 03 Sep 2015 05:33:44 GMT"; This can be a little cumbersome, so the function below should make things easier. function setCookie(name, value, exdays) { var d, expires; exdays = exdays || 1; d = new Date(); d.setTime(d.getTime() + (exdays2460601000)); expires = "expires=" + d.toUTCString(); document.cookie = name + "=" + value + "; " + expires; } To set a cookie that lasts for one year, you could use: setCookie('name', 'Batman', 365);To read a cookie you can simply access document.cookie.
console.log(document.cookie); If you’re searching for a specific value you can use the following function. function getCookie(name) { var cookie, c; cookies = document.cookie.split(';'); for (var i=0; i < cookies.length; i++) { c = cookies[i].split('='); if (c[0] == name) { return c[1]; } } return ""; } This function uses JavaScript’s string split method to split the cookie string by semi-colons. Then it loops through the result array of strings and splits them again by “=” producing the cookie key/value pair. Then it simply tests the cookie key (c[0]) against the name of the cookie you are trying to read. If it matches it returns the value (c[1]). To read a cookie you can simply access document.cookie.
console.log(document.cookie); If you’re searching for a specific value you can use the following function. function getCookie(name) { var cookie, c; cookies = document.cookie.split(';'); for (var i=0; i < cookies.length; i++) { c = cookies[i].split('='); if (c[0] == name) { return c[1]; } } return ""; } This function uses JavaScript’s string split method to split the cookie string by semi-colons. Then it loops through the result array of strings and splits them again by “=” producing the cookie key/value pair. Then it simply tests the cookie key (c[0]) against the name of the cookie you are trying to read. If it matches it returns the value (c[1]). To delete a cookie, you simply need to expire it. So deleting a cookie is basically setting the cookie with an expiration in the past. Using our setCookie function:
setCookie('name', '', -1);To delete a cookie, you simply need to expire it. So deleting a cookie is basically setting the cookie with an expiration in the past. Using our setCookie function:
setCookie('name', '', -1);If you’re using jQuery, you might as well use this cookie plugin. It allows easy management of cookies.
// read $.cookie('name'); // => "Batman" // set $.cookie('name', 'Iron Man'); // delete $.removeCookie('name');If you’re using jQuery, you might as well use this cookie plugin. It allows easy management of cookies.
// read $.cookie('name'); // => "Batman" // set $.cookie('name', 'Iron Man'); // delete $.removeCookie('name');Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.
We’re hiring. Write for Howchoo
We’re hiring. Write for Howchoo