How can I count the number of words in a file whilst editing the file in vim2019 Community Moderator ElectionHow to store Vim tabstop settings in the file?How can I paste (overwriting) with vim?Vi vs vim, or, is there any reason why I would ever want to use vi?How can I create my own spelling file for vim?Any way to provide a separate vimrc file just for 1 sessionHow can I get vim to return to normal tab display?Vim: Count all occurrences (including multiple on the same line) of char or wordCan I jump to a jump by its number in vim?How can I stop vim from editing directories?How does the processor determine each instruction's opcode and operands: looking into binary file with VIM

Grepping string, but include all non-blank lines following each grep match

Echo with obfuscation

Sigmoid with a slope but no asymptotes?

Make a Bowl of Alphabet Soup

How to preserve electronics (computers, iPads and phones) for hundreds of years

How to make a list of partial sums using forEach

How to make money from a browser who sees 5 seconds into the future of any web page?

How many people need to be born every 8 years to sustain population?

How to leave product feedback on macOS?

What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?

How to reduce predictors the right way for a logistic regression model

Isometric embedding of a genus g surface

Can I cause damage to electrical appliances by unplugging them when they are turned on?

What is the smallest number n> 5 so that 5 ^ n ends with "3125"?

Personal or impersonal in a technical resume

Language involving irrational number is not a CFL

Has the laser at Magurele, Romania reached a tenth of the Sun's power?

Does the Crossbow Expert feat's extra crossbow attack work with the reaction attack from a Hunter ranger's Giant Killer feature?

Do I have to take mana from my deck or hand when tapping a dual land?

Did I make a mistake by ccing email to boss to others?

Anime with legendary swords made from talismans and a man who could change them with a shattered body

I'm just a whisper. Who am I?

Mimic lecturing on blackboard, facing audience

If the only attacker is removed from combat, is a creature still counted as having attacked this turn?



How can I count the number of words in a file whilst editing the file in vim



2019 Community Moderator ElectionHow to store Vim tabstop settings in the file?How can I paste (overwriting) with vim?Vi vs vim, or, is there any reason why I would ever want to use vi?How can I create my own spelling file for vim?Any way to provide a separate vimrc file just for 1 sessionHow can I get vim to return to normal tab display?Vim: Count all occurrences (including multiple on the same line) of char or wordCan I jump to a jump by its number in vim?How can I stop vim from editing directories?How does the processor determine each instruction's opcode and operands: looking into binary file with VIM










20















I know I can use wc for counting characters, words and lines of files at the command line.



Is there any way I can can count the number of words while in vim?










