Search code examples
viaix

How to get the current line length in VI editor?


Is there a way to check the length of the current line where the cursor is currently in the VI editor? I tried searching in Google but all I could find is how to see the line number in the currently opened file using "set nu".


Solution

  • Write to current line to a shell command:

    :.w !wc -c
    

    Also note that the length with wc -c includes the \n. When you don't want that, substract one or use something like

    :.w !tr -d '\n'|wc -c