vim move to first non-blank in same column












5















In vim, how can I move the cursor down (or up) to the first line
containing a non-blank character in the same column ?



For example, in the following text:



item1
item2
item3
item4
item5
item6


If the cursor is on the e in item1, move the cursor to the e in item4.



If on the m in item3, move to the m in item5.



FYI, I'm looking for a quick and efficient way to navigate formatted text.



(P.S. Those are spaces not tabs.)










share|improve this question





























    5















    In vim, how can I move the cursor down (or up) to the first line
    containing a non-blank character in the same column ?



    For example, in the following text:



    item1
    item2
    item3
    item4
    item5
    item6


    If the cursor is on the e in item1, move the cursor to the e in item4.



    If on the m in item3, move to the m in item5.



    FYI, I'm looking for a quick and efficient way to navigate formatted text.



    (P.S. Those are spaces not tabs.)










    share|improve this question



























      5












      5








      5








      In vim, how can I move the cursor down (or up) to the first line
      containing a non-blank character in the same column ?



      For example, in the following text:



      item1
      item2
      item3
      item4
      item5
      item6


      If the cursor is on the e in item1, move the cursor to the e in item4.



      If on the m in item3, move to the m in item5.



      FYI, I'm looking for a quick and efficient way to navigate formatted text.



      (P.S. Those are spaces not tabs.)










      share|improve this question
















      In vim, how can I move the cursor down (or up) to the first line
      containing a non-blank character in the same column ?



      For example, in the following text:



      item1
      item2
      item3
      item4
      item5
      item6


      If the cursor is on the e in item1, move the cursor to the e in item4.



      If on the m in item3, move to the m in item5.



      FYI, I'm looking for a quick and efficient way to navigate formatted text.



      (P.S. Those are spaces not tabs.)







      vim






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 16 '14 at 14:12







      Lqueryvg

















      asked May 16 '14 at 12:29









      LqueryvgLqueryvg

      473210




      473210






















          3 Answers
          3






          active

          oldest

          votes


















          2














          You could use the following mappings to do this. (There might be some edge cases I didn't think of)



          nnoremap <leader>d m':exec '/%' . col(".") . 'cS'<CR>``n
          nnoremap <leader>u m':exec '?%' . col(".") . 'cS'<CR>``n


          The important part is :exec '/%' . col(".") . 'c' This matches the current column. This is taken directly from :h %c. Then I added a S to match non whitespace. m' and `` is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n. The only difference between the up and down version is which direction we search / for down and ? for up.



          If you instead wanted to do this with virtual columns (i.e. tabs) replace %c with %v.






          share|improve this answer





















          • 1





            That's superb; it's exactly what I was looking for! I think I will map these to <leader>j and <leader>k respectively. The only thing I will add is :noh to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !

            – Lqueryvg
            May 16 '14 at 17:59








          • 1





            @Lqueryvg while it does clobber the search register you can still use n and N to move up and down the column.

            – FDinoff
            May 16 '14 at 18:00











          • Even better ! Thanks again!!

            – Lqueryvg
            May 16 '14 at 18:06



















          2














          My JumpToVerticalOccurrence plugin provides ]| and [| mappings that provide just that, supporting [count] and without clobbering the current search pattern.






          share|improve this answer
























          • Thanks for this. I will explore the plugin as well as the "one-liner" solution.

            – Lqueryvg
            May 20 '14 at 8:43



















          0














          If you want this for code or configuration files with a defined indentation system (assuming that falls under "formatted text"), jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f755122%2fvim-move-to-first-non-blank-in-same-column%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You could use the following mappings to do this. (There might be some edge cases I didn't think of)



            nnoremap <leader>d m':exec '/%' . col(".") . 'cS'<CR>``n
            nnoremap <leader>u m':exec '?%' . col(".") . 'cS'<CR>``n


            The important part is :exec '/%' . col(".") . 'c' This matches the current column. This is taken directly from :h %c. Then I added a S to match non whitespace. m' and `` is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n. The only difference between the up and down version is which direction we search / for down and ? for up.



            If you instead wanted to do this with virtual columns (i.e. tabs) replace %c with %v.






            share|improve this answer





















            • 1





              That's superb; it's exactly what I was looking for! I think I will map these to <leader>j and <leader>k respectively. The only thing I will add is :noh to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !

              – Lqueryvg
              May 16 '14 at 17:59








            • 1





              @Lqueryvg while it does clobber the search register you can still use n and N to move up and down the column.

              – FDinoff
              May 16 '14 at 18:00











            • Even better ! Thanks again!!

              – Lqueryvg
              May 16 '14 at 18:06
















            2














            You could use the following mappings to do this. (There might be some edge cases I didn't think of)



            nnoremap <leader>d m':exec '/%' . col(".") . 'cS'<CR>``n
            nnoremap <leader>u m':exec '?%' . col(".") . 'cS'<CR>``n


            The important part is :exec '/%' . col(".") . 'c' This matches the current column. This is taken directly from :h %c. Then I added a S to match non whitespace. m' and `` is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n. The only difference between the up and down version is which direction we search / for down and ? for up.



            If you instead wanted to do this with virtual columns (i.e. tabs) replace %c with %v.






            share|improve this answer





















            • 1





              That's superb; it's exactly what I was looking for! I think I will map these to <leader>j and <leader>k respectively. The only thing I will add is :noh to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !

              – Lqueryvg
              May 16 '14 at 17:59








            • 1





              @Lqueryvg while it does clobber the search register you can still use n and N to move up and down the column.

              – FDinoff
              May 16 '14 at 18:00











            • Even better ! Thanks again!!

              – Lqueryvg
              May 16 '14 at 18:06














            2












            2








            2







            You could use the following mappings to do this. (There might be some edge cases I didn't think of)



            nnoremap <leader>d m':exec '/%' . col(".") . 'cS'<CR>``n
            nnoremap <leader>u m':exec '?%' . col(".") . 'cS'<CR>``n


            The important part is :exec '/%' . col(".") . 'c' This matches the current column. This is taken directly from :h %c. Then I added a S to match non whitespace. m' and `` is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n. The only difference between the up and down version is which direction we search / for down and ? for up.



            If you instead wanted to do this with virtual columns (i.e. tabs) replace %c with %v.






            share|improve this answer















            You could use the following mappings to do this. (There might be some edge cases I didn't think of)



            nnoremap <leader>d m':exec '/%' . col(".") . 'cS'<CR>``n
            nnoremap <leader>u m':exec '?%' . col(".") . 'cS'<CR>``n


            The important part is :exec '/%' . col(".") . 'c' This matches the current column. This is taken directly from :h %c. Then I added a S to match non whitespace. m' and `` is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n. The only difference between the up and down version is which direction we search / for down and ? for up.



            If you instead wanted to do this with virtual columns (i.e. tabs) replace %c with %v.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 16 '14 at 17:26

























            answered May 16 '14 at 17:17









            FDinoffFDinoff

            1,5431718




            1,5431718








            • 1





              That's superb; it's exactly what I was looking for! I think I will map these to <leader>j and <leader>k respectively. The only thing I will add is :noh to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !

              – Lqueryvg
              May 16 '14 at 17:59








            • 1





              @Lqueryvg while it does clobber the search register you can still use n and N to move up and down the column.

              – FDinoff
              May 16 '14 at 18:00











            • Even better ! Thanks again!!

              – Lqueryvg
              May 16 '14 at 18:06














            • 1





              That's superb; it's exactly what I was looking for! I think I will map these to <leader>j and <leader>k respectively. The only thing I will add is :noh to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !

              – Lqueryvg
              May 16 '14 at 17:59








            • 1





              @Lqueryvg while it does clobber the search register you can still use n and N to move up and down the column.

              – FDinoff
              May 16 '14 at 18:00











            • Even better ! Thanks again!!

              – Lqueryvg
              May 16 '14 at 18:06








            1




            1





            That's superb; it's exactly what I was looking for! I think I will map these to <leader>j and <leader>k respectively. The only thing I will add is :noh to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !

            – Lqueryvg
            May 16 '14 at 17:59







            That's superb; it's exactly what I was looking for! I think I will map these to <leader>j and <leader>k respectively. The only thing I will add is :noh to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !

            – Lqueryvg
            May 16 '14 at 17:59






            1




            1





            @Lqueryvg while it does clobber the search register you can still use n and N to move up and down the column.

            – FDinoff
            May 16 '14 at 18:00





            @Lqueryvg while it does clobber the search register you can still use n and N to move up and down the column.

            – FDinoff
            May 16 '14 at 18:00













            Even better ! Thanks again!!

            – Lqueryvg
            May 16 '14 at 18:06





            Even better ! Thanks again!!

            – Lqueryvg
            May 16 '14 at 18:06













            2














            My JumpToVerticalOccurrence plugin provides ]| and [| mappings that provide just that, supporting [count] and without clobbering the current search pattern.






            share|improve this answer
























            • Thanks for this. I will explore the plugin as well as the "one-liner" solution.

              – Lqueryvg
              May 20 '14 at 8:43
















            2














            My JumpToVerticalOccurrence plugin provides ]| and [| mappings that provide just that, supporting [count] and without clobbering the current search pattern.






            share|improve this answer
























            • Thanks for this. I will explore the plugin as well as the "one-liner" solution.

              – Lqueryvg
              May 20 '14 at 8:43














            2












            2








            2







            My JumpToVerticalOccurrence plugin provides ]| and [| mappings that provide just that, supporting [count] and without clobbering the current search pattern.






            share|improve this answer













            My JumpToVerticalOccurrence plugin provides ]| and [| mappings that provide just that, supporting [count] and without clobbering the current search pattern.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 16 '14 at 19:06









            Ingo KarkatIngo Karkat

            17.4k22343




            17.4k22343













            • Thanks for this. I will explore the plugin as well as the "one-liner" solution.

              – Lqueryvg
              May 20 '14 at 8:43



















            • Thanks for this. I will explore the plugin as well as the "one-liner" solution.

              – Lqueryvg
              May 20 '14 at 8:43

















            Thanks for this. I will explore the plugin as well as the "one-liner" solution.

            – Lqueryvg
            May 20 '14 at 8:43





            Thanks for this. I will explore the plugin as well as the "one-liner" solution.

            – Lqueryvg
            May 20 '14 at 8:43











            0














            If you want this for code or configuration files with a defined indentation system (assuming that falls under "formatted text"), jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.






            share|improve this answer




























              0














              If you want this for code or configuration files with a defined indentation system (assuming that falls under "formatted text"), jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.






              share|improve this answer


























                0












                0








                0







                If you want this for code or configuration files with a defined indentation system (assuming that falls under "formatted text"), jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.






                share|improve this answer













                If you want this for code or configuration files with a defined indentation system (assuming that falls under "formatted text"), jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 4 at 13:46









                HarryHarry

                1012




                1012






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f755122%2fvim-move-to-first-non-blank-in-same-column%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Aardman Animations

                    Are they similar matrix

                    “minimization” problem in Euclidean space related to orthonormal basis