share|improve this question


























    20















    I know I can use wc for counting characters, words and lines of files at the command line.



    Is there any way I can can count the number of words while in vim?










    share|improve this question
























      20












      20








      20


      4






      I know I can use wc for counting characters, words and lines of files at the command line.



      Is there any way I can can count the number of words while in vim?










      share|improve this question














      I know I can use wc for counting characters, words and lines of files at the command line.



      Is there any way I can can count the number of words while in vim?







      vim vi






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 18 '14 at 13:02









      Michael DurrantMichael Durrant

      16.4k45121186




      16.4k45121186




















          3 Answers
          3






          active

          oldest

          votes


















          21














          You can count words and lines inside vi using vi's own counter:



          Press g and then CTRL-g. Then the bottom line look for example like this:



          Col 1 of 11; Line 1 of 106; Word 1 of 344; Byte 1 of 2644


          Or use vi's method to call shell commands:



          :w !wc -w


          This calls the save (:w) command first and then wc -w and shows the output. Example:



          :w !wc -w
          344

          Press ENTER or type command to continue


          Press Enter to go back to vi.






          share|improve this answer























          • It is actually incorrect description of :w !<cmd> construct. It writes the current buffer to a pipe connected to the command. No separate write of the current buffer to a file is promised. Nevertheless, it does what question asked for.

            – mcepl
            Nov 17 '17 at 9:45



















          1














          You can also try for :!wc % in Vim, though it counts the size of the file on-disk, not what is in Vim's buffer. This may or may not be what you wanted.






          share|improve this answer










          New contributor




          Pranav Suri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















          • This counts what’s on disk (if anything), not what’s in the buffer — so if you have changed the contents of the buffer since the last save, or not saved at all, you’ll get the wrong count (or even an error if you’re creating a file).

            – Stephen Kitt
            18 hours ago











          • Contra Stephen, this is a correct solution to "How can I count the number of words in a file whilst editing the file in vim", while the accepted answer strictly-speaking isn't (although it's ambiguous what was meant or whether it matters).

            – Michael Homer
            18 hours ago











          • Funny that it's similar (minus the -w flag to restrict the output to words only) to a delete answer from 2014 by D_Bye (who apparently self-deleted it).

            – Jeff Schaller
            16 hours ago


















          0














          Plugins such as vim-airline can provide word counts for a file (and selections) as part of a status bar.






          share|improve this answer























          • This answer isn't link-only. I didn't include the specifics of any particular plugin, because (as you say) particular plugins might become outdated.

            – Patrick Sanan
            Jan 9 at 19:04











          • I stand corrected. However I would say in the future you should try to include relevant steps to implement the solution you are presenting. Thank you!

            – kemotep
            Jan 9 at 19:43









          protected by Archemar 18 hours ago



          Thank you for your interest in this question.
          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



          Would you like to answer one of these unanswered questions instead?














          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          21














          You can count words and lines inside vi using vi's own counter:



          Press g and then CTRL-g. Then the bottom line look for example like this:



          Col 1 of 11; Line 1 of 106; Word 1 of 344; Byte 1 of 2644


          Or use vi's method to call shell commands:



          :w !wc -w


          This calls the save (:w) command first and then wc -w and shows the output. Example:



          :w !wc -w
          344

          Press ENTER or type command to continue


          Press Enter to go back to vi.






          share|improve this answer























          • It is actually incorrect description of :w !<cmd> construct. It writes the current buffer to a pipe connected to the command. No separate write of the current buffer to a file is promised. Nevertheless, it does what question asked for.

            – mcepl
            Nov 17 '17 at 9:45
















          21














          You can count words and lines inside vi using vi's own counter:



          Press g and then CTRL-g. Then the bottom line look for example like this:



          Col 1 of 11; Line 1 of 106; Word 1 of 344; Byte 1 of 2644


          Or use vi's method to call shell commands:



          :w !wc -w


          This calls the save (:w) command first and then wc -w and shows the output. Example:



          :w !wc -w
          344

          Press ENTER or type command to continue


          Press Enter to go back to vi.






          share|improve this answer























          • It is actually incorrect description of :w !<cmd> construct. It writes the current buffer to a pipe connected to the command. No separate write of the current buffer to a file is promised. Nevertheless, it does what question asked for.

            – mcepl
            Nov 17 '17 at 9:45














          21












          21








          21







          You can count words and lines inside vi using vi's own counter:



          Press g and then CTRL-g. Then the bottom line look for example like this:



          Col 1 of 11; Line 1 of 106; Word 1 of 344; Byte 1 of 2644


          Or use vi's method to call shell commands:



          :w !wc -w


          This calls the save (:w) command first and then wc -w and shows the output. Example:



          :w !wc -w
          344

          Press ENTER or type command to continue


          Press Enter to go back to vi.






          share|improve this answer













          You can count words and lines inside vi using vi's own counter:



          Press g and then CTRL-g. Then the bottom line look for example like this:



          Col 1 of 11; Line 1 of 106; Word 1 of 344; Byte 1 of 2644


          Or use vi's method to call shell commands:



          :w !wc -w


          This calls the save (:w) command first and then wc -w and shows the output. Example:



          :w !wc -w
          344

          Press ENTER or type command to continue


          Press Enter to go back to vi.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 18 '14 at 13:21









          chaoschaos

          35.9k976120




          35.9k976120












          • It is actually incorrect description of :w !<cmd> construct. It writes the current buffer to a pipe connected to the command. No separate write of the current buffer to a file is promised. Nevertheless, it does what question asked for.

            – mcepl
            Nov 17 '17 at 9:45


















          • It is actually incorrect description of :w !<cmd> construct. It writes the current buffer to a pipe connected to the command. No separate write of the current buffer to a file is promised. Nevertheless, it does what question asked for.

            – mcepl
            Nov 17 '17 at 9:45

















          It is actually incorrect description of :w !<cmd> construct. It writes the current buffer to a pipe connected to the command. No separate write of the current buffer to a file is promised. Nevertheless, it does what question asked for.

          – mcepl
          Nov 17 '17 at 9:45






          It is actually incorrect description of :w !<cmd> construct. It writes the current buffer to a pipe connected to the command. No separate write of the current buffer to a file is promised. Nevertheless, it does what question asked for.

          – mcepl
          Nov 17 '17 at 9:45














          1














          You can also try for :!wc % in Vim, though it counts the size of the file on-disk, not what is in Vim's buffer. This may or may not be what you wanted.






          share|improve this answer










          New contributor




          Pranav Suri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















          • This counts what’s on disk (if anything), not what’s in the buffer — so if you have changed the contents of the buffer since the last save, or not saved at all, you’ll get the wrong count (or even an error if you’re creating a file).

            – Stephen Kitt
            18 hours ago











          • Contra Stephen, this is a correct solution to "How can I count the number of words in a file whilst editing the file in vim", while the accepted answer strictly-speaking isn't (although it's ambiguous what was meant or whether it matters).

            – Michael Homer
            18 hours ago











          • Funny that it's similar (minus the -w flag to restrict the output to words only) to a delete answer from 2014 by D_Bye (who apparently self-deleted it).

            – Jeff Schaller
            16 hours ago















          1














          You can also try for :!wc % in Vim, though it counts the size of the file on-disk, not what is in Vim's buffer. This may or may not be what you wanted.






          share|improve this answer










          New contributor




          Pranav Suri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















          • This counts what’s on disk (if anything), not what’s in the buffer — so if you have changed the contents of the buffer since the last save, or not saved at all, you’ll get the wrong count (or even an error if you’re creating a file).

            – Stephen Kitt
            18 hours ago











          • Contra Stephen, this is a correct solution to "How can I count the number of words in a file whilst editing the file in vim", while the accepted answer strictly-speaking isn't (although it's ambiguous what was meant or whether it matters).

            – Michael Homer
            18 hours ago











          • Funny that it's similar (minus the -w flag to restrict the output to words only) to a delete answer from 2014 by D_Bye (who apparently self-deleted it).

            – Jeff Schaller
            16 hours ago













          1












          1








          1







          You can also try for :!wc % in Vim, though it counts the size of the file on-disk, not what is in Vim's buffer. This may or may not be what you wanted.






          share|improve this answer










          New contributor




          Pranav Suri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.










          You can also try for :!wc % in Vim, though it counts the size of the file on-disk, not what is in Vim's buffer. This may or may not be what you wanted.







          share|improve this answer










          New contributor




          Pranav Suri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer








          edited 13 hours ago









          ilkkachu

          61.9k10102178




          61.9k10102178






          New contributor




          Pranav Suri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 20 hours ago









          Pranav SuriPranav Suri

          111




          111




          New contributor




          Pranav Suri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Pranav Suri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Pranav Suri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.












          • This counts what’s on disk (if anything), not what’s in the buffer — so if you have changed the contents of the buffer since the last save, or not saved at all, you’ll get the wrong count (or even an error if you’re creating a file).

            – Stephen Kitt
            18 hours ago











          • Contra Stephen, this is a correct solution to "How can I count the number of words in a file whilst editing the file in vim", while the accepted answer strictly-speaking isn't (although it's ambiguous what was meant or whether it matters).

            – Michael Homer
            18 hours ago











          • Funny that it's similar (minus the -w flag to restrict the output to words only) to a delete answer from 2014 by D_Bye (who apparently self-deleted it).

            – Jeff Schaller
            16 hours ago

















          • This counts what’s on disk (if anything), not what’s in the buffer — so if you have changed the contents of the buffer since the last save, or not saved at all, you’ll get the wrong count (or even an error if you’re creating a file).

            – Stephen Kitt
            18 hours ago











          • Contra Stephen, this is a correct solution to "How can I count the number of words in a file whilst editing the file in vim", while the accepted answer strictly-speaking isn't (although it's ambiguous what was meant or whether it matters).

            – Michael Homer
            18 hours ago











          • Funny that it's similar (minus the -w flag to restrict the output to words only) to a delete answer from 2014 by D_Bye (who apparently self-deleted it).

            – Jeff Schaller
            16 hours ago
















          This counts what’s on disk (if anything), not what’s in the buffer — so if you have changed the contents of the buffer since the last save, or not saved at all, you’ll get the wrong count (or even an error if you’re creating a file).

          – Stephen Kitt
          18 hours ago





          This counts what’s on disk (if anything), not what’s in the buffer — so if you have changed the contents of the buffer since the last save, or not saved at all, you’ll get the wrong count (or even an error if you’re creating a file).

          – Stephen Kitt
          18 hours ago













          Contra Stephen, this is a correct solution to "How can I count the number of words in a file whilst editing the file in vim", while the accepted answer strictly-speaking isn't (although it's ambiguous what was meant or whether it matters).

          – Michael Homer
          18 hours ago





          Contra Stephen, this is a correct solution to "How can I count the number of words in a file whilst editing the file in vim", while the accepted answer strictly-speaking isn't (although it's ambiguous what was meant or whether it matters).

          – Michael Homer
          18 hours ago













          Funny that it's similar (minus the -w flag to restrict the output to words only) to a delete answer from 2014 by D_Bye (who apparently self-deleted it).

          – Jeff Schaller
          16 hours ago





          Funny that it's similar (minus the -w flag to restrict the output to words only) to a delete answer from 2014 by D_Bye (who apparently self-deleted it).

          – Jeff Schaller
          16 hours ago











          0














          Plugins such as vim-airline can provide word counts for a file (and selections) as part of a status bar.






          share|improve this answer























          • This answer isn't link-only. I didn't include the specifics of any particular plugin, because (as you say) particular plugins might become outdated.

            – Patrick Sanan
            Jan 9 at 19:04











          • I stand corrected. However I would say in the future you should try to include relevant steps to implement the solution you are presenting. Thank you!

            – kemotep
            Jan 9 at 19:43















          0














          Plugins such as vim-airline can provide word counts for a file (and selections) as part of a status bar.






          share|improve this answer























          • This answer isn't link-only. I didn't include the specifics of any particular plugin, because (as you say) particular plugins might become outdated.

            – Patrick Sanan
            Jan 9 at 19:04











          • I stand corrected. However I would say in the future you should try to include relevant steps to implement the solution you are presenting. Thank you!

            – kemotep
            Jan 9 at 19:43













          0












          0








          0







          Plugins such as vim-airline can provide word counts for a file (and selections) as part of a status bar.






          share|improve this answer













          Plugins such as vim-airline can provide word counts for a file (and selections) as part of a status bar.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 9 at 17:26









          Patrick SananPatrick Sanan

          1033




          1033












          • This answer isn't link-only. I didn't include the specifics of any particular plugin, because (as you say) particular plugins might become outdated.

            – Patrick Sanan
            Jan 9 at 19:04











          • I stand corrected. However I would say in the future you should try to include relevant steps to implement the solution you are presenting. Thank you!

            – kemotep
            Jan 9 at 19:43

















          • This answer isn't link-only. I didn't include the specifics of any particular plugin, because (as you say) particular plugins might become outdated.

            – Patrick Sanan
            Jan 9 at 19:04











          • I stand corrected. However I would say in the future you should try to include relevant steps to implement the solution you are presenting. Thank you!

            – kemotep
            Jan 9 at 19:43
















          This answer isn't link-only. I didn't include the specifics of any particular plugin, because (as you say) particular plugins might become outdated.

          – Patrick Sanan
          Jan 9 at 19:04





          This answer isn't link-only. I didn't include the specifics of any particular plugin, because (as you say) particular plugins might become outdated.

          – Patrick Sanan
          Jan 9 at 19:04













          I stand corrected. However I would say in the future you should try to include relevant steps to implement the solution you are presenting. Thank you!

          – kemotep
          Jan 9 at 19:43





          I stand corrected. However I would say in the future you should try to include relevant steps to implement the solution you are presenting. Thank you!

          – kemotep
          Jan 9 at 19:43





          protected by Archemar 18 hours ago



          Thank you for your interest in this question.
          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



          Would you like to answer one of these unanswered questions instead?



          Popular posts from this blog

          getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

          Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

          Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.